7. Flutter——GridView元件
GridView 元件的常用引數
-
當資料量很大的時候用矩陣方式排列比較清晰。此時我們可以用網格列表元件 GridView 實 現佈局。
-
常用屬性:
名稱 | 型別 | 說明 |
---|---|---|
scrollDirection | Axis | 滾動 |
padding | EdgeInsetsGeometry | 內邊距 |
resolve | bool | 元件反向序列化 |
crossAxisSpacing | double | 水平子 Widget 之間間距 |
mainAxisSpacing | double | 垂直子 Widget 之間間距 |
crossAxisCount | int | 一行的 Widget 數量 |
childAspectRatio | double | 子 Widget 寬高比例 |
children | int | < Widget >[ ] |
gridDelegate | SliverGridDelegateWithFix edCrossAxisCount(常用) SliverGridDelegateWithMax CrossAxisExtent | 控制佈局主要用在 GridView.builder 裡面 |
GridView.count 實現網格佈局
import'package:flutter/material.dart';
import'res/listData.dart';
voidmain()=>runApp(MyApp());
classMyAppextendsStatelessWidget{
@override
Widgetbuild(BuildContextcontext){
returnMaterialApp(
home:Scaffold(
appBar:AppBar(title:Text('FlutterDemo')),
body:LayoutContent(),
));
}
}
classLayoutContentextendsStatelessWidget{
List<Widget>_getListData(){
vartempList=listData.map((value){
returnContainer(
child: Column(
children:<Widget>[
Image.network(value["imageUrl"]),
SizedBox(height:12),
Text(value["title"],
textAlign:TextAlign.center,
style:TextStyle(fontSize:20)),
],
),
decoration:BoxDecoration(
border:Border.all(
color:Color.fromRGBO(230,230,230,0.9),
width:1.0
)
),
);
});
returntempList.toList();
}
@override
Widgetbuild(BuildContextcontext){
returnGridView.count(
padding:EdgeInsets.all(20),
crossAxisCount:2,
crossAxisSpacing:20,
mainAxisSpacing:20,
children:this._getListData(),
);
}
}
GridView.builder 實現網格佈局
import'package:flutter/material.dart';
import'res/listData.dart';
voidmain()=>runApp(MyApp());
classMyAppextendsStatelessWidget{
@override Widgetbuild(BuildContextcontext){
returnMaterialApp(
home:Scaffold(
appBar:AppBar(title:Text('FlutterDemo')),
body:LayoutContent(),
));
}
}
classLayoutContentextendsStatelessWidget{
Widget_getListData(context,index){
returnContainer(
child: Column(
children:<Widget>[
Image.network(listData[index]["imageUrl"]),
SizedBox(height:12),
Text(listData[index]["title"],
textAlign: TextAlign.center,style:TextStyle(fontSize: 20)),
],
),
decoration:BoxDecoration(
border:Border.all(
color:Color.fromRGBO(230,230,230,0.9),
width:1.0
)
),
);
}
@override
Widgetbuild(BuildContextcontext){
returnGridView.builder(
itemCount:listData.length,
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
//橫軸元素個數
crossAxisCount:2,
//縱軸間距
mainAxisSpacing:20.0,
//橫軸間距
crossAxisSpacing:10.0,
//子元件寬高長度比例
childAspectRatio:1.0
),
itemBuilder:this._getListData,
);
}
}
相關文章
- flutter Swiper+GridViewFlutterView
- jQuery找到GridView控制元件jQueryView控制元件
- Flutter的staggered GridView詳細使用FlutterView
- Flutter網格型佈局 - GridView篇FlutterView
- Flutter 佈局(八)- Stack、IndexedStack、GridView詳解FlutterIndexView
- Flutter GridView 中使用Offstage 或者 Visibility 無效FlutterView
- Flutter入門進階之旅(十四)ListView&GridViewFlutterView
- Flutter Web網站之ScrollView+GridView優化FlutterWeb網站View優化
- Flutter基礎(七)Scrolling Widget之ListView、GridView、PageViewFlutterView
- Flutter 基礎(七)Scrolling Widget 之 ListView、GridView、PageViewFlutterView
- Flutter元件Flutter元件
- C# DevExpress控制元件Gridview和GridControl學習總結C#devExpress控制元件View
- Flutter元件ImageFlutter元件
- GridView繫結資料與隱藏指定控制元件(模板列)View控制元件
- GridView全選View
- Flutter元件學習(一)—— Text元件Flutter元件
- Flutter 元件總結Flutter元件
- Flutter | ConstrainedBox & UnconstrainedBox 元件FlutterAI元件
- Flutter元件大全(四)Flutter元件
- Flutter元件大全(五)Flutter元件
- Flutter元件大全(一)Flutter元件
- Flutter元件總結Flutter元件
- Flutter | 佈局元件Flutter元件
- Flutter 使用GridView寫一個根據child數量自動增加的GridListFlutterView
- 7.介面
- Flutter 拖拽排序元件 ReorderableListViewFlutter排序元件View
- Flutter——Materia Design元件集合Flutter元件
- Flutter | 1.9 全新元件 ToggleButtonsFlutter元件
- Flutter widget元件簡介Flutter元件
- Flutter元件之ChoiceChip教程Flutter元件
- Flutter自定義元件-MultiShowerFlutter元件
- Flutter控制元件--AppBarFlutter控制元件APP
- Unity的Flutter元件渲染UnityFlutter元件
- GridView列相同合併View
- Flutter新手入門常用元件總結,讓你瞭解更多的Flutter元件?Flutter元件
- Flutter 系列文章:Flutter Text 控制元件介紹Flutter控制元件
- Flutter 系列文章:Flutter Container 控制元件介紹FlutterAI控制元件
- Flutter 系列文章:Flutter Image 控制元件介紹Flutter控制元件