当前位置:网站首页>[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 )
边栏推荐
- Welfare | Hupu isux11 Anniversary Edition is limited to hand sale!
- Add two numbers of leetcode
- Import a large amount of data to redis in shell mode
- Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
- Research Report on the overall scale, major manufacturers, major regions, products and applications of building automation power meters in the global market in 2022
- Welfare, let me introduce you to someone
- Construction and maintenance of business websites [7]
- Interpretation of some papers published by Tencent multimedia laboratory in 2021
- ctf-HCTF-Final-Misc200
- Plastic floating dock Industry Research Report - market status analysis and development prospect forecast
猜你喜欢
[question brushing diary] classic questions of dynamic planning
[cloud native topic -49]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - basic processes and steps
Spend more time with your computer on this special holiday, HHH
JDBC | Chapter 4: transaction commit and rollback
[871. Minimum refueling times]
Detailed upgrade process of AWS eks
Customized Huawei hg8546m restores Huawei's original interface
5 environment construction spark on yarn
Go language learning summary (5) -- Summary of go learning notes
Review of the latest 2022 research on "deep learning methods for industrial defect detection"
随机推荐
Research Report on the overall scale, major manufacturers, major regions, products and applications of hollow porcelain insulators in the global market in 2022
Micro SD Card Industry Research Report - market status analysis and development prospect forecast
Construction and maintenance of business websites [9]
Accounting regulations and professional ethics [16]
1005 spell it right (20 points) "PTA class a exercise"
[hands on deep learning]02 softmax regression
Who do you want to open a stock account? Is it safe to open a mobile account?
Common routines of compressed packets in CTF
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of signal distributors in the global market in 2022
A river of spring water flows eastward
Welfare, let me introduce you to someone
In depth research and investment feasibility report of global and Chinese isolator industry, 2022-2028
[fluent] dart generic (generic class | generic method | generic with specific type constraints)
Customized Huawei hg8546m restores Huawei's original interface
Web3js method to obtain account information and balance
[question brushing diary] classic questions of dynamic planning
One week dynamics of dragon lizard community | 2.07-2.13
Check the confession items of 6 yyds
An analysis of the past and present life of the meta universe
Research Report on micro gripper industry - market status analysis and development prospect prediction