1 进度指示器

LinearProgressIndicator

  1. // 模糊进度条(会执行一个动画)
  2. LinearProgressIndicator(
  3. backgroundColor: Colors.grey[200],
  4. valueColor: AlwaysStoppedAnimation(Colors.blue),
  5. ),
  6. //进度条显示50%
  7. LinearProgressIndicator(
  8. backgroundColor: Colors.grey[200],
  9. valueColor: AlwaysStoppedAnimation(Colors.blue),
  10. value: .5,
  11. )

CircularProgressIndicator

  1. // 模糊进度条(会执行一个旋转动画)
  2. CircularProgressIndicator(
  3. backgroundColor: Colors.grey[200],
  4. valueColor: AlwaysStoppedAnimation(Colors.blue),
  5. ),
  6. //进度条显示50%,会显示一个半圆
  7. CircularProgressIndicator(
  8. backgroundColor: Colors.grey[200],
  9. valueColor: AlwaysStoppedAnimation(Colors.blue),
  10. value: .5,
  11. ),

自定义尺寸

  1. // 线性进度条高度指定为3
  2. SizedBox(
  3. height: 3,
  4. child: LinearProgressIndicator(
  5. backgroundColor: Colors.grey[200],
  6. valueColor: AlwaysStoppedAnimation(Colors.blue),
  7. value: .5,
  8. ),
  9. ),
  10. // 圆形进度条直径指定为100
  11. SizedBox(
  12. height: 100,
  13. width: 100,
  14. child: CircularProgressIndicator(
  15. backgroundColor: Colors.grey[200],
  16. valueColor: AlwaysStoppedAnimation(Colors.blue),
  17. value: .7,
  18. ),
  19. ),

进度色动画

  1. //实现一个进度条在3秒内从灰色变成蓝色的动画:
  2. import 'package:flutter/material.dart';
  3. class ProgressRoute extends StatefulWidget {
  4. @override
  5. _ProgressRouteState createState() => _ProgressRouteState();
  6. }
  7. class _ProgressRouteState extends State<ProgressRoute>
  8. with SingleTickerProviderStateMixin {
  9. AnimationController _animationController;
  10. @override
  11. void initState() {
  12. //动画执行时间3秒
  13. _animationController =
  14. new AnimationController(vsync: this, duration: Duration(seconds: 3));
  15. _animationController.forward();
  16. _animationController.addListener(() => setState(() => {}));
  17. super.initState();
  18. }
  19. @override
  20. void dispose() {
  21. _animationController.dispose();
  22. super.dispose();
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return SingleChildScrollView(
  27. child: Column(
  28. children: <Widget>[
  29. Padding(
  30. padding: EdgeInsets.all(16),
  31. child: LinearProgressIndicator(
  32. backgroundColor: Colors.grey[200],
  33. valueColor: ColorTween(begin: Colors.grey, end: Colors.blue)
  34. .animate(_animationController), // 从灰色变成蓝色
  35. value: _animationController.value,
  36. ),
  37. );
  38. ],
  39. ),
  40. );
  41. }
  42. }

自定义进度条:CustomPainter

https://github.com/yumi0629/FlutterUI/blob/master/lib/circleprogressbar/circle_progress_bar.dart

2 可收缩面板ExpandPanel

  1. import 'package:flutter/material.dart';
  2. class ExpansionPanelItem {
  3. final String headerText;
  4. final Widget body;
  5. bool isExpanded;
  6. ExpansionPanelItem({
  7. this.headerText,
  8. this.body,
  9. this.isExpanded,
  10. });
  11. }
  12. class ExpansionPanelDemo extends StatefulWidget {
  13. @override
  14. _ExpansionPanelDemoState createState() => _ExpansionPanelDemoState();
  15. }
  16. class _ExpansionPanelDemoState extends State<ExpansionPanelDemo> {
  17. bool _isExpand = false;
  18. List<ExpansionPanelItem> _expansionPanelItems;
  19. @override
  20. void initState() {
  21. // TODO: implement initState
  22. super.initState();
  23. _expansionPanelItems = <ExpansionPanelItem>[
  24. ExpansionPanelItem(
  25. headerText: 'Panel A',
  26. body: Container(
  27. padding: EdgeInsets.all(16.0),
  28. width: double.infinity,
  29. child: Text('Content for Panel A'),
  30. ),
  31. isExpanded: false,
  32. ),
  33. ExpansionPanelItem(
  34. headerText: 'Panel B',
  35. body: Container(
  36. padding: EdgeInsets.all(16.0),
  37. width: double.infinity,
  38. child: Text('Content for Panel B'),
  39. ),
  40. isExpanded: false,
  41. ),
  42. ExpansionPanelItem(
  43. headerText: 'Panel C',
  44. body: Container(
  45. padding: EdgeInsets.all(16.0),
  46. width: double.infinity,
  47. child: Text('Content for Panel C'),
  48. ),
  49. isExpanded: false,
  50. )
  51. ];
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return Scaffold(
  56. appBar: AppBar(
  57. title: Text('ExpansionPanelDemo'),
  58. elevation: 0.0,
  59. ),
  60. body: Container(
  61. padding: EdgeInsets.all(16.0),
  62. child: Column(
  63. mainAxisAlignment: MainAxisAlignment.center,
  64. children: <Widget>[
  65. ExpansionPanelList(
  66. expansionCallback: (panelIndex, isExpanded) {
  67. setState(() {
  68. _expansionPanelItems[panelIndex].isExpanded =
  69. !_expansionPanelItems[panelIndex].isExpanded;
  70. });
  71. },
  72. children: _expansionPanelItems.map((ExpansionPanelItem item) {
  73. return ExpansionPanel(
  74. isExpanded: item.isExpanded,
  75. body: item.body,
  76. headerBuilder: (BuildContext context, bool isExpanded) {
  77. return Container(
  78. padding: EdgeInsets.all(16.0),
  79. child: Text(
  80. item.headerText,
  81. style: Theme.of(context).textTheme.title,
  82. ),
  83. );
  84. });
  85. }).toList(),
  86. ),
  87. ],
  88. ),
  89. ),
  90. );
  91. }
  92. }

3 SizedBox

  1. 能强制子控件具有特定宽度、高度或两者都有,使子控件设置的宽高失效

4 步骤控件Stepper

image.png

  1. int _currentStep = 0;
  2. Widget build(BuildContext context) {
  3. return Scaffold(
  4. appBar: AppBar(
  5. title: Text('StepDemo'),
  6. elevation: 0.0,
  7. ),
  8. body: Container(
  9. padding: EdgeInsets.all(16.0),
  10. child: Column(
  11. mainAxisAlignment: MainAxisAlignment.center,
  12. children: <Widget>[
  13. Theme(
  14. data: Theme.of(context).copyWith(
  15. primaryColor: Colors.black,
  16. ),
  17. child: Stepper(
  18. controlsBuilder: (BuildContext context,
  19. {VoidCallback onStepContinue, VoidCallback onStepCancel}) {
  20. return Row(
  21. children: <Widget>[
  22. FlatButton(
  23. onPressed: onStepContinue,
  24. child: const Text('CONTINUE'),
  25. ),
  26. FlatButton(
  27. onPressed: onStepCancel,
  28. child: const Text('Up Step'),
  29. ),
  30. ],
  31. );
  32. },
  33. currentStep: _currentStep,
  34. onStepTapped: (int value) {
  35. setState(() {
  36. _currentStep = value;
  37. });
  38. },
  39. onStepContinue: () {
  40. setState(() {
  41. _currentStep < 2 ? _currentStep += 1 : _currentStep = 0;
  42. });
  43. },
  44. onStepCancel: () {
  45. setState(() {
  46. _currentStep > 0 ? _currentStep -= 1 : _currentStep = 0;
  47. });
  48. },
  49. steps: [
  50. Step(
  51. title: Text("Login"),
  52. subtitle: Text('Login first'),
  53. content: Text(
  54. 'Cupidatat sunt voluptate esse velit dolor voluptate elit amet pariatur et amet in.'),
  55. isActive: _currentStep == 0,
  56. ),
  57. Step(
  58. title: Text("Choose Plan"),
  59. subtitle: Text('Choose you plan'),
  60. content: Text(
  61. 'Cupidatat sunt voluptate esse velit dolor voluptate elit amet pariatur et amet in.'),
  62. isActive: _currentStep == 1,
  63. ),
  64. Step(
  65. title: Text("Confirm payment"),
  66. subtitle: Text('Confirm your payment method'),
  67. content: Text(
  68. 'Cupidatat sunt voluptate esse velit dolor voluptate elit amet pariatur et amet in.'),
  69. isActive: _currentStep == 2,
  70. )
  71. ],
  72. ),
  73. )
  74. ],
  75. ),
  76. ),
  77. );
  78. }

5 抽屉Drawer:

抽屉分为左抽屉(drawer)和右侧抽屉(endDrawer)

  1. class DrawerDemo extends StatelessWidget{
  2. @override
  3. Widget build(BuildContext context) {
  4. // TODO: implement build
  5. return Drawer(//抽屉
  6. child: ListView(
  7. padding: EdgeInsets.zero,
  8. children: <Widget>[
  9. UserAccountsDrawerHeader(
  10. accountName: Text('wangqiao',style:TextStyle(fontWeight: FontWeight.bold)),
  11. accountEmail: Text('wangqiao@hotoneaudio.com'),
  12. currentAccountPicture: CircleAvatar(//圆形头像
  13. backgroundImage: NetworkImage('https://resources.ninghao.org/images/wanghao.jpg'),
  14. ),
  15. decoration: BoxDecoration(//抽屉头的装饰器
  16. color: Colors.yellow[400],//背景色
  17. image: DecorationImage(
  18. image: NetworkImage('https://resources.ninghao.org/images/childhood-in-a-picture.jpg'),//背景图片
  19. fit: BoxFit.cover,//填充形式
  20. colorFilter: ColorFilter.mode(//颜色的过滤器
  21. Colors.yellow[400].withOpacity(0.6),
  22. BlendMode.hardLight
  23. ),
  24. ),
  25. ),
  26. ),
  27. ListTile(
  28. title: Text('Messages',textAlign: TextAlign.right,),
  29. trailing: Icon(Icons.message,color:Colors.black12,size:22.0),
  30. leading: Icon(Icons.menu,color:Colors.black12,size:22.0),
  31. onTap: ()=>Navigator.pop(context),
  32. ),
  33. ListTile(
  34. title: Text('Favorite',textAlign: TextAlign.right,),
  35. trailing: Icon(Icons.favorite,color:Colors.black12,size:22.0),
  36. leading: Icon(Icons.search,color:Colors.black12,size:22.0),
  37. onTap: ()=>Navigator.pop(context),
  38. ),
  39. ListTile(
  40. title: Text('Settings',textAlign: TextAlign.right,),
  41. trailing: Icon(Icons.settings,color:Colors.black12,size:22.0),
  42. leading: Icon(Icons.folder,color:Colors.black12,size:22.0),
  43. onTap: ()=>Navigator.pop(context),
  44. ),
  45. ],
  46. ),
  47. );//左侧抽屉;
  48. }
  49. }

6 时间和日期选择器

DatePicker:showDatePicker

