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,//按钮位置
      ),
    );
  }
相关推荐
-SOLO-1 小时前
解决VMware 显示比例被重置的问题
android
luj_17682 小时前
星火科技助力边远地区防病攻坚
c语言·开发语言·c++·经验分享·算法
always_TT2 小时前
【Python 日志记录:logging 模块入门】
开发语言·python·php
alexhilton2 小时前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack
xcLeigh2 小时前
Go入门:变量声明的五种方式详解
java·开发语言·golang
zmzb01033 小时前
C++课后习题训练记录Day175
开发语言·c++
脱胎换骨-军哥3 小时前
C++ 代码规范与格式化指南
开发语言·c++·代码规范
枕星而眠4 小时前
C++ STL Map容器完全指南:从有序红黑树到无序哈希表
java·开发语言
爱吃牛肉的大老虎5 小时前
Rust对象之结构体,枚举,特性
开发语言·后端·rust
Lesile5 小时前
Android:Hilt框架入门 · 在ViewUI和ComposeUI下的应用
android·android jetpack