Skip to content

Instantly share code, notes, and snippets.

@emisjerry
Created September 30, 2019 12:35
Show Gist options
  • Save emisjerry/cfc854300d0d710521d1b874e57ef592 to your computer and use it in GitHub Desktop.
Save emisjerry/cfc854300d0d710521d1b874e57ef592 to your computer and use it in GitHub Desktop.
Container, shape and Expanded
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
void pn(num n) => print(n);
// Column -> container
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget scaffold = Scaffold(
appBar: AppBar(title: Text("My App")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 2,
child: Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
color: Colors.blue,
shape: BoxShape.rectangle,
),
alignment: Alignment.center,
// child的對齊
child: Icon(Icons.home, color: Colors.white),
),
),
Expanded(
child: Container(
width: 100.0,
height: 100.0,
margin: EdgeInsets.only(top: 10),
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.rectangle,
),
alignment: Alignment.center,
// child的對齊
child: Icon(Icons.keyboard, color: Colors.white),
),
),
Container(
width: 100.0,
height: 100.0,
margin: EdgeInsets.only(top: 10),
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
alignment: Alignment.center,
// child的對齊
child: Icon(Icons.schedule, color: Colors.white),
),
],
),
),
);
return scaffold;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment