当前位置:网站首页>[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
2022-07-02 21:33:00 【Programmer community】
List of articles
- One 、FractionallySizedBox Components
- Two 、Stack Layout components
- 3、 ... and 、Positioned Components
- Four 、 Complete code example
- 5、 ... and 、 Related resources
One 、FractionallySizedBox Components
FractionallySizedBox Components : The controllable components are horizontal / Fill the parent container vertically ;
class FractionallySizedBox extends SingleChildRenderObjectWidget {
const FractionallySizedBox({
Key key, this.alignment = Alignment.center, this.widthFactor, this.heightFactor, Widget child, }) : assert(alignment != null), assert(widthFactor == null || widthFactor >= 0.0), assert(heightFactor == null || heightFactor >= 0.0), super(key: key, child: child);}
FractionallySizedBox Component usage :
- Set the width to fill the parent container : widthFactor Field settings ;
- Set the height to fill the parent container : heightFactor Field settings ;
- Set tile components : child Field settings Widget Components ;
// level / Tile components vertically FractionallySizedBox( // Set the width to fill the parent container widthFactor: 1, // Set the height to fill the parent container heightFactor: 1, // The level to set / Components of tile operation in vertical direction child: Components to control tiling ( Widget type ), ),)
Code example :
// level / Tile components vertically FractionallySizedBox( // Set the width to fill the parent container widthFactor: 1, // The level to set / Components of tile operation in vertical direction child: Container( decoration: BoxDecoration(color: Colors.black), child: Text( " Highly adaptive , The width fills the parent container ", style: TextStyle(color: Colors.amberAccent), ), ),)
Two 、Stack Layout components
Stack Layout components : Equivalent to frame layout ;
class Stack extends MultiChildRenderObjectWidget {
/// Creates a stack layout widget. /// /// By default, the non-positioned children of the stack are aligned by their /// top left corners. Stack({
Key key, this.alignment = AlignmentDirectional.topStart, this.textDirection, this.fit = StackFit.loose, this.overflow = Overflow.clip, List<Widget> children = const <Widget>[], }) : super(key: key, children: children);}
Stack Layout component usage : stay children Set several fields Widget Components , The last component is displayed at the top , Overwrite the previous components ;
Code example :
// Frame layout Stack( children: <Widget>[ Image.network("https://img-blog.csdnimg.cn/20210301145757946.png", width: 100, height: 100, ), Image.network("https://img-blog.csdnimg.cn/20210228180808133.png", width: 25, height: 25, ), ],),
3、 ... and 、Positioned Components
Positioned Components : Used in Stack Specify the location of a component in the layout
class Positioned extends ParentDataWidget<Stack> {
/// Creates a widget that controls where a child of a [Stack] is positioned. /// /// Only two out of the three horizontal values ([left], [right], /// [width]), and only two out of the three vertical values ([top], /// [bottom], [height]), can be set. In each case, at least one of /// the three must be null. /// /// See also: /// /// * [Positioned.directional], which specifies the widget's horizontal /// position using `start` and `end` rather than `left` and `right`. /// * [PositionedDirectional], which is similar to [Positioned.directional] /// but adapts to the ambient [Directionality]. const Positioned({
Key key, this.left, // Set the distance from the component to the left this.top, // Set the distance from the component to the top this.right, // Set the distance from the component to the right this.bottom, // Set the distance between the component and the bottom this.width, // Set component width this.height, // Component height settings @required Widget child, }) : assert(left == null || right == null || width == null), assert(top == null || bottom == null || height == null), super(key: key, child: child);}
Positioned Component usage :
- Set component width : width Field ;
- Component height settings : height Field ;
- Set the distance from the component to the left : left Field ;
- Set the distance from the component to the top : top Field ;
- Set the distance from the component to the right : right Field ;
- Set the distance between the component and the bottom : bottom Field ;
Code example :
// Frame layout Stack( children: <Widget>[ Image.network("https://img-blog.csdnimg.cn/20210301145757946.png", width: 100, height: 100, ), // Set the component location at Stack Relative position of Positioned( right: 0, // From the right side 0 distance bottom: 0, // From the bottom 0 distance // Set the component position of the constraint child: Image.network("https://img-blog.csdnimg.cn/20210228180808133.png", width: 25, height: 25, ), ), ],),
Four 、 Complete code example
Complete code example :
import 'package:flutter/material.dart';class LayoutPage extends StatefulWidget {
@override _LayoutPageState createState() => _LayoutPageState();}class _LayoutPageState extends State<LayoutPage> {
/// 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: ' Example layout components ', theme: ThemeData( primarySwatch: Colors.blue, ), home: Scaffold( // Top title bar appBar: AppBar(title: Text(' Example layout components '),), // 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 "), // A linear layout arranged horizontally Row( children: <Widget>[ // Original picture , For comparison Image.network("https://img-blog.csdnimg.cn/20210301145757946.png", width: 100, height: 100, ), // Circular clipping component , take child Cut the layout into a circle ClipOval( // Use SizedBox Component constrains layout size child: SizedBox( width: 100, height: 100, // Use SizedBox Constrain this Image Component size child: Image.network("https://img-blog.csdnimg.cn/20210301145757946.png"), ), ), Padding( // Set the inside margin 5 padding: EdgeInsets.all(15), // Square cutting component , Cut the components into squares child: ClipRRect( // Set the clipping fillet , Set the radius of the four corners to 10 Fillet of borderRadius: BorderRadius.all(Radius.circular(10)), // Modify the transparency component , Set up here 50% transparency child: Opacity( opacity: 0.5, // Set up 100x100 Size picture component child: Image.network("https://img-blog.csdnimg.cn/20210301145757946.png", width: 100, height: 100, ), ), ), ), ], ), // Set up a layout container , For encapsulation PageView Components Container( // Set height height: 200, // Set margins margin: EdgeInsets.all(15), // Set decoration , Dark orange background decoration: BoxDecoration( color: Colors.white ), // Set up subcomponents PageView Cutting components for child: PhysicalModel( color: Colors.transparent, // Set the fillet radius 15 borderRadius: BorderRadius.circular(50), // Set crop behavior , Anti-Aliasing clipBehavior: Clip.antiAlias, // Set up PageView Components 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),), ), ], ), ), ), Container( child: Column( children: <Widget>[ // level / Tile components vertically FractionallySizedBox( // Set the width to fill the parent container widthFactor: 1, // The level to set / Components of tile operation in vertical direction child: Container( decoration: BoxDecoration(color: Colors.black), child: Text( " Highly adaptive , The width fills the parent container ", style: TextStyle(color: Colors.amberAccent), ), ), ) ], ), ), // Frame layout Stack( children: <Widget>[ Image.network("https://img-blog.csdnimg.cn/20210301145757946.png", width: 100, height: 100, ), // Set the component location at Stack Relative position of Positioned( right: 0, // From the right side 0 distance bottom: 0, // From the bottom 0 distance // Set the component position of the constraint child: Image.network("https://img-blog.csdnimg.cn/20210228180808133.png", width: 25, height: 25, ), ), ], ), ], ), ), ], ), // 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 :
5、 ... 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/15484718 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- MySQL learning notes (Advanced)
- Happy Lantern Festival! Tengyuanhu made you a bowl of hot dumplings!
- Golang embeds variables in strings
- Friends who firmly believe that human memory is stored in macromolecular substances, please take a look
- Analysis of enterprise financial statements [1]
- JDBC | Chapter 3: SQL precompile and anti injection crud operation
- Accounting regulations and professional ethics [17]
- Construction and maintenance of business websites [8]
- [shutter] statefulwidget component (image component | textfield component)
- [C language] [sword finger offer article] - replace spaces
猜你喜欢
rwctf2022_ QLaaS
[fluent] dart technique (independent main function entry | nullable type determination | default value setting)
How is LinkedList added?
MySQL learning notes (Advanced)
[shutter] shutter layout component (Introduction to layout component | row component | column component | sizedbox component | clipoval component)
Roommate, a king of time, I took care of the C language structure memory alignment
Go language learning summary (5) -- Summary of go learning notes
One week dynamics of dragon lizard community | 2.07-2.13
Unexpectedly, there are such sand sculpture code comments! I laughed
D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
随机推荐
rwctf2022_ QLaaS
Backpack template
Hot backup routing protocol (HSRP)
Research Report on minimally invasive medical robot industry - market status analysis and development prospect prediction
Share the easy-to-use fastadmin open source system - Installation
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of multi-channel signal conditioners in the global market in 2022
Number of DP schemes
This team with billions of data access and open source dreams is waiting for you to join
Construction and maintenance of business website [5]
2021 software security report: open source code, happiness and disaster depend on each other?
[shutter] statefulwidget component (pageview component)
Sword finger offer (II) -- search in two-dimensional array
[fluent] dart generic (generic class | generic method | generic with specific type constraints)
One week dynamics of dragon lizard community | 2.07-2.13
Capacity expansion mechanism of ArrayList
Research Report on the overall scale, major manufacturers, major regions, products and applications of outdoor vacuum circuit breakers in the global market in 2022
Interpretation of some papers published by Tencent multimedia laboratory in 2021
Add two numbers of leetcode
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of the inverted front fork of the global market in 2022
Cardinality sorting (detailed illustration)