Flutter Tutorial - Flutter Expanded Widget | RRTutors

Flutter Expanded Widget

The Expanded component allows Row, Column, Flex and other sub-components to expand in the direction of their main axis and fill the available space. Similar usage of widget properties in Android

 

  • Expanded will be distributed as full as possible in the main axis direction of Row, Column, or Flex

  • If Column contains two childs and two widgets are expanded, both share the

available vertical space evenly.

  • If only one is expanded, the expanded one takes up

all the available vertical space.

  • If neither is expanded, the available vertical space

goes unfilled


 

Example:


 

class ExpandedWidget extends StatelessWidget {

 @override

 Widget build(BuildContext context) {

   // TODO: implement build

   return MaterialApp(

       home: Scaffold(

         appBar: AppBar(backgroundColor: Colors.pink,title: Text("Expanded Widget"),),

     body: new Row(

       children: <Widget>[

         new Expanded(

           flex: 2,

           child: new Container(

             child: new Text('Text1', textAlign: TextAlign.center),

             height: 100,

             alignment: AlignmentDirectional.center,

             color: Colors.yellow,

           ),

         ),

         new Expanded(

           flex: 1,

           child: new Container(

             child: new Text('Text2', textAlign: TextAlign.center),

             height: 100,

             alignment: AlignmentDirectional.center,

             color: Colors.lightGreen,

           ),

         ),

         new Expanded(

           flex: 1,

           child: new Container(

             child: new Text('Text3', textAlign: TextAlign.center),

             height: 100,

             alignment: AlignmentDirectional.center,

             color: Colors.deepPurple,

           ),

         ),

       ],

     ),

   ));

 }

}

 

Flutter Expanded widget

 

Flexible

It is actually Expanded inheritance Flexible. Use Flexible widgets to Row, Column or Flex provided in the main shaft expands to fill the available space in flexibility (e.g., horizontal filling sub assembly Row or perpendicular filled Column), but Expandeddifferent, Flexible is not required to fill the available space sub components.

 

Flexible The control must be Row, Column or Flex a descendant of Row, the path from the control to its closure , Column or Flex the path must contain only Stateless Widgets or Stateful Widget these, and cannot be other types of widgets (for example Render ObjectWidget)


 

Center

This widget is used to center a Widget within its parent

Widget.

 

Advertisements