当前位置: 首页 > article >正文

Flutter组件————Scaffold

Scaffold

Scaffold 是一个基础的可视化界面结构组件,它实现了基本的Material Design布局结构。使用 Scaffold 可以快速地搭建起包含应用栏(AppBar)、内容区域(body)、抽屉菜单(Drawer)、底部导航栏(BottomNavigationBar)等元素的界面。

参数

Scaffold 参数列表

参数名类型描述
appBarPreferredSizeWidget设置页面顶部的应用栏,通常是一个 AppBar 组件。
bodyWidget页面的主要内容区域,可以是任意类型的 widget。
floatingActionButtonWidget定义浮动按钮,通常是一个 FloatingActionButton 组件。
floatingActionButtonLocationFloatingActionButtonLocation定义浮动按钮的位置,默认为 FloatingActionButtonLocation.endFloat
floatingActionButtonAnimatorFloatingActionButtonAnimator定义浮动按钮动画行为,默认使用 FloatingActionButtonAnimator.scaling
drawerWidget定义侧边抽屉菜单,通常是一个 Drawer 组件。
endDrawerWidget类似于 drawer,但它位于屏幕的另一侧。
bottomNavigationBarWidget设置页面底部的导航栏,如 BottomNavigationBar
bottomSheetWidget显示在底部的模态弹出层,通常用于临时显示信息或操作选项。
backgroundColorColor设置 Scaffold 的背景颜色。
resizeToAvoidBottomInsetbool控制是否调整 body 的大小以避免被键盘遮挡,默认值为true。
primarybool指示此 Scaffold 是否应该被视为应用程序的主要 Scaffold,影响滚动行为。
extendBodybool如果设置为 true,则 body 将延伸到 bottomNavigationBarpersistentFooter 下方。
extendBodyBehindAppBarbool如果设置为 true,则 body 将延伸到 appBar 下方。
persistentFooterButtonsList定义一组固定在页面底部的按钮。
drawerScrimColorColorDrawer 打开时,屏幕上其他部分的颜色(半透明)。
drawerEdgeDragWidthdouble定义从屏幕边缘拖动打开 Drawer 的宽度。默认情况下,整个屏幕宽度都可以触发拖动手势。
restorationIdString用于状态恢复的标识符,允许 Scaffold 在应用程序重启后恢复其状态。

内部组件使用

1.Flutter组件————AppBar
2.Flutter组件————FloatingActionButton
3.Flutter组件————BottomNavigationBar

代码示例


class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int pageIndex = 0;
  //所有右侧行为按钮
  List<Widget> actionList = const [
    Icon(Icons.social_distance),
    SizedBox(
      width: 30,
    ),
    Icon(Icons.cyclone),
    SizedBox(
      width: 30,
    ),
    Icon(Icons.manage_accounts),
    SizedBox(
      width: 40,
    )
  ];
  List<Widget> pageList = const [
    Text("首页"),
    Text("新增"),
    Text("用户"),
  ];

  void floatBtnFunc() {
    debugPrint("点击了悬浮按钮");
    HapticFeedback.vibrate();
  }

  
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary, //背景颜色
        foregroundColor: const Color.fromARGB(135, 226, 5, 255),
        // leading: const Icon(Icons.accessibility_new_rounded), //左侧按钮
        title: const Text("Flutter 示例"), //标题
        // actions: actionList, //右侧按钮
        elevation: 10, //下方阴影
        shadowColor: const Color.fromARGB(136, 0, 225, 255), //阴影颜色
        centerTitle: true, // 标题是否居中(ios默认居中,Android默认居左)
        surfaceTintColor: const Color.fromARGB(172, 249, 128, 0), //表面颜色
        toolbarHeight: 50, //顶部栏高度
        iconTheme: const IconThemeData(
            size: 20, color: Color.fromARGB(207, 255, 251, 0)), //控制内部元素样式
        primary: true, // 是否显示主要按钮
        titleSpacing: 10, //标题内边距
        bottom: const TabBar(tabs: [
          Tab(icon: Icon(Icons.directions_car)),
          Tab(icon: Icon(Icons.directions_transit)),
          Tab(icon: Icon(Icons.directions_bike)),
        ]), //顶部栏底部按钮
        shape: const RoundedRectangleBorder(
            borderRadius:
                BorderRadius.vertical(bottom: Radius.circular(15)) //顶部栏底部按钮样式
            ),
      ), //顶部栏
      body: Center(
        child: ListView(
          padding: const EdgeInsets.only(top: 15),
          children: [
            Row(
              children: [pageList[pageIndex]],
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: floatBtnFunc, //点击事件
        tooltip: "悬浮按钮", //长按提示信息
        backgroundColor: Colors.blue, //背景颜色
        foregroundColor: Colors.white, // 内部组件颜色
        elevation: 10, //阴影
        shape: ShapeBorder.lerp(
            const CircleBorder(), const CircleBorder(), 0.5), //按钮形状
        mini: false, //是否小尺寸
        hoverColor: Colors.green, //悬浮颜色
        splashColor: Colors.yellow, //点击颜色
        focusColor: Colors.red, //获取焦点颜色
        autofocus: true, //是否自动获取焦点

        clipBehavior: Clip.hardEdge, //裁剪方式
        child: const Icon(Icons.info), // //按钮内部组件
      ), //浮动按钮
      floatingActionButtonLocation:
          FloatingActionButtonLocation.centerDocked, //浮动按钮位置
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home), //图标
            label: "首页",  //标签
            tooltip: "首页",   //长按提示信息
            backgroundColor: Colors.blueAccent, //背景颜色
            activeIcon: Icon(Icons.home_filled), //选中图标
          ),
          BottomNavigationBarItem(icon: Icon(Icons.add), label: "新增"),
          BottomNavigationBarItem(icon: Icon(Icons.verified_user), label: "用户"),
        ], //底部导航栏
        currentIndex: pageIndex, //当前页面索引
        onTap: (index) {
          setState(() {
            pageIndex = index;
          });
        }, //点击事件
        type: BottomNavigationBarType.fixed, //导航栏的类型
        iconSize: 25,  //图标大小
        elevation: 20, //阴影
        selectedFontSize: 12, //选中字体大小
        unselectedFontSize: 12, //未选中字体大小
        selectedItemColor: Colors.blue, //选中颜色
        unselectedItemColor: Colors.black, //未选中颜色
        showUnselectedLabels: true, //是否显示未选中的标签
        selectedLabelStyle: const TextStyle(color: Colors.blue), //选中文本样式
        unselectedLabelStyle: const TextStyle(color: Colors.black), //未选中文本样式
        backgroundColor: const Color.fromARGB(255, 99, 255, 247),
        showSelectedLabels: true, //分别控制是否显示选中和未选中的标签文本,默认都是显示的
      ),
      backgroundColor: Colors.white24, //背景颜色
      persistentFooterButtons: const [Icon(Icons.add_a_photo_outlined),Icon(Icons.add_alarm_rounded)], //底部固定按钮
      drawer: Drawer(child: ListView(children: const [Text("侧边栏")],),),   //左侧边栏(不可以使用appBar的leader)
      endDrawer:  Drawer(child: ListView(children: const [Text("右侧侧边栏")],),)  // 右侧边栏(不可以使用appBar的actions)
    );
  }
}

效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


http://www.kler.cn/a/446510.html

相关文章:

  • iPhone恢复技巧:如何从 iPhone 恢复丢失的照片
  • 密钥管理系统在数据安全解决方案中的重要性
  • TensorFlow_T11 优化器对比实验
  • 用docker快速安装电子白板Excalidraw绘制流程图
  • GaussDB数据库中SQL诊断解析之配置SQL限流
  • Bcrypt在线密码加密生成器
  • 【人工智能】用Python实现图卷积网络(GCN):从理论到节点分类实战
  • 【网络云计算】2024第51周-每日【2024/12/20】小测-理论-周测
  • WeakAuras NES Script(lua)
  • 【微信小程序开发 - 3】:项目组成介绍
  • 易快报-飞书-金蝶云星空集成项目技术分享
  • QoS 流分类
  • 云手机有哪些用途?云手机选择推荐
  • leetcode 面试经典 150 题:长度最小的子数组
  • HCIA/HCIP/HCIE的报名官网
  • Python中bs4库的详细介绍
  • 多个Echart遍历生成 / 词图云
  • 相机内外参知识
  • 【Rust自学】4.4. 引用与借用
  • Golang学习历程【第三篇 基本数据类型类型转换】