Row布局(行布局,水平方向布局)

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget{
  4. @override
  5. Widget build(BuildContext context){
  6. return MaterialApp(
  7. title: "后台标题",
  8. home: Scaffold(
  9. appBar: new AppBar(
  10. title: new Text("水平方向布局"),
  11. ),
  12. body: new Row( //行布局
  13. children: <Widget>[
  14. Expanded(child: //Expanded灵活布局(平分布局大小)
  15. new RaisedButton(
  16. onPressed: (){},//点击事件
  17. color: Colors.redAccent,
  18. child: new Text("红色按钮"),
  19. ),
  20. ),
  21. new RaisedButton( //不加Expanded就根据字体大小获得按钮大小
  22. onPressed: (){},
  23. color: Colors.blue,
  24. child: new Text("蓝色按钮"),
  25. ),
  26. Expanded(child:
  27. new RaisedButton(
  28. onPressed: (){},
  29. color: Colors.lightGreenAccent,
  30. child: new Text("绿色按钮"),
  31. ),
  32. ),
  33. ],
  34. ),
  35. ),
  36. );
  37. }
  38. }

Column垂直方向布局

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget{
  4. @override
  5. Widget build(BuildContext context){
  6. return MaterialApp(
  7. title: "后台标题",
  8. home: Scaffold(
  9. appBar: new AppBar(
  10. title: new Text("垂直方向布局"),
  11. ),
  12. //这个位置把Center去掉的话只能根据屏幕垂直居中,使用要加上Center才能完美屏幕居中
  13. body:Center(child: new Column(//垂直布局
  14. crossAxisAlignment: CrossAxisAlignment.center,//根据文本最长的对齐方式 center居中对齐 end尾部对齐 start头对齐
  15. mainAxisAlignment: MainAxisAlignment.center,//相对于Column界面垂直方向居中对齐
  16. children: <Widget>[
  17. Text("文本1"),
  18. //加入Expanded可以使文本3去到底部,文本1在顶部,文本2在文本1下面,Expanded把文本2进行了填充
  19. Expanded(child: Text("文本2文本2文本2文本2"),),
  20. Text("文本3"),
  21. ],
  22. )
  23. )
  24. ),
  25. );
  26. }
  27. }

Stack层叠布局

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget{
  4. @override
  5. Widget build(BuildContext context){
  6. var stack=new Stack(
  7. alignment: const FractionalOffset(0.5, 0.94),//配置文本的位置
  8. children: <Widget>[
  9. new CircleAvatar(//圆形图片
  10. backgroundImage: new NetworkImage('http://img5.mtime.cn/mt/2020/11/22/123214.39240924_1280X720X2.jpg'),
  11. radius: 100.0,
  12. ),
  13. new Container(//盒子容器
  14. decoration: new BoxDecoration(
  15. color: Colors.blue
  16. ),
  17. padding: EdgeInsets.all(5.0),
  18. child: Text("注意呀"),
  19. )
  20. ],
  21. );
  22. return MaterialApp(
  23. title: "后台标题",
  24. home: Scaffold(
  25. appBar: new AppBar(
  26. title: new Text("Stack层叠布局"),
  27. ),
  28. body:Center(
  29. child: stack,//引用stack
  30. )
  31. ),
  32. );
  33. }
  34. }

绝对定位(适合多元素重叠)

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget{
  4. @override
  5. Widget build(BuildContext context){
  6. var stack=new Stack(
  7. alignment: const FractionalOffset(0.5, 0.94),//配置文本的位置
  8. children: <Widget>[
  9. new CircleAvatar(//圆形图片
  10. backgroundImage: new NetworkImage('http://img5.mtime.cn/mt/2020/11/22/123214.39240924_1280X720X2.jpg'),
  11. radius: 100.0,
  12. ),
  13. new Positioned(//相对于css的绝对定位
  14. top: 10.0,
  15. left: 10.0,
  16. child: new Text("文本1"),
  17. ),
  18. new Positioned(
  19. bottom: 10.0,
  20. right: 10.0,
  21. child: new Text("文本2"),
  22. )
  23. ],
  24. );
  25. return MaterialApp(
  26. title: "后台标题",
  27. home: Scaffold(
  28. appBar: new AppBar(
  29. title: new Text("Stack层叠布局"),
  30. ),
  31. body:Center(
  32. child: stack,//引用stack
  33. )
  34. ),
  35. );
  36. }
  37. }

ListView和GridView网格第二章已有

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget{
  4. @override
  5. Widget build(BuildContext context){
  6. var card=new Card(//定义一个卡片布局
  7. child: Column(
  8. children: <Widget>[
  9. ListTile(
  10. title: Text('广东省普宁市',style: TextStyle(fontWeight: FontWeight.w500),),
  11. subtitle: Text("WWT1008611"),
  12. leading: new Icon(Icons.account_box,color: Colors.lightBlue,),
  13. ),new Divider(),//分割线
  14. ListTile(
  15. title: Text('广东省普宁市',style: TextStyle(fontWeight: FontWeight.w500),),
  16. subtitle: Text("WWT1008611"),
  17. leading: new Icon(Icons.account_box,color: Colors.lightBlue,),
  18. ),new Divider(),//分割线
  19. ListTile(
  20. title: Text('广东省普宁市',style: TextStyle(fontWeight: FontWeight.w500),),
  21. subtitle: Text("WWT1008611"),
  22. leading: new Icon(Icons.account_box,color: Colors.lightBlue,),
  23. ),
  24. ],
  25. ),
  26. );
  27. return MaterialApp(
  28. title: "后台标题",
  29. home: Scaffold(
  30. appBar: new AppBar(
  31. title: new Text("卡片布局"),
  32. ),
  33. body:Center(
  34. child: card,//引用card
  35. )
  36. ),
  37. );
  38. }
  39. }