zoukankan      html  css  js  c++  java
  • 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'; }); }, ), ); } }

     效果:

  • 相关阅读:
    [转]为什么阿里巴巴要禁用Executors创建线程池?
    支付宝的架构到底有多牛逼!
    [转] Java Agent使用详解
    Spring Boot必备技能之Starter自定义
    面试题:JVM 堆内存溢出后,其他线程是否可继续工作?
    Docker 容器化应用
    Python Click 学习笔记
    MySQL优化(7):其他注意事项
    MySQL优化(6):分表和读写分离
    MySQL优化(5):分区
  • 原文地址:https://www.cnblogs.com/loaderman/p/11342831.html
Copyright © 2011-2022 走看看