Flutter开发之——Scaffold

一 概述(Scaffold)

  • Scaffold译为脚手架,建筑领域中,指保证施工过程顺利而搭建的工作平台
  • 在编程领域中与此类似,脚手架的作用就像是一个功能强大的布局容器
  • Scaffold容器中定义好了导航栏、抽屉、悬浮按钮、内容试图等区域
  • 开发者只需要根据界面的需要,来填充脚手架的内容即可

二 Scaffold介绍

2.1 Scaffold源码

class Scaffold extends StatefulWidget {
  /// Creates a visual scaffold for material design widgets.
  const Scaffold({
    Key? key,
    this.appBar, //布局顶部的appBar工具栏
    this.body, //内容区域
    this.floatingActionButton, //悬浮按钮
    this.floatingActionButtonLocation, //悬浮按钮位置
    this.floatingActionButtonAnimator, //悬浮按钮动画
    this.persistentFooterButtons,//介于[body]和[bottomNavigationBar]之间的一组按钮
    this.drawer, //左边的抽屉
    this.onDrawerChanged,//左边抽屉发生变化
    this.endDrawer, //右边的抽屉
    this.onEndDrawerChanged, //右边抽屉发生变化
    this.bottomNavigationBar, //底部导航菜单
    this.bottomSheet,//底部持久化提示框
    this.backgroundColor, //内容背景色
    this.resizeToAvoidBottomPadding,//键盘出现时,界面重新布局(已过时)
    this.resizeToAvoidBottomInset, //键盘出现时,界面重新布局(代替resizeToAvoidBottomPadding)
    this.primary = true,//AppBar是否显示在屏幕顶部(默认显示为true)
    this.drawerDragStartBehavior = DragStartBehavior.start,
    this.extendBody = false,
    this.extendBodyBehindAppBar = false,
    this.drawerScrimColor,
    this.drawerEdgeDragWidth,
    this.drawerEnableOpenDragGesture = true,
    this.endDrawerEnableOpenDragGesture = true,
  }) : assert(primary != null),
       assert(extendBody != null),
       assert(extendBodyBehindAppBar != null),
       assert(drawerDragStartBehavior != null),
       super(key: key);

2.2 属性解释

属性名说明取值
appBar导航栏AppBar对象
backgroundColor背景颜色Color对象
body内容Widget
bottomNavigationBar底部导航栏Widget
bottomSheet持久化显示的底部抽屉Widget
drawer左侧抽屉Widget
endDrawer右侧抽屉Widget
floatingActionButton悬浮按钮Widget
persistentFooterButtons底部按钮组件List<Widget>
primaryappBar是否从屏幕顶部布局bool对象

2.3 Scaffold中组件

2.3.1 AppBar
属性名说明取值
actions按钮列表List<Widget>
backgroundColor背景颜色Color
centerTitle是否居中bool
leading标题左侧组件Widget
title标题Widget
2.3.2 BottomNavigationBar
属性名说明取值
items标签组(多个值)List<BottomNavigationBarItem>
onTap点击标签的回调Func
BottomNavigationBarType设置类型fixed-自适应宽度
shifting-位置和尺寸都有单击动画
fixedColor选中颜色Color
backgroundColor背景颜色Color
inconSize图标尺寸,默认24数值
selectedItemColor选中标签颜色Color
unselectedItemColor未选中标签颜色Color
selectedIconTheme选中风格
unselectedIconTheme未选中风格

三 示例

3.1 代码

Scaffold(
      appBar: AppBar(title: Text(widget.title),
      backgroundColor:Colors.orange ,
        centerTitle: true,
        //leading: Text("左侧组件"),
      ),
      bottomNavigationBar: BottomNavigationBar(items: [
        BottomNavigationBarItem(icon: Icon(Icons.print),title: Text("打印")),
        BottomNavigationBarItem(icon: Icon(Icons.stop),title: Text("停止")),
      ],
      type: BottomNavigationBarType.fixed,
        backgroundColor: Colors.blue,
        iconSize: 34,
        selectedItemColor: Colors.red,
        unselectedItemColor: Colors.cyan,
      ),
      //bottomSheet: Text("持久化显示底部抽屉"),
      resizeToAvoidBottomPadding: true,
      resizeToAvoidBottomInset: true,
      drawer: Drawer(
          child: Center(
            child: Container(
              color: Colors.orange,
              child: Text('左侧边栏',style: TextStyle(color: Colors.white,fontSize: 24.0),),
            ),
          )
      ),
      onDrawerChanged: _drawLeftChange ,
      onEndDrawerChanged: _drawEndChange,
      endDrawer: Drawer(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text("右侧抽屉"),
              Text("右侧抽屉"),
              Text("右侧抽屉"),
            ],
          )
      ),
      persistentFooterButtons: [Icon(Icons.send),Text("One"),RaisedButton.icon(onPressed: (){}, icon: Icon(Icons.print), label: Text("打印"))],
      backgroundColor: Colors.grey,
      primary: true,
      extendBody: false,
      body: Column(
        children: <Widget>[
          Text("Body",textScaleFactor: 2,),

        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );

3.2 效果图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值