Skip to content

Instantly share code, notes, and snippets.

@erluxman

erluxman/SpacerDemo.dart

Last active Apr 11, 2020
Embed
What would you like to do?
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