Scaffold属性概要

  • 页面的脚手架

    1. Scaffold({
    2. // 键
    3. Key key,
    4. // 顶部导航栏
    5. this.appBar,
    6. // 应用主体部分
    7. this.body,
    8. // 悬浮按钮
    9. this.floatingActionButton,
    10. // 悬浮按钮位置
    11. this.floatingActionButtonLocation,
    12. // 悬浮按钮动画
    13. this.floatingActionButtonAnimator,
    14. // 底部按钮(在bottomNavigationBar)
    15. this.persistentFooterButtons,
    16. // 左侧菜单栏
    17. this.drawer,
    18. // 右侧菜单栏
    19. this.endDrawer,
    20. // 底部导航栏
    21. this.bottomNavigationBar,
    22. // 底部抽屉(应该不是底部抽屉的意思)
    23. this.bottomSheet,
    24. // 背景颜色
    25. this.backgroundColor,
    26. // 调整Scaffold大小,避免部件被遮挡住(如软键盘弹出时),已弃用,使用resizeToAvoidBottomInset代替
    27. this.resizeToAvoidBottomPadding,
    28. // 如果为true,则body和scaffold的浮动窗口小部件应自行调整大小,以避免屏幕键盘的高度由环境MediaQuery的MediaQueryData.viewInsets bottom属性定义
    29. this.resizeToAvoidBottomInset,
    30. // 一般情况下为默认为true,与appBar高度及显示位置有关
    31. this.primary = true,
    32. // 抽屉拖动启动行为
    33. this.drawerDragStartBehavior = DragStartBehavior.start,
    34. // 拓展体,值为true时,
    35. this.extendBody = false,
    36. // 抽屉蒙层颜色:抽屉打开没覆盖到的地方蒙层的颜色
    37. this.drawerScrimColor,
    38. // 抽屉边缘拖拽宽度:离抽屉多远可以拖拽出抽屉
    39. this.drawerEdgeDragWidth,
    40. })
  • key的创建,key相当于当前Scaffold的引用 ```dart final _scaffoldKey = GlobalKey();

@override Widget build(BuildContext context) { return Scaffold( key: _scaffoldKey, body: Container( alignment: Alignment.bottomCenter, child: TextField(), ), ); }

```

  • resizeToAvoidBottomInset及resizeToAvoidBottomPadding(已废弃,不推荐使用,和前者作用相同)属性差异比对

设置边距自动.gif设置边距自动值未true.gif
resizeToAvoidBottomInset值为false resizeToAvoidBottomInset值为true

  • extendBody属性差异比对

image.pngimage.png
extendBody值为false extendBody值为true