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,//按钮位置
      ),
    );
  }
相关推荐
Mr.Jessy2 分钟前
Web APIs 学习第四天:DOM事件进阶
开发语言·前端·javascript·学习·ecmascript
旧时光_4 分钟前
第2章:第一个Flutter应用 —— 2.4 路由管理
flutter
studyForMokey9 分钟前
【Kotlin内联函数】
android·开发语言·kotlin
小虚竹14 分钟前
Rust日志系统完全指南:从log门面库到env_logger实战
开发语言·后端·rust
星释14 分钟前
Rust 练习册 8:链表实现与所有权管理
开发语言·链表·rust
今日说"法"16 分钟前
Rust 日志级别与结构化日志:从调试到生产的日志策略
开发语言·后端·rust
-大头.17 分钟前
Rust并发编程实战技巧
开发语言·后端·rust
Yurko1331 分钟前
【C语言】选择结构和循环结构的进阶
c语言·开发语言·学习
小白学大数据40 分钟前
构建1688店铺商品数据集:Python爬虫数据采集与格式化实践
开发语言·爬虫·python
大邳草民1 小时前
深入理解 Python 的“左闭右开”设计哲学
开发语言·笔记·python