当前位置:网站首页>[shutter] pull the navigation bar sideways (drawer component | pageview component)
[shutter] pull the navigation bar sideways (drawer component | pageview component)
2022-07-03 02:02:00 【Programmer community】
List of articles
- One 、Drawer Components
- Two 、PageView Components
- 3、 ... and 、 Complete code example
- Four 、 Related resources
One 、Drawer Components
Scaffold In the component drawer Parameters , Is to set the side pull navigation bar menu , Assign it a Drawer Components ;
Drawer Components are side pull menus , Of this component child Set up a ListView Components , Set in list DrawerHeader , ListTile And so on ;
class Drawer extends StatelessWidget {
const Drawer({
Key? key, this.elevation = 16.0, this.child, this.semanticLabel, }) : assert(elevation != null && elevation >= 0.0), super(key: key);}
Side pull menu example :
drawer: Drawer( child: ListView( children: datas.map((TabData data) {
/// Single button entry return ListTile( title: Text(data.title), /// Click event onTap: () {
/// Jump to the corresponding navigation page _pageController.jumpToPage(data.index); _currentIndex = data.index; /// Close side pull menu Navigator.pop(context); }, ); }).toList(), ),),
Two 、PageView Components
PageView The two most important fields of the component :
- PageController? controller
- List<Widget> children
PageController Used to control the PageView The jump , PageController The main function is to call void jumpToPage(int page) Method , Page Jump ;
jumpToPage The page jumps to... In the menu bar at the bottom onTap Click in the event to call , After updating the current page , Need to call setState Method update interface ;
PageView Constructors :
PageView({
Key? key, this.scrollDirection = Axis.horizontal, // Set the scroll direction vertical / level this.reverse = false, // Reverse scrolling PageController? controller, // Scroll control class this.physics, // Scroll logic , Don't roll / rolling / Scroll to whether the edge bounces this.pageSnapping = true, // If you set false , You cannot capture page gestures this.onPageChanged, // Call back this function when switching pages List<Widget> children = const <Widget>[], this.dragStartBehavior = DragStartBehavior.start, this.allowImplicitScrolling = false, this.restorationId, this.clipBehavior = Clip.hardEdge, }) : assert(allowImplicitScrolling != null), assert(clipBehavior != null), controller = controller ?? _defaultPageController, childrenDelegate = SliverChildListDelegate(children), super(key: key);
PageView Code example :
/// Sliding components , The core elements of the interface PageView( /// The controller that controls page flipping controller: _pageController, /// Widget Component array , Set up multiple Widget Components children: datas.map((TabData data) {
return Padding( /// padding 20 padding: const EdgeInsets.all(20.0), /// PageView Components shown individually in child: TabContent(data: data), ); }).toList(), physics: NeverScrollableScrollPhysics(),),
3、 ... and 、 Complete code example
Complete code example :
import 'package:flutter/material.dart';/// Side pull navigation bar example void main() {
runApp( DrawerWidget() );}class DrawerWidget extends StatefulWidget {
@override _DrawerWidgetState createState() => _DrawerWidgetState();}class _DrawerWidgetState extends State<DrawerWidget> with SingleTickerProviderStateMixin {
/// The current index value int _currentIndex = 0; /// PageView controller , Used to control the PageView var _pageController = PageController( /// Initial index value initialPage: 0, ); @override void dispose() {
super.dispose(); /// The destruction PageView controller _pageController.dispose(); } @override Widget build(BuildContext context) {
/// The root component return MaterialApp( home: Scaffold( /// Sliding components , The core elements of the interface body: PageView( /// The controller that controls page flipping controller: _pageController, /// Widget Component array , Set up multiple Widget Components children: datas.map((TabData data) {
return Padding( /// padding 20 padding: const EdgeInsets.all(20.0), /// PageView Components shown individually in child: TabContent(data: data), ); }).toList(), physics: NeverScrollableScrollPhysics(), ), drawer: Drawer( child: ListView( children: datas.map((TabData data) {
/// Single button entry return ListTile( title: Text(data.title), /// Click event onTap: () {
/// Jump to the corresponding navigation page _pageController.jumpToPage(data.index); _currentIndex = data.index; /// Close side pull menu Navigator.pop(context); }, ); }).toList(), ), ), ), ); }}/// Encapsulate the icon and text data of the navigation bar class TabData {
/// Navigation data constructor const TabData({
this.index, this.title, this.icon}); /// Navigation title final String title; /// Navigation icons final IconData icon; /// Indexes final int index;}/// Navigation bar data set const List<TabData> datas = const <TabData>[ const TabData(index: 0, title: '3D', icon: Icons.threed_rotation), const TabData(index: 1, title: ' The printer ', icon: Icons.print), const TabData(index: 2, title: ' Animation ', icon: Icons.animation), const TabData(index: 3, title: ' Transformation ', icon: Icons.transform), const TabData(index: 4, title: ' Height ', icon: Icons.height), const TabData(index: 5, title: ' describe ', icon: Icons.description), const TabData(index: 6, title: ' forward ', icon: Icons.forward), const TabData(index: 7, title: ' The camera ', icon: Icons.camera), const TabData(index: 8, title: ' Set up ', icon: Icons.settings), const TabData(index: 9, title: ' Academic degree ', icon: Icons.school),];/// adopt TabBar The navigation bar switches the main contents of the display /// Used in TabBarView Components shown in class TabContent extends StatelessWidget {
const TabContent({
Key key, this.data}) : super(key: key); /// Generate components based on this data entry final TabData data; @override Widget build(BuildContext context) {
TextStyle textStyle = TextStyle(color: Colors.yellow, fontSize: 50); return Card( /// Set up 20 Pixel margin margin: EdgeInsets.all(20), /// Set shadow elevation: 10, /// The card color is black color: Colors.black, /// The elements in the card are displayed in the center child: Center( /// Linear layout in vertical direction child: Column( /// On the spindle ( vertical direction ) The size occupied mainAxisSize: MainAxisSize.min, /// centered crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ /// Set icon Icon(data.icon, size: 128.0, color: Colors.green), /// Set text Text(data.title, style: TextStyle(color: Colors.yellow, fontSize: 50)), ], ), ), ); }}
Operation effect display :
Four 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- Flutter Plug in download address : https://pub.dev/packages
- Flutter Developing documents : https://flutter.cn/docs ( Strongly recommend )
- official GitHub Address : https://github.com/flutter
- Flutter The Chinese community : https://flutter.cn/
- Flutter Practical tutorial : https://flutter.cn/docs/cookbook
- Flutter CodeLab : https://codelabs.flutter-io.cn/
- Dart Chinese document : https://dart.cn/
- Dart Developer website : https://api.dart.dev/
- Flutter Chinese net : https://flutterchina.club/ , http://flutter.axuer.com/docs/
- Flutter Related issues : https://flutterchina.club/faq/ ( It is recommended to watch it at the introductory stage )
- GitHub Upper Flutter Open source examples : https://download.csdn.net/download/han1202012/15989510
- Flutter Practical e-books : https://book.flutterchina.club/chapter1/
Important topics :
- Flutter Animation reference documentation : https://flutterchina.club/animations/
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_frame ( Keep updating with the progress of the blog , There may not be the source code of this blog )
Blog source snapshot : https://download.csdn.net/download/han1202012/16277725 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- 浏览器是如何对页面进行渲染的呢?
- 微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
- [Yu Yue education] Jiujiang University material analysis and testing technology reference
- Comment communiquer avec Huawei Cloud IOT via le Protocole mqtt
- Huakaiyun (Zhiyin) | virtual host: what is a virtual host
- Certaines fonctionnalités du développement d'applets
- Depth (penetration) selector:: v-deep/deep/ and > > >
- stm32F407-------IIC通讯协议
- Trial setup and use of idea GoLand development tool
- Swift development learning
猜你喜欢
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
PS去除水印详解
Deep learning notes (constantly updating...)
小程序开发的部分功能
MySQL learning 03
技术大佬准备就绪,话题C位由你决定
[error record] navigator operation requested with a context that does not include a naviga
[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)
ByteDance data Lake integration practice based on Hudi
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
随机推荐
Network security - Trojan horse
Comment le chef de file gère - t - il l'équipe en cas d'épidémie? Contributions communautaires
Network security - the simplest virus
Swift开发学习
How do browsers render pages?
[shutter] top navigation bar implementation (scaffold | defaulttabcontroller | tabbar | tab | tabbarview)
Redis:Redis的简单使用
How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?
es6 filter() 数组过滤方法总结
Learn BeanShell before you dare to say you know JMeter
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
Cloud native topic sorting (to be updated)
詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
深度(穿透)选择器 ::v-deep/deep/及 > > >
The technology boss is ready, and the topic of position C is up to you
【Camera专题】OTP数据如何保存在自定义节点中
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
ByteDance data Lake integration practice based on Hudi
stm32F407-------DMA
Stm32f407 ------- IIC communication protocol