Created
April 21, 2020 23:51
-
-
Save PoojaB26/564ca3391b28bc035e675ea86c4355ef to your computer and use it in GitHub Desktop.
Row Widget Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar(title: Text("Row Widget: Examples")), | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
static final TextStyle bigStyle = TextStyle(fontSize: 20); | |
//Simple Row of similar Text children | |
final row1 = Row( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
Text("Column 1", style: bigStyle,), | |
Text("Column 2", style: bigStyle,), | |
Text("Column 3", style: bigStyle,) | |
], | |
); | |
//Row with children of different Widgets | |
final row2 = Row( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
FlutterLogo( | |
size: 100.0, | |
colors: Colors.red, | |
), | |
Text("Column 2", style: bigStyle,), | |
Container( | |
color: Colors.green, | |
height: 100.0, | |
width: 100.0, | |
) | |
], | |
); | |
//Playing with MainAxisAlignment | |
final row3 = Row( | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: [ | |
FlutterLogo( | |
size: 100.0, | |
colors: Colors.red, | |
), | |
Text("Child Two", style: bigStyle,), | |
Container( | |
color: Colors.blue, | |
height: 100.0, | |
width: 100.0, | |
) | |
], | |
); | |
//Row having Column as child | |
final row4 = Row( | |
mainAxisSize: MainAxisSize.min, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: [ | |
Text("Parent Text 1"), | |
Text("Parent Text 2"), | |
Column( | |
mainAxisSize: MainAxisSize.min, | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: [ | |
Text("Child Row Text 1"), | |
Text("Child Row Text 2") | |
], | |
), | |
], | |
); | |
@override | |
Widget build(BuildContext context) { | |
return row3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment