class _MyAppState extends State<MyApp> { @override Widget build(BuildContext context) { return MaterialApp( title: 'Container组件', home: Scaffold( appBar: AppBar( title: Text('Container组件'), ), body: Center( child: Container( padding: EdgeInsets.all(20.0), child: Container( color: Colors.green, margin: EdgeInsets.all(10.0), ), width: 200.0, height: 200.0, decoration: BoxDecoration( color: Colors.white, border: Border.all(color: Colors.grey, width: 10.0), borderRadius: BorderRadius.all(Radius.circular(10.0)), ), )), ), ); } }
Flutter笔记35:Container组件
Container和html的div非常想,是非常常用的组件,Container如果不设置宽高,默认占满父组件,这和css的div不一样: