Skip to content

Instantly share code, notes, and snippets.

@erluxman
Last active April 11, 2020 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erluxman/f0d077124527a8078cdb2eede1e9bf73 to your computer and use it in GitHub Desktop.
Save erluxman/f0d077124527a8078cdb2eede1e9bf73 to your computer and use it in GitHub Desktop.
Demo of spacer widget
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