網(wǎng)站首頁 編程語言 正文
本文實例為大家分享了Flutter StaggeredGridView實現(xiàn)瀑布流的具體代碼,供大家參考,具體內(nèi)容如下
在根目錄pubspec.yaml文件中添加依賴
dependencies: ? ? ? flutter_staggered_grid_view: 0.4.0
import 'dart:math'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; void main(Listargs) { ? runApp(app()); } class app extends StatelessWidget { ? const app({Key key}) : super(key: key); ? @override ? Widget build(BuildContext context) { ? ? return MaterialApp( ? ? ? home: homebody(), ? ? ); ? } } class homebody extends StatelessWidget { ? @override ? Widget build(BuildContext context) { ? ? return Scaffold( ? ? ? appBar: AppBar( ? ? ? ? title: const Text('StaggeredGridView'), ? ? ? ), ? ? ? body: Padding( ? ? ? ? padding: const EdgeInsets.all(4), ? ? ? ? child: StaggeredGridView.countBuilder( ? ? ? ? ? ? shrinkWrap: true, ? ? ? ? ? ? crossAxisCount: 4, ? ? ? ? ? ? crossAxisSpacing: 4, ? ? ? ? ? ? mainAxisSpacing: 4, ? ? ? ? ? ? itemCount: 100, ? ? ? ? ? ? itemBuilder: (context, index) { ? ? ? ? ? ? ? return Container( ? ? ? ? ? ? ? ? height:100+200*Random().nextDouble(), ? ? ? ? ? ? ? ? ? color: Colors.green, ? ? ? ? ? ? ? ? ? child: new Center( ? ? ? ? ? ? ? ? ? ? child: new CircleAvatar( ? ? ? ? ? ? ? ? ? ? ? backgroundColor: Colors.white, ? ? ? ? ? ? ? ? ? ? ? child: new Text('$index'), ? ? ? ? ? ? ? ? ? ? ), ? ? ? ? ? ? ? ? ? )); ? ? ? ? ? ? }, ? ? ? ? ? ? staggeredTileBuilder: (index) => StaggeredTile.fit(1)), ? ? ? ), ? ? ); ? } }
效果如下:
原文鏈接:https://blog.csdn.net/m0_38013946/article/details/122258121
相關(guān)推薦
- 2022-04-15 windows+vscode穿越跳板機調(diào)試遠程代碼的圖文教程_python
- 2022-02-06 TP6記錄報錯的SQL語句
- 2022-12-25 Android?Flutter實現(xiàn)評分組件的示例代碼_Android
- 2022-08-20 Pygame?精準檢測圖像碰撞的問題_python
- 2022-07-07 Pytorch卷積神經(jīng)網(wǎng)絡(luò)遷移學(xué)習(xí)的目標及好處_python
- 2022-08-12 C#?Unicode編碼解碼的實現(xiàn)_C#教程
- 2023-02-06 C語言實現(xiàn)文件讀寫功能流程_C 語言
- 2022-06-11 C#實現(xiàn)文件Move和Copy操作_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支