• flutter chip标签组件


    //一个Material widget。 它可以将一个复杂内容实体展现在一个小块中,如联系人。
    import
    'package:flutter/material.dart'; class ChipDemo extends StatefulWidget { @override _ChipDemoState createState() => _ChipDemoState(); } class _ChipDemoState extends State<ChipDemo> { List<String> _tags = [ 'Apple', 'Banana', 'Lemon', ]; String _action = 'Nothing'; List<String> _selected = []; String _choice = 'Lemon'; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('ChipDemo'), elevation: 0.0, ), body: Container( padding: EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Wrap( spacing: 8.0, runSpacing: 8.0, children: <Widget>[ Chip( label: Text('Life'), ), Chip( label: Text('Sunset'), backgroundColor: Colors.orange, ), Chip( label: Text('Wanghao'), avatar: CircleAvatar( backgroundColor: Colors.grey, child: Text('皓'), ), ), Chip( label: Text('Wanghao'), avatar: CircleAvatar( backgroundImage: NetworkImage( 'https://resources.ninghao.net/images/wanghao.jpg' ), ), ), Chip( label: Text('City'), onDeleted: () {}, deleteIcon: Icon(Icons.delete), deleteIconColor: Colors.redAccent, deleteButtonTooltipMessage: 'Remove this tag', ), Divider( color: Colors.grey, height: 32.0, // indent: 32.0, ), Wrap( spacing: 8.0, children: _tags.map((tag) { return Chip( label: Text(tag), onDeleted: () { setState(() { _tags.remove(tag); }); }, ); }).toList(), ), Divider( color: Colors.grey, height: 32.0, // indent: 32.0, ), Container( double.infinity, child: Text('ActionChip: $_action'), ), Wrap( spacing: 8.0, children: _tags.map((tag) { return ActionChip( label: Text(tag), onPressed: () { setState(() { _action = tag; }); }, ); }).toList(), ), Divider( color: Colors.grey, height: 32.0, // indent: 32.0, ), Container( double.infinity, child: Text('FilterChip: ${_selected.toString()}'), ), Wrap( spacing: 8.0, children: _tags.map((tag) { return FilterChip( label: Text(tag), selected: _selected.contains(tag), onSelected: (value) { setState(() { if (_selected.contains(tag)) { _selected.remove(tag); } else { _selected.add(tag); } }); }, ); }).toList(), ), Divider( color: Colors.grey, height: 32.0, // indent: 32.0, ), Container( double.infinity, child: Text('ChoiceChip: $_choice'), ), Wrap( spacing: 8.0, children: _tags.map((tag) { return ChoiceChip( label: Text(tag), selectedColor: Colors.black, selected: _choice == tag, onSelected: (value) { setState(() { _choice = tag; }); }, ); }).toList(), ), ], ), ], ), ), floatingActionButton: FloatingActionButton( child: Icon(Icons.restore), onPressed: () { setState(() { _tags = [ 'Apple', 'Banana', 'Lemon', ]; _selected = []; _choice = 'Lemon'; }); }, ), ); } }

     效果:

  • 相关阅读:
    求随机数平均值方法 求随机数方差方法 求正态分布的随机数
    combox 绑定
    winform界面textbox框 鼠标经过时出现浮动
    Regex
    C# 3.0 一行求方差
    通过Linq 实现DataTable Group By
    ORACLE 时间运算
    发布几个国外的XHTML模板站,DIV+CSS模板下载
    C# 3.0新特性系列:隐含类型var
    在NTier 或多层应用程序中使用ADO.NET Entity Framework
  • 原文地址:https://www.cnblogs.com/loaderman/p/11342831.html
Copyright © 2020-2023  润新知