TimePicker:showTimePicker

  1. import 'package:flutter/material.dart';
  2. import 'package:intl/intl.dart';
  3. import 'dart:async';
  4. class DateTimeDemo extends StatefulWidget {
  5. @override
  6. _DateTimeDemoState createState() => _DateTimeDemoState();
  7. }
  8. class _DateTimeDemoState extends State<DateTimeDemo> {
  9. DateTime selectedDate = DateTime.now();
  10. TimeOfDay selectedTime = TimeOfDay(hour: 9, minute: 30);
  11. Future<void> _selectDate() async //异步
  12. {
  13. final DateTime date = await showDatePicker( //等待异步处理的结果
  14. //等待返回
  15. context: context,
  16. initialDate: selectedDate,
  17. firstDate: DateTime(1900),
  18. lastDate: DateTime(2100),
  19. );
  20. if (date == null) return; //点击DatePicker的cancel
  21. setState(() {
  22. //点击DatePicker的OK
  23. selectedDate = date;
  24. });
  25. }
  26. Future<void> _seletedTime() async {//异步
  27. final TimeOfDay time = await showTimePicker( //等待异步处理的结果
  28. context: context,
  29. initialTime: selectedTime,
  30. );
  31. if (time == null) return;
  32. setState(() {
  33. selectedTime = time;
  34. });
  35. }
  36. @override
  37. Widget build(BuildContext context) {
  38. return Scaffold(
  39. appBar: AppBar(
  40. title: Text('DateTimeDemo'),
  41. elevation: 0.0,
  42. ),
  43. body: Container(
  44. padding: EdgeInsets.all(16.0),
  45. child: Column(
  46. mainAxisAlignment: MainAxisAlignment.center,
  47. children: <Widget>[
  48. Row(
  49. mainAxisAlignment: MainAxisAlignment.center,
  50. children: <Widget>[
  51. InkWell(
  52. //包装一个相应点击的组件
  53. onTap: _selectDate,
  54. child: Row(
  55. children: <Widget>[
  56. // Text(DateFormat.yMd().format(selectedDate)),// 5/10/2019
  57. // Text(DateFormat.yMMM().format(selectedDate)),// May 2019
  58. Text(DateFormat.yMMMd()
  59. .format(selectedDate)), // May 10, 2019
  60. // Text(DateFormat.yMMMMd().format(selectedDate)),// May 10, 2019
  61. Icon(Icons.arrow_drop_down),
  62. ],
  63. ),
  64. ),
  65. InkWell(
  66. //包装一个相应点击的组件
  67. onTap: _seletedTime,
  68. child: Row(
  69. children: <Widget>[
  70. Text(selectedTime.format(context)), // May 10, 2019
  71. Icon(Icons.arrow_drop_down),
  72. ],
  73. ),
  74. )
  75. ],
  76. ),
  77. ],
  78. ),
  79. ),
  80. );
  81. }
  82. }

7 标签 Chip

  1. import 'package:flutter/material.dart';
  2. class ChipDemo extends StatefulWidget {
  3. @override
  4. _ChipDemoState createState() => _ChipDemoState();
  5. }
  6. class _ChipDemoState extends State<ChipDemo> {
  7. @override
  8. Widget build(BuildContext context) {
  9. return Scaffold(
  10. appBar: AppBar(
  11. title: Text('ChipDemo'),
  12. elevation: 0.0,
  13. ),
  14. body: Container(
  15. padding: EdgeInsets.all(16.0),
  16. child: Column(
  17. mainAxisAlignment: MainAxisAlignment.center,
  18. children: <Widget>[
  19. Wrap(//自动换行
  20. spacing: 8.0, //一行中两个chip的间距,当不设置时,自动调整间隔
  21. runSpacing: 8.0, //两行之间的间距
  22. children: <Widget>[
  23. Chip(
  24. label: Text('Life')
  25. ),
  26. Chip(
  27. label: Text('Sunset'),
  28. backgroundColor: Colors.orange,
  29. ),
  30. Chip(
  31. label: Text('Wanghao'),
  32. avatar: CircleAvatar(
  33. backgroundColor:Colors.grey,
  34. child:Text('皓'),
  35. ),
  36. ),
  37. Chip(
  38. label: Text('Wanghao'),
  39. avatar: CircleAvatar(
  40. backgroundImage:NetworkImage('https://resources.ninghao.org/images/wanghao.jpg'),
  41. ),
  42. ),
  43. ],
  44. ),
  45. ],
  46. ),
  47. ),
  48. );
  49. }
  50. }

8 对话框

AlertDialog

  1. import 'package:flutter/material.dart';
  2. import 'package:intl/intl.dart';
  3. class AlertDialogDemo extends StatefulWidget {
  4. @override
  5. _AlertDialogDemoState createState() => _AlertDialogDemoState();
  6. }
  7. enum Action { Cancel, OK }
  8. class _AlertDialogDemoState extends State<AlertDialogDemo> {
  9. String _choice = 'Nothing';
  10. Future _openAlertDialog() async {
  11. final action = await showDialog(
  12. context: context,
  13. barrierDismissible: false, // 点击提示框外围不消失
  14. builder: (BuildContext context) {
  15. return AlertDialog(
  16. title: Text('AlertDialog'),
  17. content: Text('Are you sure about this ?'),
  18. actions: <Widget>[
  19. FlatButton(
  20. child: Text('Cancel'),
  21. onPressed: () {
  22. Navigator.pop(context, Action.Cancel);
  23. },
  24. ),
  25. FlatButton(
  26. child: Text('OK'),
  27. onPressed: () {
  28. Navigator.pop(context, Action.OK);
  29. },
  30. ),
  31. ],
  32. );
  33. });
  34. switch (action) {
  35. case Action.OK:
  36. setState(() {
  37. _choice = 'OK';
  38. });
  39. break;
  40. case Action.Cancel:
  41. setState(() {
  42. _choice = 'Cancel';
  43. });
  44. break;
  45. default:
  46. }
  47. }
  48. @override
  49. Widget build(BuildContext context) {
  50. return Scaffold(
  51. appBar: AppBar(
  52. title: Text('AlertDialogDemo'),
  53. elevation: 0.0,
  54. ),
  55. body: Container(
  56. padding: EdgeInsets.all(16.0),
  57. child: Column(
  58. mainAxisAlignment: MainAxisAlignment.center,
  59. children: <Widget>[
  60. Text('Your choice is : $_choice'),
  61. SizedBox(height: 16.0),
  62. Row(
  63. mainAxisAlignment: MainAxisAlignment.center,
  64. children: <Widget>[
  65. RaisedButton(
  66. child: Text('Open AlertDialog'),
  67. onPressed: _openAlertDialog,
  68. ),
  69. ],
  70. )
  71. ],
  72. ),
  73. ),
  74. );
  75. }
  76. }

sheet

