当前位置:网站首页>[shutter] statefulwidget component (pageview component)
[shutter] statefulwidget component (pageview component)
2022-07-02 21:24:00 【Programmer community】
List of articles
- One 、PageView Components
- Two 、PageView Component complete code example
- 3、 ... and 、 Related resources
One 、PageView Components
PageView Component constructor : The optional parameter in the constructor is PageView All settable options of the component ;
class PageView extends StatefulWidget {
PageView({
Key key, this.scrollDirection = Axis.horizontal, this.reverse = false, PageController controller, this.physics, this.pageSnapping = true, this.onPageChanged, 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 Components children Set up : children Field to set each page component it wants to slide and switch ; In general use Container Encapsulate complex components ;
Code example : The following code is PageView Three sliding switching components are set in , All are Container Components , Every Container Are set in the center , Decorator , Displayed subcomponents Text ;
// Set up a layout container , For encapsulation PageView Components Container( // Set height height: 200, // Set margins margin: EdgeInsets.only(top: 10), // Set decoration , Dark orange background decoration: BoxDecoration( color: Colors.deepOrange ), // Set up subcomponents PageView child: PageView( // Set up PageView Several components encapsulated in children: <Widget>[ // The first page component Container( // Set the center mode , centered alignment:Alignment.center, // Decorator settings , Green background decoration: BoxDecoration(color: Colors.green), // Main text displayed child: Text(" page 0", style: TextStyle(fontSize: 20, color: Colors.black),), ), // The second page component Container( // Set the center mode , centered alignment:Alignment.center, // Decorator settings , Green background decoration: BoxDecoration(color: Colors.red), // Main text displayed child: Text(" page 1", style: TextStyle(fontSize: 20, color: Colors.white),), ), // The third page component Container( // Set the center mode , centered alignment:Alignment.center, // Decorator settings , Green background decoration: BoxDecoration(color: Colors.black), // Main text displayed child: Text(" page 2", style: TextStyle(fontSize: 20, color: Colors.yellow),), ), ], ), ),Two 、PageView Component complete code example
Complete code example :
import 'package:flutter/material.dart';class StatefulWidgetPage extends StatefulWidget {
@override _StatefulWidgetPageState createState() => _StatefulWidgetPageState();}class _StatefulWidgetPageState extends State<StatefulWidgetPage> {
/// The currently selected bottom navigation bar index int _currentSelectedIndex = 0; // This widget is the root of your application. @override Widget build(BuildContext context) {
// Text component style , Can be set to Text Text component // Set font size 20, The color is red TextStyle textStyle = TextStyle(fontSize: 20, color: Colors.red); return MaterialApp( title: 'StatefulWidgetPage Component example ', theme: ThemeData( primarySwatch: Colors.blue, ), home: Scaffold( // Top title bar appBar: AppBar(title: Text('StatefulWidgetPage Component example '),), // Bottom navigation bar BottomNavigationBar Set up // items You can set multiple BottomNavigationBarItem bottomNavigationBar: BottomNavigationBar( // Set the currently selected bottom navigation index currentIndex: _currentSelectedIndex, // Set the callback event of clicking the navigation bar at the bottom , index The parameter is the index value of the click onTap: (index){
// Callback StatefulWidget Component's setState Method of setting state , Modify the currently selected index // after BottomNavigationBar The component will automatically update the currently selected tab setState(() {
// change int _currentSelectedIndex The state of the variable _currentSelectedIndex = index; }); }, // entry items: [ // Set the bottom navigation bar entry , Each entry can be set with an icon BottomNavigationBarItem( // The default icon icon: Icon(Icons.home, color: Colors.grey,), // Icon in active state activeIcon: Icon(Icons.home, color: Colors.red,), // Set title title: Text(" Home page ") ), // Set the bottom navigation bar entry , Each entry can be set with an icon BottomNavigationBarItem( // The default icon icon: Icon(Icons.settings, color: Colors.grey,), // Icon in active state activeIcon: Icon(Icons.settings, color: Colors.red,), // Set title title: Text(" Set up ") ) ],), // Set the levitation button floatingActionButton: FloatingActionButton( onPressed: (){
print(" Click the hover button "); }, child: Text(" Levitation button assembly "), ), // Container Container usage body: _currentSelectedIndex == 0 ? // Refresh indicator component RefreshIndicator( // Display content child: ListView( children: <Widget>[ Container( // Corresponding to the bottom navigation bar settings tab // Set the decorator of the container , BoxDecoration Is the most commonly used decorator // You can check it by yourself BoxDecoration Properties that can be set in decoration: BoxDecoration(color: Colors.white), // Set up child How the sub components are centered , Center alignment: Alignment.center, // Child components , The subcomponent is set to a Column Components child: Column( // Column Child components , Set up here Text Text component children: <Widget>[ Text(" Main page tab , The drop-down refresh "), // Picture components , Load a picture from the network Image.network( // Picture address "https://img-blog.csdnimg.cn/20210228180808133.png", // Image width width: 200, // Picture height height: 200, ), // Input box components TextField( // Set the input box style decoration: InputDecoration( // Set content margins , The left and right margins are 10, The upper and lower margins are 0 contentPadding: EdgeInsets.fromLTRB(10, 0, 10, 0), // Set prompt copywriting information hintText: " Prompt information ", // Set prompt copy style hintStyle: TextStyle(fontSize: 20, color: Colors.grey), ), ), // Set up a layout container , For encapsulation PageView Components Container( // Set height height: 200, // Set margins margin: EdgeInsets.only(top: 10), // Set decoration , Dark orange background decoration: BoxDecoration( color: Colors.deepOrange ), // Set up subcomponents PageView child: PageView( // Set up PageView Several components encapsulated in children: <Widget>[ // The first page component Container( // Set the center mode , centered alignment:Alignment.center, // Decorator settings , Green background decoration: BoxDecoration(color: Colors.green), // Main text displayed child: Text(" page 0", style: TextStyle(fontSize: 20, color: Colors.black),), ), // The second page component Container( // Set the center mode , centered alignment:Alignment.center, // Decorator settings , Green background decoration: BoxDecoration(color: Colors.red), // Main text displayed child: Text(" page 1", style: TextStyle(fontSize: 20, color: Colors.white),), ), // The third page component Container( // Set the center mode , centered alignment:Alignment.center, // Decorator settings , Green background decoration: BoxDecoration(color: Colors.black), // Main text displayed child: Text(" page 2", style: TextStyle(fontSize: 20, color: Colors.yellow),), ), ], ), ), ], ), ), ], ), // Method of callback during refresh // When a drop-down operation occurs in the list , Call back the method // The callback is Future Type of onRefresh: _refreshIndicatorOnRefresh, ) : Container( // Corresponding to the bottom navigation bar settings tab // Set the decorator of the container , BoxDecoration Is the most commonly used decorator // You can check it by yourself BoxDecoration Properties that can be set in decoration: BoxDecoration(color: Colors.white), // Set up child How the sub components are centered , Center alignment: Alignment.center, // Child components , The subcomponent is set to a Column Components child: Column( // Column Child components , Set up here Text Text component children: <Widget>[ Text(" Set up page tabs ") ], ), ) , // This setting is related to _currentSelectedIndex == 0? Corresponding , ?: Ternary operator ), ); } /// RefreshIndicator When a pull-down operation occurs , Call back the method /// This is an asynchronous method , Add... Before the method body async keyword Future<Null> _refreshIndicatorOnRefresh() async{
// Pause 500 ms , Use await Keyword implementation // Here 500 ms Between , The list is in refresh state // 500 ms after , The list becomes non refreshed await Future.delayed(Duration(milliseconds: 500)); return null; }}Operation effect display :

3、 ... and 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- 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 ( unofficial , The translation is very good ) : 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 )
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_cmd ( 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/15500147 ( The source code snapshot of this blog , You can find the source code of this blog )

边栏推荐
- Sword finger offer (II) -- search in two-dimensional array
- Volvo's first MPV is exposed! Comfortable and safe, equipped with 2.0T plug-in mixing system, it is worth first-class
- Detailed upgrade process of AWS eks
- JDBC | Chapter 3: SQL precompile and anti injection crud operation
- Research Report on the overall scale, major manufacturers, major regions, products and applications of metal oxide arresters in the global market in 2022
- Number of DP schemes
- Cloud computing technology [2]
- Go cache of go cache series
- [cloud native topic -49]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - basic processes and steps
- Welfare | Hupu isux11 Anniversary Edition is limited to hand sale!
猜你喜欢

Add two numbers of leetcode

Activation function - relu vs sigmoid

JDBC | Chapter 4: transaction commit and rollback

Talk about macromolecule coding theory and Lao Wang's fallacy from the perspective of evolution theory

Review of the latest 2022 research on "deep learning methods for industrial defect detection"

Highly qualified SQL writing: compare lines. Don't ask why. Asking is highly qualified..

How does esrally perform simple custom performance tests?

I did a craniotomy experiment: talk about macromolecule coding theory and Lao Wang's fallacy from corpus callosum and frontal leukotomy
![[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)](/img/a7/0b87fa45ef2edd6fac519b40adbeae.gif)
[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)

Wu Enda's machine learning mind mapping insists on clocking in for 23 days - building a knowledge context, reviewing, summarizing and replying
随机推荐
Redis -- three special data types
[cloud native topic -49]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - basic processes and steps
Research Report on the overall scale, major manufacturers, major regions, products and applications of micro hydraulic cylinders in the global market in 2022
3DES (deSede) encryption CBC mode pkcs7padding filling Base64 encoding key 24byte iv8byte
2021 software security report: open source code, happiness and disaster depend on each other?
Research Report on market supply and demand and strategy of China's plastic pump industry
6 pyspark Library
在券商账户上买基金安全吗?哪里可以买基金
mysql
China microporous membrane filtration market trend report, technological innovation and market forecast
想问问,现在开户有优惠吗?在线开户是安全么?
[question brushing diary] classic questions of dynamic planning
[hands on deep learning]02 softmax regression
Add two numbers of leetcode
[12] the water of the waves is clear, which can wash my tassel. The water of the waves is muddy, which can wash my feet
Research Report on market supply and demand and strategy of Chinese garden equipment industry
MySQL learning notes (Advanced)
[fluent] dart function (function composition | private function | anonymous function | function summary)
kernel tty_ struct
Is it safe to buy funds on securities accounts? Where can I buy funds