Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter stretch columns to full screen height

Tags:

All three elements are at the top of the screen and stretch to fill the width, but I want them to stretch to fill the screen vertically from top to bottom.

I tried adding a Row around everything but it throws the error RenderFlex children have non-zero flex but incoming width constraints are unbounded? So I tried wrapping that Row in an Expanded widget which throws the error 'Expanded widgets must be placed inside Flex widgets'.

return Scaffold(   backgroundColor: Color(0xFF222222),   body: Column(   children: <Widget>[     SizedBox(height: 20),     Row(       // crossAxisAlignment: CrossAxisAlignment.stretch,//throws error       children: <Widget>[         Expanded(           child: Column(             crossAxisAlignment: CrossAxisAlignment.stretch,             children: <Widget>[               Container(                 color: Colors.red,                 child: Text('Left', textAlign: TextAlign.center),               ),             ],           ),         ),         Expanded(           child: Column(             crossAxisAlignment: CrossAxisAlignment.stretch,             children: <Widget>[               Container(                 color: Colors.red,                 child: Text('Right', textAlign: TextAlign.center),               ),             ],           ),         ),       ],     ),     Column(       crossAxisAlignment: CrossAxisAlignment.stretch,       children: <Widget>[         Container(           color: Colors.red,           child: Text('Bottom', textAlign: TextAlign.center),         ),       ],     ),   ], ), ); 
like image 898
Hasen Avatar asked Jul 25 '19 13:07

Hasen


People also ask

How do I make my columns full height and Flutter?

To get columns to take up the full width of the display and to share the height equally I did the following: return MaterialApp( home: Scaffold( backgroundColor: Colors. black, body: SafeArea( child: Column( mainAxisAlignment: MainAxisAlignment. center, children: <Widget>[ Expanded( child: SizedBox( width: double.

How much height does a column take by default in Flutter?

By default column takes full available height and row takes full available width. It basically takes two values, min and max (default). When it sets to min, it will be the total size of the components it contains. When it sets to max , it covers the most possible area.


1 Answers

Is this more like what you are after?

Each container contains a column allowing you to add multiple widgets.

return Scaffold(       backgroundColor: Color(0xFF222222),       body: SafeArea(         child: Column(           mainAxisAlignment: MainAxisAlignment.spaceBetween,           crossAxisAlignment: CrossAxisAlignment.stretch,           children: <Widget>[             Expanded(               child: Row(                 mainAxisAlignment: MainAxisAlignment.spaceBetween,                 crossAxisAlignment: CrossAxisAlignment.stretch,                 children: <Widget>[                   Expanded(                     child: Container(                       color: Colors.red,                       child: Column(                         mainAxisAlignment: MainAxisAlignment.start,                         children: <Widget>[                           Text('Left', textAlign: TextAlign.center),                           Text('Left', textAlign: TextAlign.center),                           Text('Left', textAlign: TextAlign.center),                         ],                       ),                     ),                   ),                   Expanded(                     child: Container(                       color: Colors.green,                       child: Column(                         mainAxisAlignment: MainAxisAlignment.end,                         children: <Widget>[                           Text('Right', textAlign: TextAlign.center),                           Text('Right', textAlign: TextAlign.center),                           Text('Right', textAlign: TextAlign.center),                         ],                       ),                     ),                   ),                 ],               ),             ),             Expanded(               child: Container(                 color: Colors.blue,                 child: Column(                   mainAxisAlignment: MainAxisAlignment.center,                   children: <Widget>[                     Text('Bottom', textAlign: TextAlign.center),                     Text('Bottom', textAlign: TextAlign.center),                     Text('Bottom', textAlign: TextAlign.center),                   ],                 ),               ),             ),           ],         ),       ),     );  

Screenshot of code running

like image 61
Max Macfarlane Avatar answered Sep 17 '22 17:09

Max Macfarlane