弹出的底部sheet,有模态(showModalBottomSheet)和非模态两种(showBottomSheet)

  1. import 'package:flutter/material.dart';
  2. import 'package:intl/intl.dart';
  3. class BottomSheetDemo extends StatefulWidget {
  4. @override
  5. _BottomSheetDemoState createState() => _BottomSheetDemoState();
  6. }
  7. class _BottomSheetDemoState extends State<BottomSheetDemo> {
  8. final _BottomSheetScaffoldKey = GlobalKey<ScaffoldState>();
  9. Future _openModelBottomSheet() async {
  10. final option = await showModalBottomSheet(
  11. context: context,
  12. builder: (BuildContext context) {
  13. return Container(
  14. height: 200,
  15. child: Column(
  16. children: <Widget>[
  17. ListTile(
  18. title: Text('Option A'),
  19. onTap: () {
  20. Navigator.pop(context, 'A');
  21. },
  22. ),
  23. ListTile(
  24. title: Text('Option B'),
  25. onTap: () {
  26. Navigator.pop(context, 'B');
  27. },
  28. ),
  29. ListTile(
  30. title: Text('Option C'),
  31. onTap: () {
  32. Navigator.pop(context, 'C');
  33. },
  34. ),
  35. ],
  36. ),
  37. );
  38. });
  39. print(option);
  40. }
  41. _openBottomSheet() {
  42. _BottomSheetScaffoldKey.currentState
  43. .showBottomSheet((BuildContext context) {
  44. return BottomAppBar(
  45. child: Container(
  46. height: 90.0,
  47. width: double.infinity,
  48. padding: EdgeInsets.all(16),
  49. child: Row(
  50. children: <Widget>[
  51. Icon(Icons.pause_circle_outline),
  52. SizedBox(width: 16.0),
  53. Text('01:30/03:30'),
  54. Expanded(
  55. child: Text('Fix you - Coldplay', textAlign: TextAlign.right),
  56. )
  57. ],
  58. ),
  59. ),
  60. );
  61. });
  62. }
  63. @override
  64. Widget build(BuildContext context) {
  65. return Scaffold(
  66. appBar: AppBar(
  67. title: Text('BottomSheetDemo'),
  68. elevation: 0.0,
  69. ),
  70. key: _BottomSheetScaffoldKey,
  71. body: Container(
  72. padding: EdgeInsets.all(16.0),
  73. child: Column(
  74. mainAxisAlignment: MainAxisAlignment.center,
  75. children: <Widget>[
  76. FlatButton(
  77. child: Text('Open BottomSheet'),
  78. onPressed: _openBottomSheet,
  79. ),
  80. FlatButton(
  81. child: Text('Open ModelBottomSheet'),
  82. onPressed: _openModelBottomSheet,
  83. )
  84. ],
  85. ),
  86. ),
  87. );
  88. }
  89. }

SimpleDialog

  1. import 'package:flutter/material.dart';
  2. import 'package:intl/intl.dart';
  3. class DialogDemo extends StatefulWidget {
  4. @override
  5. _DialogDemoState createState() => _DialogDemoState();
  6. }
  7. enum Option { A, B, C }
  8. class _DialogDemoState extends State<DialogDemo> {
  9. String _choice = 'Nothing';
  10. @override
  11. Widget build(BuildContext context) {
  12. _openSimpleDialog() async {
  13. final option = await showDialog(
  14. context: context,
  15. builder: (BuildContext context) {
  16. return SimpleDialog(
  17. title: Text('SimpleDialog'),
  18. children: <Widget>[
  19. SimpleDialogOption(
  20. child: Text('Option A'),
  21. onPressed: () {
  22. Navigator.pop(context, Option.A);
  23. },
  24. ),
  25. SimpleDialogOption(
  26. child: Text('Option B'),
  27. onPressed: () {
  28. Navigator.pop(context, Option.B);
  29. },
  30. ),
  31. SimpleDialogOption(
  32. child: Text('Option C'),
  33. onPressed: () {
  34. Navigator.pop(context, Option.C);
  35. },
  36. ),
  37. ],
  38. );
  39. },
  40. );
  41. switch (option) {
  42. case Option.A:
  43. setState(() {
  44. _choice = 'A';
  45. });
  46. break;
  47. case Option.B:
  48. setState(() {
  49. _choice = 'B';
  50. });
  51. break;
  52. case Option.C:
  53. setState(() {
  54. _choice = 'C';
  55. });
  56. break;
  57. default:
  58. }
  59. }
  60. return Scaffold(
  61. appBar: AppBar(
  62. title: Text('ShowDialog'),
  63. elevation: 0.0,
  64. ),
  65. floatingActionButton: FloatingActionButton(
  66. child: Icon(Icons.format_list_numbered),
  67. onPressed: _openSimpleDialog,
  68. ),
  69. body: Container(
  70. padding: EdgeInsets.all(16.0),
  71. child: Column(
  72. mainAxisAlignment: MainAxisAlignment.center,
  73. children: <Widget>[
  74. Row(
  75. mainAxisAlignment: MainAxisAlignment.center,
  76. children: <Widget>[
  77. Text('Your choice is : $_choice'),
  78. ],
  79. ),
  80. ],
  81. ),
  82. ),
  83. );
  84. }
  85. }

SnackBar :过一会会消失

  1. import 'package:flutter/material.dart';
  2. class SnackBarDemo extends StatefulWidget {
  3. @override
  4. _SnackBarDemoState createState() => _SnackBarDemoState();
  5. }
  6. class _SnackBarDemoState extends State<SnackBarDemo> {
  7. @override
  8. Widget build(BuildContext context) {
  9. return Scaffold(
  10. appBar: AppBar(
  11. title: Text('SnackBarDemo'),
  12. elevation: 0.0,
  13. ),
  14. body: Container(
  15. padding: EdgeInsets.all(16.0),
  16. child: Column(
  17. mainAxisAlignment: MainAxisAlignment.center,
  18. children: <Widget>[
  19. Row(
  20. mainAxisAlignment: MainAxisAlignment.center,
  21. children: <Widget>[
  22. SnackbarButton(),
  23. ],
  24. ),
  25. ],
  26. ),
  27. ),
  28. );
  29. }
  30. }
  31. class SnackbarButton extends StatelessWidget {
  32. @override
  33. Widget build(BuildContext context) {
  34. // TODO: implement build
  35. return FlatButton(
  36. child: Text('Open SnackBa'),
  37. onPressed: () {
  38. Scaffold.of(context).showSnackBar(
  39. SnackBar(
  40. content: Text('Processing'),
  41. action: SnackBarAction(
  42. label: 'OK',
  43. onPressed: () {},
  44. ),
  45. ));
  46. });
  47. }
  48. }

Tooltip:

不打断用户操作,停顿时间比较少的提示,长按显示提示

  1. Tooltip(
  2. message: '不要碰我,我怕痒',
  3. child: Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1560316081080&di=de32c1eff5ca4ad78e8387d132d9109c&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F015e475725bd5432f875a399743555.png%401280w_1l_2o_100sh.png',
  4. fit:BoxFit.cover,
  5. scale: 2.0,
  6. ),
  7. )

9 FlutterLogo

  1. 一般用作占位图,<br />FlutterLogo属性
  • size:大小
  • colors:颜色
  • textColor:“Flutter”文本的颜色
  • style: FlutterLogoStyle.markOnly,是否以及在何处绘制“颤动”文本。默认情况下,仅绘制徽标本身
  • duration:动画的时长
  • curve:Curves.fastOutSlowIn 动画样式
    1. FlutterLogo(
    2. size: 100,
    3. textColor: Colors.red,
    4. duration: Duration(milliseconds: 3000),
    5. style: FlutterLogoStyle.stacked,
    6. curve: Curves.bounceIn,
    7. ),

    10 Clip

    ClipOval剪裁为圆形

    1. ClipOval(
    2. child: Container(
    3. height: 150,
    4. width: 150,
    5. color: Colors.red,
    6. ),
    7. )

    ClipRRect剪裁为圆角矩形

    ```dart

ClipRRect( borderRadius: BorderRadius.all(Radius.circular(20)), child: Container( height: 150, width: 150, color: Colors.red, ),

  1. <a name="cgtvE"></a>
  2. #### ClipRect 将溢出部分剪裁
  3. ```dart
  4. ClipRect(
  5. child: Container(
  6. height: 150,
  7. width: 150,
  8. color: Colors.red,
  9. ),

CustomClipper自定义剪裁

  • ClipRec中设置clipper
  • ClipPath 中设置clipBehavior控制剪辑方式

    1) Clip.none,没有剪辑 最快
    2) Clip.hardEdge,不抗锯齿 快
    3) Clip.antiAlias,抗锯齿 慢
    4) Clip.antiAliasWithSaveLayer, 抗锯齿和saveLayer 很慢
    默认 Clip.antiAlias

  • child 子控件 ```dart ClipPath( clipper: MyCustomClipperPath(), child: Container( height: 150, width: 150, color: Colors.red, ), ),

class MyCustomClipperPath extends CustomClipper { //获取裁剪范围 @override Path getClip(Size size) { //左上角为(0,0) var path = Path(); // 画一个小方块 path.moveTo(8.0, 8.0);//起始点 path.lineTo(8.0, 17.0); path.lineTo(17.0, 17.0); path.lineTo(17.0, 8.0);

  1. path.close();//
  2. return path;

}

//是否重新裁剪 @override bool shouldReclip(CustomClipper oldClipper) { return true; }

}

  1. [
  2. ](https://blog.csdn.net/ruoshui_t/article/details/100621793)
  3. <a name="nkv8D"></a>
  4. ### 11 Table
  5. 表格<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1994311/1621244296418-b0b537e5-36cc-4b16-8ef2-68ac5c372a51.png#clientId=ubece8d2a-8e82-4&from=paste&height=145&id=ube21bddd&margin=%5Bobject%20Object%5D&name=image.png&originHeight=290&originWidth=558&originalType=binary&size=37109&status=done&style=none&taskId=u1acb9feb-2a46-4ddf-91d1-4c8bc1b0259&width=279)
  6. ```dart
  7. import 'package:flutter/material.dart';
  8. void main() => runApp(new MyApp());
  9. class MyApp extends StatelessWidget {
  10. @override
  11. Widget build(BuildContext context) {
  12. return new MaterialApp(
  13. title: 'Table组件',
  14. home: new Scaffold(
  15. appBar: new AppBar(
  16. title: new Text('Table组件'),
  17. ),
  18. body: Center(
  19. child: Container(
  20. //表格
  21. child: Table(
  22. //所有列宽
  23. columnWidths: const {
  24. //列宽
  25. 0: FixedColumnWidth(100.0),
  26. 1: FixedColumnWidth(200.0),
  27. 2: FixedColumnWidth(50.0),
  28. },
  29. //表格边框样式
  30. border: TableBorder.all(
  31. color: Colors.green,
  32. width: 2.0,
  33. style: BorderStyle.solid,
  34. ),
  35. children: [
  36. TableRow(
  37. //第一行样式 添加背景色
  38. decoration: BoxDecoration(
  39. color: Colors.grey,
  40. ),
  41. children: [
  42. //增加行高
  43. SizedBox(
  44. height: 30.0,
  45. child: Text('姓名',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),),
  46. ),
  47. Text('性别',style: TextStyle(fontWeight: FontWeight.bold),),
  48. Text('年龄',style: TextStyle(fontWeight: FontWeight.bold),),
  49. ]
  50. ),
  51. TableRow(
  52. children: [
  53. Text('张三'),
  54. Text('男'),
  55. Text('20'),
  56. ]
  57. ),
  58. TableRow(
  59. children: [
  60. Text('小红'),
  61. Text('女'),
  62. Text('28'),
  63. ]
  64. ),
  65. TableRow(
  66. children: [
  67. Text('李四'),
  68. Text('男'),
  69. Text('28'),
  70. ]
  71. ),
  72. TableRow(
  73. children: [
  74. Text('机器猫'),
  75. SizedBox(
  76. width: 88.0,
  77. height: 88.0,
  78. child: Image.asset('assets/cat.jpeg'),
  79. ),
  80. Text('26'),
  81. ]
  82. ),
  83. ],
  84. ),
  85. ),
  86. ),
  87. ),
  88. );
  89. }
  90. }

12 Offstage

  1. 通过一个参数来控制child是否显示<br />当offstagetrue,控件隐藏; offstagefalse,显示; Offstage不可见的时候,如果child有动画等,需要手动停掉,Offstage并不会停掉动画等操作。
  1. const Offstage({ Key key, this.offstage = true, Widget child })
  1. <br />[

](https://blog.csdn.net/mxthing/article/details/97933954)