By Alvin Alexander. Last updated: October 24, 2019
As a brief note, on this page I found this example of how to set the size of a Flutter Container
:
Container( height: MediaQuery.of(context).copyWith().size.height / 3, );
After looking at what the copyWith
method does:
copyWith
: Creates a copy of this media query data but with the given fields replaced with the new values.
I don’t think it’s needed in this example, so you should get the exact same effect with this code:
Container( height: MediaQuery.of(context).size.height / 3, );
For instance, I use this code in a production app to set the size of this Flutter Container
to be one-fourth of the screen height:
returnContainer( height: MediaQuery.of(context).size.height / 4, child: CupertinoDatePicker( mode: CupertinoDatePickerMode.time, initialDateTime: DateTime(1969, 1, 1, _timeOfDay.hour, _timeOfDay.minute), onDateTimeChanged: (DateTime newDateTime) { var newTod = TimeOfDay.fromDateTime(newDateTime); _updateTimeFunction(newTod); }, use24hFormat: false, minuteInterval: 1, ) );
In summary, if you wanted to see how to set the size of a Flutter Container — in this case, the Container height — I hope these examples are helpful.