美文网首页Flutter
Flutter(二十一)Scaffold

Flutter(二十一)Scaffold

作者: 天色将变 | 来源:发表于2019-07-17 21:31 被阅读5次

Scaffold是Flutter提供的一个组合widget内部封装了常用的控件

  • 导航栏
  • 侧边抽屉
  • 底部导航栏
  • 一个悬浮的按钮
属性
  • appBar://导航栏
  • drawer: new MyDrawer(), //左边抽屉
  • endDrawer: new MyDrawer(),// 右边抽屉
  • bottomNavigationBar: 底部导航
  • floatingActionButton: 悬浮按钮
  • floatingActionButtonLocation: 悬浮按钮的位置
  • floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,//???
  • persistentFooterButtons:// 底部导航栏上方的工具栏
  • bottomSheet: Icon(Icons.alarm),// persistentFooterButtons上方的widget
  • backgroundColor: Colors.red[200], //顶部导航栏与底部导航栏之间的背景色
  • resizeToAvoidBottomInset: false,//???
  • resizeToAvoidBottomPadding: false,//????
  • primary: true,//???
  • drawerDragStartBehavior: DragStartBehavior.down,//???
  • drawerScrimColor: ,//drawer拉出来后,drawer外的部分的颜色
image.png
class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        //导航栏
        title: Text("Scaffold"),
        actions: <Widget>[
          //导航栏右侧菜单
          IconButton(icon: Icon(Icons.add_alarm), onPressed: () {}),
        ],
      ),
      drawer: new MyDrawer(), //左边抽屉
      endDrawer: new MyDrawer(),// 右边抽屉
      bottomNavigationBar: BottomNavigationBar(
        // 底部导航
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: Icon(Icons.access_alarms), title: Text('alarm')),
          BottomNavigationBarItem(
              icon: Icon(Icons.search), title: Text('search')),
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('home')),
          BottomNavigationBarItem(icon: Icon(Icons.edit), title: Text('edit')),
        ],
        type: BottomNavigationBarType.fixed,
        currentIndex: _selectedIndex,
        fixedColor: Colors.blue,
        onTap: onTap,
      ),
      floatingActionButton: FloatingActionButton(
          //悬浮按钮
          child: Icon(Icons.add),
          onPressed: _onAdd),
      //floatingActionButton 的位置
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,// 按钮居中,
//      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
//      floatingActionButtonLocation: FloatingActionButtonLocation.startTop,
//      floatingActionButtonLocation: FloatingActionButtonLocation.miniStartTop,
//      floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
//      floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
//      floatingActionButtonLocation: FloatingActionButtonLocation.endTop,

//      floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,//???
    // 底部导航栏上方的工具栏
        persistentFooterButtons:<Widget>[
          Icon(Icons.edit),
          Icon(Icons.save_alt),
          Icon(Icons.verified_user),
        ],
      // persistentFooterButtons上方的widget
      bottomSheet: Icon(Icons.alarm),

      //顶部导航栏与底部导航栏之间的背景色
      backgroundColor: Colors.red[200],

      resizeToAvoidBottomInset: false,//???
      resizeToAvoidBottomPadding: false,//????

      primary: true,//???
      drawerDragStartBehavior: DragStartBehavior.down,//???
      drawerScrimColor: Colors.green[100],//drawer拉出来后,drawer外的部分的颜色
    );
  }

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

  void _onAdd() {}
}

class MyDrawer extends StatelessWidget {
  const MyDrawer({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(top: 38.0),
            child: Row(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 17.0),
                  child: ClipOval(
                    child: Image.asset(
                      "images/avatar3.jpg",
                      width: 80,
                    ),
                  ),
                ),
                Text(
                  "zzc",
                  style: TextStyle(fontWeight: FontWeight.bold),
                )
              ],
            ),
          ),
          Expanded(
            child: ListView(
              children: <Widget>[
                ListTile(
                  leading: const Icon(Icons.access_alarms),
                  title: const Text('access_alarms'),
                ),
                ListTile(
                  leading: const Icon(Icons.delete),
                  title: const Text('delete'),
                ),
                ListTile(
                  leading: const Icon(Icons.save),
                  title: const Text('save'),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

相关文章

网友评论

    本文标题:Flutter(二十一)Scaffold

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