美文网首页Flutter
Flutter(十九)FloatingActionButton

Flutter(十九)FloatingActionButton

作者: 天色将变 | 来源:发表于2019-07-17 20:22 被阅读3次

一个悬浮按钮

属性
  • child: Icon(Icons.add),
  • onPressed: _onAdd,// 点击调用方法
  • tooltip: 'aaa',// 长按后的toast提示
  • foregroundColor: Colors.red,//前景色,对一些透明处覆盖颜色
  • backgroundColor: Colors.red[200],//背景色
  • focusColor: Colors.blue,// ???
  • hoverColor: Colors.blue,// ???
  • hoverElevation: 10,// ???
  • focusElevation: 10,// ???
  • disabledElevation: 10,//button禁用时的嘤嘤大小
  • elevation: 10,//正常状态下阴影大小
  • highlightElevation: 20,// 高亮状态下阴影大小
  • mini: false,// 是否最小,默认false
  • shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),// 设置形状
  • clipBehavior: Clip.antiAliasWithSaveLayer,// ???
  • isExtended: true,// ???
  • materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,//???
image.png
class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        //导航栏
        title: Text("App Name"),
        actions: <Widget>[
          //导航栏右侧菜单
          IconButton(icon: Icon(Icons.share), onPressed: () {}),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        // 底部导航
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
          BottomNavigationBarItem(
              icon: Icon(Icons.business), title: Text('Business')),
          BottomNavigationBarItem(
              icon: Icon(Icons.school), title: Text('School')),
        ],
        currentIndex: _selectedIndex,
        fixedColor: Colors.blue,
        onTap: _onItemTapped,
      ),
      floatingActionButton: FloatingActionButton(
          //悬浮按钮
          child: Icon(Icons.add),
          onPressed: _onAdd,// 点击调用方法
        tooltip: 'aaa',// 长按后的toast提示
        foregroundColor: Colors.red,//前景色,对一些透明处覆盖颜色
        backgroundColor: Colors.red[200],//背景色
        focusColor: Colors.blue,// ???
        hoverColor: Colors.blue,// ???
        hoverElevation: 10,// ???
        focusElevation: 10,// ???
        disabledElevation: 10,//button禁用时的嘤嘤大小
        elevation: 10,//正常状态下阴影大小
        highlightElevation: 20,// 高亮状态下阴影大小
        mini: false,// 是否最小,默认false
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),// 设置形状
        clipBehavior: Clip.antiAliasWithSaveLayer,// ???
        isExtended: true,// ???
        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,//???
      ),
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  void _onAdd() {
    setState(() {
      _selectedIndex++;
      if (_selectedIndex > 2) {
        _selectedIndex = 0;
      }
    });
  }
}

相关文章

网友评论

    本文标题:Flutter(十九)FloatingActionButton

    本文链接:https://www.haomeiwen.com/subject/anoclctx.html