Last active
April 11, 2020 01:49
-
-
Save erluxman/f0d077124527a8078cdb2eede1e9bf73 to your computer and use it in GitHub Desktop.
Demo of spacer widget
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( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.red, | |
padding: EdgeInsets.all(16), | |
child: Column( | |
children: [ | |
Text( | |
"Using Containers", | |
style: TextStyle(fontSize: 30, color: Colors.white), | |
), | |
Row( | |
children: [ | |
GreenRectangle(), | |
Container(width: 20), | |
GreenRectangle(), | |
Container(width: 20), | |
GreenRectangle(), | |
Container(width: 20), | |
GreenRectangle(), | |
Container(width: 20), | |
GreenRectangle(), | |
], | |
), | |
Container(height: 30), | |
Text( | |
"Using Spacer", | |
style: TextStyle(fontSize: 30, color: Colors.white), | |
), | |
Row( | |
children: [ | |
GreenRectangle(), | |
Spacer(), | |
GreenRectangle(), | |
Spacer(), | |
GreenRectangle(), | |
Spacer(), | |
GreenRectangle(), | |
Spacer(), | |
GreenRectangle(), | |
], | |
), | |
], | |
), | |
); | |
} | |
} | |
class GreenRectangle extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.green, | |
height: 50, | |
width: 50, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment