Skip to content

Instantly share code, notes, and snippets.

@PoojaB26
Created April 21, 2020 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PoojaB26/564ca3391b28bc035e675ea86c4355ef to your computer and use it in GitHub Desktop.
Save PoojaB26/564ca3391b28bc035e675ea86c4355ef to your computer and use it in GitHub Desktop.
Row Widget Examples
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