首页 > 其他分享 >Flutter Scaffold

Flutter Scaffold

时间:2023-03-09 15:32:59浏览次数:29  
标签:Icons Text Scaffold button child Flutter Icon

Read about Flutter Scaffold, its uses, properties and the importance of Scaffold widget in Flutter Apps.
The Scaffold widget is the base of the screen for a single page. It is used to implement the basic functional layout structure of an app. You can easily implement functional widgets like AppBar, FloatingActionButton, ButtonNavigationBar, Drawer, and many more widgets on the app using the Scaffold widget.

You can easily build an app using Scaffold and implement basic components with very less code, it can allow you to put all the material components to give look and feel to your app.

Constructors of Scaffold() widget:

Scaffold({
Key key,
PreferredSizeWidget appBar,
Widget body,
Widget floatingActionButton,
FloatingActionButtonLocation floatingActionButtonLocation,
FloatingActionButtonAnimator floatingActionButtonAnimator,
List persistentFooterButtons,
Widget drawer,
Widget endDrawer,
Widget bottomNavigationBar,
Widget bottomSheet,
Color backgroundColor,
bool resizeToAvoidBottomPadding,
bool resizeToAvoidBottomInset,
bool primary: true,
DragStartBehavior drawerDragStartBehavior:
DragStartBehavior.start,
bool extendBody: false,
bool extendBodyBehindAppBar: false,
Color drawerScrimColor,
double drawerEdgeDragWidth,
bool drawerEnableOpenDragGesture: true,
bool endDrawerEnableOpenDragGesture: true
})

The properties of the constructors are explained below:

1. appBar - PreferredSizeWidget

It is a horizontal bar displayed at the top of the screen. The app bar is one of the main components in your app, without it, your app may seem incomplete. The appBar widget has its own properties like elevation, title, actions, etc.

Scaffold(
appBar: AppBar(
title:Text("AppBar"), //title aof appbar
backgroundColor: Colors.redAccent, //background color of appbar
),
)

Flutter Scaffold_Text

2. backgroundColor - Color

This property on Scaffold is used to change the background color of the Scaffold screen.

Scaffold(
backgroundColor: Colors.blue, //set background color of scaffold to blue
)

Flutter Scaffold_ide_02

3. body - Widget

This is the main content property on Scaffold. You have to pass the widget and it will be displayed on the screen.

Scaffold(
body: Center( //content body on scaffold
child: Text("Scaffold Widget")
)
)

4. floatingActionButton - Widget

It is a floating button that is used for quick action.

Scaffold(
floatingActionButton:FloatingActionButton( //Floating action button on Scaffold
onPressed: (){
//code to execute on button press
},
child: Icon(Icons.send), //icon inside button
)
)

Flutter Scaffold_ide_03

class HomePage extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("AppBar"), // title of appbar
backgroundColor: Colors.redAccent, // background color of appbar
),
backgroundColor: Colors.yellow,
floatingActionButton: FloatingActionButton(//Floating action button on Scaffold
//To pass data to the back page, you need to put Navigator.push() method
//on "Click on Me" or any back buttons like below:
//传递参数到上一页时需要这样设置
onPressed:() async {
var backdata = await Navigator.push(context, MaterialPageRoute(builder:(context){
return SecondScreen(word: "Hello", val: 4);
}));
print(backdata);
},
child: Icon(Icons.send), // icon inside button
),
body: Center(
child: TextButton(
onPressed: () { print("scaffold widget text button clicked"); },
child: Text("Scaffold Widget"),

)
)
);
}
}

效果如下

Flutter Scaffold_sed_04

5. floatingActionButtonLocation - FloatingActionButtonLocation

This property is used to set location of Floating action button on the screen.

Flutter Scaffold_Text_05

6. drawer - Widget

It is a navigation panel where you can put different menu items to navigate. When you add a drawer to Scaffold, the menu icon will appear on appBar.

Scaffold(
drawer: Drawer( //drawer navigation on scaffold
child: SafeArea(
child:Column( //column widget
children: [
ListTile(
leading: Icon(Icons.home),
title: Text("Home Page"),
subtitle: Text("Subtitle menu 1"),
),
ListTile(
leading: Icon(Icons.search),
title: Text("Search Page"),
subtitle: Text("Subtitle menu 1"),
),

//put more menu items here
],
),
),
),
)

很形象的关键字——抽屉。

Flutter Scaffold_ide_06

7. bottomNavigationBar - Widget

This component is similar to appBar which is displayed at bottom of the screen. You can pass BottomNavigationBar() widget or BottomAppBar() widget on this property.

Scaffold(
bottomNavigationBar: BottomNavigationBar( //bottom navigation bar on scaffold
items: [ //items inside navigation bar
BottomNavigationBarItem(
icon: Icon(Icons.add),
label: "Button 1",
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: "Button 2",
),
BottomNavigationBarItem(
icon: Icon(Icons.camera),
label: "Button 3",
),

//put more items here
],
),
)

这个就是底部的appBar

Flutter Scaffold_ide_07


如果用另一种

bottomNavigationBar: BottomAppBar(
//bottom navigation bar on scaffold
child: Text(
"hello buttom",textAlign: TextAlign.center,
),
)

效果如下

Flutter Scaffold_sed_08

