当前位置:网站首页>[shutter -- basic component] use of AppBar
[shutter -- basic component] use of AppBar
2022-07-21 06:59:00 【Kevin-Dev】
One 、 brief introduction
AppBar Displayed in the app At the top of the , Or say Top bar , Corresponding Android Of Toolbar.
- Basic composition
Two 、 attribute
- leading: If you omit leading , but AppBar With Drawer Of Scaffold in , Then a button To open Drawer. without Drawer , The default is a return arrow , You can turn it off by setting automaticallyImplyLeading by false ,
- automaticallyImplyLeading = true: If there is leading This won't work ; without leading , When there is a sidebar , false: The default picture will not be displayed ,true Will be displayed The default image , And respond to the event of opening the sidebar
- title: title
- actions, Dexter icon, In general icon Or words
- flexibleSpace, stay title Something on it , Generally useless
- bottom, It is commonly tabbar , It could be something else
- elevation, Z Shaft height , That is, the shadow The default is 1 The default is height Shadowy
- backgroundColor, The color of the navigation bar The default is ThemeData The color of the
- brightness, The depth of the status bar There are two themes: white and black
- iconTheme,
- centerTitle, title Is it in the middle?
- titleSpacing flexibleSpace and title Distance of Coincident by default
- NavigationToolbar.kMiddleSpacing,
- toolbarOpacity = 1.0 Transparency of the navigation bar
- bottomOpacity = 1.0 bottom Transparency
3、 ... and 、 example
1. design sketch
2. Complete code
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({
Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
body: Center(
child: AppBarStatefulWidget(),
)
)
);
}
}
class AppBarStatefulWidget extends StatefulWidget {
const AppBarStatefulWidget({
Key? key}) : super(key: key);
@override
_AppBarStatefulWidget createState() => _AppBarStatefulWidget();
}
class _AppBarStatefulWidget extends State with SingleTickerProviderStateMixin {
final List<Tab> _tabs = <Tab>[
new Tab(text: ' Focus on '),
new Tab(text: ' Push and press '),
new Tab(text: ' video '),
new Tab(text: ' game '),
new Tab(text: ' music '),
new Tab(text: ' sports '),
new Tab(text: ' life '),
new Tab(text: ' picture '),
];
var _tabController;
@override
void initState() {
_tabController = TabController(vsync: this, length: _tabs.length);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: _drawer(context),
body: TabBarView(
controller: _tabController,
children: _tabs.map((Tab tab) {
return new Center(child: Text(tab.text.toString()));
}).toList(),
),
appBar: AppBar(
leading: Icon(Icons.home),
// If this item is not set , Secondary page The default is the return arrow , Pages with sidebars have icons by default ( Used to open the sidebar )
automaticallyImplyLeading: true,
// If there is leading This won't work ; without leading , When there is a sidebar , false: The default picture will not be displayed ,true Will be displayed The default image , And respond to the event of opening the sidebar
title: Text(" title "),
centerTitle: true,
// Whether the title is centered
actions: <Widget>[
IconButton(
icon: Icon(Icons.save),
tooltip: 'Add Alarm',
onPressed: () {
// Don't write onPressed Default , This picture cannot be clicked And there will be non clickable styles ( and I wrote this in different styles )
// If there is onPressed But the value is null It will also be a non clickable style
}),
IconButton(
icon: Icon(Icons.add_alarm),
tooltip: 'Add Alarm',
onPressed: () {
// do nothing
})
],
bottom: TabBar(
isScrollable: true,
labelColor: Colors.redAccent, // Selected Widget Color
indicatorColor:Colors.redAccent, // Selected indicator color
labelStyle: new TextStyle(fontSize: 15.0),// You have to set , Set up color useless , because labelColor It's set up
unselectedLabelColor: Colors.white,
unselectedLabelStyle: new TextStyle(
fontSize: 15.0), // Set up color useless , because unselectedLabelColor It's set up
controller: _tabController,
// tabbar You have to set controller Otherwise, the report will be wrong
indicatorSize: TabBarIndicatorSize.label,
// Yes tab and label Two kinds of
tabs: _tabs,
),
),
);
}
}
Drawer _drawer(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.lightBlueAccent,
),
child: Center(
child: SizedBox(
width: 60.0,
height: 60.0,
child: CircleAvatar(
child: Text(' Head portrait '),
),
),
),
),
ListTile(
title: Text('Item 1'),
leading: new CircleAvatar(
child: new Icon(Icons.school),
),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Item 2'),
leading: new CircleAvatar(
child: new Text('B2'),
),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Item 3'),
leading: new CircleAvatar(
child: new Icon(Icons.list),
),
onTap: () {
Navigator.pop(context);
},
),
],
),
);
}
边栏推荐
- 华为机试:学生方阵
- 认清影响因子引发的是是非非,善待逆境中顽强崛起的国产期刊
- Anacona环境太多??jupyter中如何查看自己当前在哪个环境
- Few-shot Video-to-Video(NeurIPS 2019)视频生成论文解读
- 使用 LVS+Keepalived 实现 MySQL 双主复制负载均衡高可用
- MoCo V2:MoCo系列再升级
- Babang MS Marco! Transformer based hybrid list aware sorting model
- “如今,99.9% 以上的代码都是垃圾!”
- Analyzing the internal mechanism and breakthrough path of "Web3 paradox"
- Pyspark:DataFrame的转化操作及行动操作
猜你喜欢
随机推荐
【Go开源宝藏】基于 Golang 语法的性能调优技巧(数组的遍历)
6-11漏洞利用-利用搭建环境发送邮件
数仓之数据质量建设
【Typora】This beta version of Typora is expired, please download and install a newer version.
基于NLua实现使用lua脚本中多线程执行方法
查询Mysql服务器的线程信息(详解)
PostgreSQL中按时间月份自动创建分区表
[go open source treasure] performance tuning skills based on golang syntax (string splicing)
数据整合 | 国内外数据整合有什么工具?
PostgreSQL查看表、表索引、视图、表结构以及参数设置
为 KubeSphere 集群启用免费的泛域名 SSL 证书并实现证书自动更新和分发
创建线程:pthread_create
Wallys/3×3/2×2 MIMO/ 802.11ac/ Mini PCIe /2,4GHz / 5GHz QCA 9880
uni-app开发之HBuilderX连接夜神模拟器
DAO的精简化治理的委托机制
ACTF出题(dropper+master_of_dns)
加密市场中的14个心智模型
【Flutter -- 基础组件】AppBar 的使用
golang--操作日期
(note) feature fusion method in neural network (add/connect)