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

Flutter——最详细(Scaffold)使用教程

Scaffold简介

相当于界面的主体(类似于安卓最外层PhoneWindow),组件的展示都必须依附于它。

使用场景:

每一个界面都是脚手架,通过它来进行架构实现,优美的布局效果。

属性作用
appBar顶部的标题栏
body显示整体布局
floatingActionButton右下角按钮
floatingActionButtonLocation按钮的位置
floatingActionButtonAnimator按钮动画
drawer左侧滑动组件
onDrawerChanged滑动事件监听
endDrawer右侧滑动组件
onEndDrawerChanged编辑完成
bottomNavigationBar底部菜单组件
backgroundColor背景色
persistentFooterButtons显示在基架底部的一组按钮
resizeToAvoidBottomInset如果脚手架上方显示屏幕键盘,则可以调整机身大小以避免与键盘重叠,从而防止机身内部的小部件被键盘遮挡。

endDrawer 属性效果

      endDrawer: Container(color: Colors.white,width: 200,child: Center(child: Column(children: [Text('测试endDrawer'),Text('测试endDrawer'),],),),)

在这里插入图片描述

floatingActionButton 属性
floatingActionButtonLocation: 属性 startFloat、centerFloat、endFloat、 等几个属性

floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: FloatingActionButton(onPressed: () {},tooltip: 'Increment',child: const Icon(Icons.add),)

FloatingActionButtonLocation.startFloat
在这里插入图片描述
在这里插入图片描述

body: 属性代表布局的身体,相当于红色这一区域;
backgroundColor: 整体红色区域部分的背景颜色;

在这里插入图片描述

drawer: 左侧滑动组件

  drawer: Container(color: Colors.white,width: 200,child: Center(child: Column(children: [Text('测试drawer'),Text('测试drawer'),],),),),

在这里插入图片描述

bottomNavigationBar: 底部菜单栏按钮

   bottomNavigationBar: BottomNavigationBar(items: const <BottomNavigationBarItem>[BottomNavigationBarItem(icon: Icon(Icons.home),label: '首页',),BottomNavigationBarItem(icon: Icon(Icons.search),label: '搜索',),BottomNavigationBarItem(icon: Icon(Icons.settings),label: '设置',),],currentIndex: _selectedIndex,selectedItemColor: Colors.blue,onTap: (index) {setState(() {_selectedIndex = index;});},)

在这里插入图片描述

persistentFooterButtons: 显示在基架底部的一组按钮。

      persistentFooterAlignment:  AlignmentDirectional.bottomEnd,persistentFooterButtons: [TextButton(onPressed: () {// 按钮1的点击事件处理逻辑},child: Text('按钮1'),),TextButton(onPressed: () {// 按钮2的点击事件处理逻辑},child: Text('按钮2'),),],

在这里插入图片描述

整体代码块

import 'package:flutter/material.dart';class ScaffoldPage extends StatefulWidget {const ScaffoldPage({Key? key}) : super(key: key);State<ScaffoldPage> createState() => _ScaffoldPageState();
}class _ScaffoldPageState extends State<ScaffoldPage> {int _selectedIndex = 0;List<Widget> _widgetOptions = [// 每个选项对应的页面或小部件// 可以根据需要替换为自己的页面或小部件Text('首页'),Text('搜索'),Text('设置'),];Widget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text('测试脚手架'),),backgroundColor: Colors.blueAccent,body: Center(child: _widgetOptions.elementAt(_selectedIndex),),endDrawer: Container(color: Colors.white,width: 200,child: Center(child: Column(children: [Text('测试endDrawer'),Text('测试endDrawer'),],),),),drawer: Container(color: Colors.white,width: 200,child: Center(child: Column(children: [Text('测试drawer'),Text('测试drawer'),],),),),bottomNavigationBar: BottomNavigationBar(items: const <BottomNavigationBarItem>[BottomNavigationBarItem(icon: Icon(Icons.home),label: '首页',),BottomNavigationBarItem(icon: Icon(Icons.search),label: '搜索',),BottomNavigationBarItem(icon: Icon(Icons.settings),label: '设置',),],currentIndex: _selectedIndex,selectedItemColor: Colors.blue,onTap: (index) {setState(() {_selectedIndex = index;});},),floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,floatingActionButton: FloatingActionButton(onPressed: () {},tooltip: 'Increment',child: const Icon(Icons.add),),persistentFooterAlignment:  AlignmentDirectional.bottomEnd,persistentFooterButtons: [TextButton(onPressed: () {// 按钮1的点击事件处理逻辑},child: Text('按钮1'),),TextButton(onPressed: () {// 按钮2的点击事件处理逻辑},child: Text('按钮2'),),],);}
}

项目地址

https://github.com/z244370114/flutter_demo

http://www.lryc.cn/news/208095.html

相关文章:

  • C语言编写图形化界面-创建按钮-为其指定样式
  • C++并发与多线程(7) | 创建多个线程时数据共享的问题
  • 进程间通信(匿名管道、命名管道、消息队列、共享内存、信号量、信号、Socket)
  • 浅谈中国汽车充电桩行业市场状况及充电桩选型的介绍
  • Postgresql在jdbc处理bit字段的解决方案
  • ESMapping字段
  • 基于LDA的隐式标签协同过滤推荐算法_文勇军
  • 在线设计数据库表用Itbuilder,极简易用真香!!!
  • onclick事件的用法
  • 二叉排序树
  • 探秘Spring的设计精髓,深入解析架构原理
  • Python Wordcloud报错:Only supported for TrueType fonts,多种解决方案
  • 为虚拟网络提供敏捷负载均衡:Everoute LB 特性解读
  • Jmeter 接口测试,参数值为列表,如何参数化?
  • DeepinV20实现使用CapsLock键切换输入法
  • 基于springboot实现校友社交平台管理系统项目【项目源码+论文说明】计算机毕业设计
  • WordPress主题模板 大前端D8 5.1版本完整开源版源码简洁大气多功能配置
  • 如何在Postman中使用静态HTTP
  • vscode 提升Vue开发效率的必备插件与工具
  • mysql/java/springboot/javaweb请假系统,分为学生/辅导员/超级管理员
  • Android11系统桌面隐藏指定APP图标
  • WEB使用百度地图展示某地地址
  • 22年上半年下午题
  • 大文件分片上传-续传-秒传(详解)
  • CE-LVD证书跟CE-EMC证书有什么区别?
  • 使用Mapster实现双向映射,解放搬砖体力活
  • 一种基于屏幕分辨率的RTSP主子码流切换的多路视频监控的播放方案
  • SpringBoot日志+SpringMVC+UUID重命名文件+Idea热部署
  • 向日葵远程控制中的键盘异常问题
  • 【iOS免越狱】利用IOS自动化web-driver-agent_appium-实现自动点击+滑动屏幕