Flutter开发 了解Scaffold

Text组件属性基本了解

dart 复制代码
Text(
          "第一个flutter应用",
          style: TextStyle(
            color: Colors.green, //颜色
            fontSize: 25, //字体大小
            decoration: TextDecoration.none, //下划线
          ),
        )

Scaffold

布局结构的脚手架。

属性介绍:

body:主要内容,由多个Widget元素组成。

backgroundColor:设置当前页面的内容的背景色。默认使用的事Theme

dart 复制代码
Scaffold(
        body: Center(child: Text("data")),
        backgroundColor: Colors.white,
      )

appBar:顶部标题栏

appBar属性名 说明
title 标题栏的文本内容
leading 左边图标
iconTheme 图标的颜色
actions 右边图标
centerTitle 居中

示例

dart 复制代码
  Widget build(BuildContext context) {
    
    return MaterialApp(
      title: 'Flutter Demo', //任务管理窗口中显示的应用程序标题
      theme: ThemeData(
        //主题
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text("测试主题色-主页", style: TextStyle(color: Colors.orange)),
          backgroundColor: Colors.red,
          leading: Icon(Icons.menu),
          iconTheme: IconThemeData(color: Colors.green),
          actions: [
            IconButton(icon: Icon(Icons.add), onPressed: () {}),
            IconButton(icon: Icon(Icons.menu), onPressed: () {}),
          ],
          centerTitle: true,
        ),
        body: Center(child: Text("data")),
        backgroundColor: Colors.white,
      ),
    );
  }

bottomNavigationBar:底部导航栏

bottomNavigationBar属性 说明
items 点击项
currentIndex 选中项的下标
onTap 点击事件
dart 复制代码
    return MaterialApp(
      title: 'Flutter Demo', //任务管理窗口中显示的应用程序标题
      theme: ThemeData(
        //主题
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
      ),
      home: Scaffold(
        ......
        bottomNavigationBar: BottomNavigationBar(
          items: [//选项
            BottomNavigationBarItem(icon: Icon(Icons.add), label: "首页"),
            BottomNavigationBarItem(icon: Icon(Icons.access_alarm), label: "搜索"),
            BottomNavigationBarItem(icon: Icon(Icons.account_box), label: "我的"),
          ],
          onTap: (value) {//点击事件

            print(value);
          },
          currentIndex: 1,//当前选择
        ),
      ),
    );

drawer: 抽屉组件

dart 复制代码
 Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo', //任务管理窗口中显示的应用程序标题
      theme: ThemeData(
        //主题
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
      ),
      home: Scaffold(
        .......
        drawer: Drawer(//左边抽屉
          child: ListView(
            children: [
              UserAccountsDrawerHeader(//用户信息部分
                accountName: Text("用户名"),
                accountEmail: Text("xxxx@163.com"),
                currentAccountPicture: CircleAvatar(backgroundImage: AssetImage("images/account.jpg"),),//本体图片的头像
                onDetailsPressed: () {

                  print("点击头像");
                },
              ),
              ListTile(//列表信息
                leading: Icon(Icons.school),
                title: Text("学校"),
                subtitle: Text("毕业院校"),
              ),
              ListTile(
                leading: Icon(Icons.school),
                title: Text("学校2"),
                subtitle: Text("毕业院校"),
              ),
            ],
          ),
        ),
      ),
    );
  }

添加本地account.jpg图片,创建images,存放图片。

在pubspec.yaml配置图片

yaml 复制代码
flutter:
  assets:
    - images/account.jpg

floatingActionButton:悬停在内容上面的按钮

dart 复制代码
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo', //任务管理窗口中显示的应用程序标题
      theme: ThemeData(
        //主题
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
      ),
      home: Scaffold(
 		.......
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: Icon(Icons.print),//图标
          foregroundColor: Colors.red,
          backgroundColor: Colors.green,
          elevation: 4,//默认阴影
          highlightElevation: 20,//点击阴影
          mini: true,//是否使用小图标
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,//按钮位置
      ),
    );
  }
相关推荐
KaMeidebaby35 分钟前
卡梅德生物技术快报|抗体亲和力成熟工业化调控新机制:差异性浆细胞增殖工艺优化思路
java·开发语言·人工智能·算法·机器学习·架构·spark
取个名字太难了~1 小时前
越用越便宜,越用越强大:影像 SDK 的边际成本递减与网络效应实践
android·数码相机·美颜·相机连接·demu
心中有国也有家1 小时前
AtomGit Flutter 鸿蒙客户端: ChangeNotifier 模式
学习·flutter·华为·harmonyos
luj_17681 小时前
心形曲线轨迹控制三大关键技术
c语言·开发语言·c++·经验分享·算法
Mininglamp_27182 小时前
Claude Code 封禁中国开发者之后:本地 AI 编程工具的替代方案实测
开发语言·人工智能·windows·开源软件·ai-native
思麟呀2 小时前
C++17(三)if constexpr+折叠表达式
开发语言·c++
醉城夜风~2 小时前
Java详解经典算法题:接雨水(三种实现方案+原理剖析)
java·开发语言·算法
qydz112 小时前
杰理开发基础知识(3)
开发语言·嵌入式开发·杰理科技
贾斯汀frank2 小时前
C# 15 类型系统改进:Union Types
开发语言·windows·c#
阿里嘎多学长2 小时前
2026-07-10 GitHub 热点项目精选
开发语言·程序员·github·代码托管