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

这篇具有很好参考价值的文章主要介绍了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'),
            ],
          ),
        ),
      )

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

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

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

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

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

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

drawer: 左侧滑动组件

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

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

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;
          });
        },
      )

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

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

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

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

整体代码块

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文章来源地址https://www.toymoban.com/news/detail-738181.html

到了这里,关于Flutter——最详细(Scaffold)使用教程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • Flutter——最详细(TextField)使用教程

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

    文本输入框,拥有复杂的属性。可指定控制器、文字样式、装饰线、行数限制、游标样式等。监听输入框变动事件。 搜索框,输入账号密码等 属性 作用 controller 输入框监听器 decoration 输入框装饰属性 textAlign 内容对齐方式 textAlignVertical 文本垂直对齐 textDirection 文字方向 ma

    2024年02月13日
    浏览(11)
  • Flutter——最详细(Map)使用教程

    键值对的集合,您可以使用其关联的键从中检索值。 普通的 HashMap 是无序的(不保证顺序), LinkedHashMap 按键插入顺序迭代,而像 SplayTreeMap 这样的排序映射按排序顺序迭代键。 1,添加元素 addEntries() 2,更新组元素 update() 3,更新所有元素的值 updateAll() 4,删除指定的元素

    2024年02月06日
    浏览(11)
  • flutter getx 简单使用教程

    所以Flutter使用GetX真的很不错 为什么说什么GetX好用呢? 1、依赖注入 GetX是通过依赖注入的方式,存储相应的XxxGetxController;已经脱离了InheritedWidget那一套玩法,自己手动去管理这些实例,使用场景被大大拓展 2、跨页面交互 这绝对是GetX的一个优点!对于复杂的生产环境,跨

    2024年02月08日
    浏览(9)
  • Flutter Image库详细介绍与使用指南

    1. 介绍 在Flutter中,图片是应用程序中不可或缺的一部分,而 image 库是一个强大而灵活的图片加载和处理库。通过使用 image^ 4.1.4 ,您可以轻松地实现图片的加载、缓存、调整大小和裁剪等功能,同时还支持各种图片格式。 2. 安装 在 pubspec.yaml 文件中添加以下依赖: 然后运行

    2024年01月25日
    浏览(15)
  • 教程:Flutter 和 Rust混合编程,使用flutter_rust_bridge自动生成ffi代码

    教程:Flutter 和 Rust混合编程,使用flutter_rust_bridge自动生成ffi代码

    实践环境:Arch Linux flutter_rust_bridge官方文档 Flutter环境配置教程 | Rust环境配置教程 记录使用 flutter_rust_bridge 遇到的一些坑。 假设我们已经配置了Fluuter与Rust环境 现在直接使用flutter_rust_bridge模板创建自己的项目 运行: 现在我们先让项目跑起来: 编辑 native/src/api.rs 安装代码生

    2024年02月09日
    浏览(13)
  • Flutter 使用pageview无缝隙自动轮播教程

    导入要使用的轮播图片 声明变量 然后在initState里面初始化一下 在dispose里面去掉 最后在你需要的地方加入下面代码就行了

    2024年02月07日
    浏览(7)
  • 2023年Flutter教程_Flutter+Getx仿小米商城项目实战视频教程-V3版

    Flutter 是谷歌公司开发的一款开源、免费的UI框架,可以让我们快速的在Android和iOS上构建高质量App。它最大的特点就是跨平台、以及高性能。  目前 Flutter 已经支持 iOS、Android、Web、Windows、macOS、Linux 的跨平台开发 。   GetX  是 Flutter 上的一个轻量且强大的解决方案,我们可以

    2024年02月08日
    浏览(9)
  • Flutter 安装教程 + 运行教程

    Flutter 安装教程 + 运行教程

    https://flutter.cn/docs/get-started/install/windows 解压完后根据自己的位置放置,如(D:flutter) 注意 请勿将 Flutter 有特殊字符或空格的路径下。 请勿将 Flutter 安装在需要高权限的文件夹内,例如 C:Program Files。 国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时

    2024年02月10日
    浏览(8)
  • Flutter状态管理:RxDart,详细介绍

    RxDart是一个基于Dart语言的响应式编程库,它提供了一套用于处理异步事件序列的工具。在Flutter应用中,RxDart可以很好地用于管理应用状态。 响应式编程是一种编程范式,它将应用程序的逻辑分解为响应事件的流。当应用程序中发生事件时,可以通过这些流来响应这些事件。

    2024年02月10日
    浏览(10)
  • 无涯教程-Flutter - 简介

    Flutter是一个由谷歌开发的开源移动应用软件开发工具包,用于为Android、iOS、 Windows、Mac、Linux、Google Fuchsia开发应用。    通常,创建移动应用程序是一个非常复杂和具有挑战性的任务。有许多框架可用,它提供了开发移动应用程序的出色函数。对于开发移动应用程序,Andr

    2024年02月10日
    浏览(8)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包