You can also set notched shape on bottomNavigationBar with BottomAppBar().

class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("AppBar"), // title of appbar
backgroundColor: Colors.redAccent, // background color of appbar
),
backgroundColor: Colors.white,
floatingActionButton: FloatingActionButton(
//Floating action button on Scaffold
//To pass data to the back page, you need to put Navigator.push() method
//on "Click on Me" or any back buttons like below:
//传递参数到上一页时需要这样设置
onPressed: () async {
var backdata = await Navigator.push(context,
MaterialPageRoute(builder: (context) {
return SecondScreen(word: "Hello", val: 4);
}));
print(backdata);
},
child: Icon(Icons.send), // icon inside button
),
//This property is used to set location of Floating action button on the screen.
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
drawer: Drawer(
//drawer navigation on scaffold
child: SafeArea(
child: Column(
//column widget
children: [
ListTile(
leading: Icon(Icons.home),
title: Text("Home Page"),
subtitle: Text("Subtitle menu 1"),
onTap: () {
//fixme not work
(context) => HomePage();
},
),
ListTile(
leading: Icon(Icons.search),
title: Text("Search Page"),
subtitle: Text("Subtitle menu 1"),
onTap: () {
//fixme not work
(context) => SecondScreen(word: "searchWord", val: 5);
}),

//put more menu items here
],
),
),
),
bottomNavigationBar: BottomAppBar(//bottom navigation bar on scaffold
shape: CircularNotchedRectangle(), //shape of notch
notchMargin: 10, //notche margin between floating button and bottom appbar
//bottom navigation bar on scaffold
child: Row( //children inside bottom appbar
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children:[
IconButton(onPressed: (){}, icon: Icon(Icons.menu)),
IconButton(onPressed: (){}, icon: Icon(Icons.search)),
]
),

color: Colors.blue,
// items: [ //items inside navigation bar
// BottomNavigationBarItem(
// icon: Icon(Icons.add),
// label: "Button 1",
// ),
// BottomNavigationBarItem(
// icon: Icon(Icons.search),
// label: "Button 2",
// ),
// BottomNavigationBarItem(
// icon: Icon(Icons.camera),
// label: "Button 3",
// ),
//
// //put more items here
// ],
),
body: Center(
child: TextButton(
onPressed: () {
print("scaffold widget text button clicked");
},
child: Text("Scaffold Widget"),
)));
}
}

效果perfect~

Flutter Scaffold_Text_09

作者:​​ukyo--3点买菜​​


标签:Icons,Text,Scaffold,button,child,Flutter,Icon
From: https://blog.51cto.com/u_11956468/6110598

相关文章

  • Flutter 笔记
    FlutterFlutter核心原理底层绘制采用OpenGL,调用原生绘图接口,实现高性能什么是UI框架?由于操作系统直接操作API来绘制图片十分繁琐,将操作系统原生API封装在一个编程框架......
  • 基于声网 Flutter SDK 实现多人视频通话
    前言本文是由声网社区的开发者“小猿”撰写的Flutter基础教程系列中的第一篇。本文除了讲述实现多人视频通话的过程,还有一些Flutter开发方面的知识点。该系列将基于声网......
  • 跨端开发新选择:Flutter与FinClip,让应用开发更高效、更实用
    为什么说flutter是一个强大的跨端框架?Flutter是一个基于Dart编程语言的移动应用程序开发框架,由Google开发。它的强大之处在于它可以快速构建高性能、美观、灵活的跨平台......
  • flutter系列之:在flutter中自定义themes
    目录简介MaterialApp中的themes自定义themes的使用总结简介一般情况下我们在flutter中搭建的app基本上都是用的是MaterialApp这种设计模式,MaterialApp中为我们接下来使用......
  • Flutter Developer Roadmap All In One
    FlutterDeveloperRoadmapAllInOneFlutter&DartLearningtobecomeamodernFlutterdeveloperin2023https://roadmap.sh/flutter(......
  • flutter 上下文菜单的使用
    1.什么是上下文菜单上下文菜单主要是指一种通过上下文贯穿多级组件的特定的弹窗菜单,如pc端的鼠标右击菜单移动端的长按菜单或内容选择菜单2.在flutter中使用上下文菜单......
  • Flutter 下载篇 - 叁 | 网络库切换实践与思考
    前言本文是关于使用flutter_download_manager下载功能的实践和探索。我们将基于flutter_download_manager的功能扩展,改造成自己想要的样子。在阅读本文之前,建议先了解前两......
  • Flutter 下载篇 - 贰 | 当下载器遇上切换网络库
    需求背景继上篇《Flutter下载篇-壹|flutter_download_manager源码解析》中详细介绍了flutter_download_manager用法和原理。在优缺点中提到,该库纯Dart实现,支持......
  • 成品直播源码,Flutter 夜间模式 全局字体
    成品直播源码,Flutter夜间模式全局字体 import'package:flutter/material.dart';import'package:flutter_widget/router/applicationRouterGradual.dart';import'pa......
  • 剖析flutter_download_manager学习如何做下载管理,暂停和取消
    前言内容类应用中图片或文件下载,一般应用中应用更新和升级,这些都是经典的下载场景。下载是项目中基础且重要的模块。从代码逻辑复用性和人力成本考虑,一直想实现一个纯Dar......