網站首頁 編程語言 正文
本文實例為大家分享了Flutter StaggeredGridView實現瀑布流的具體代碼,供大家參考,具體內容如下
在根目錄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
相關推薦
- 2023-11-15 Python pip指定安裝鏡像源;pip安裝如何指定和更改鏡像源?
- 2022-10-02 Flutter的鍵值存儲數據庫使用示例詳解_Android
- 2023-07-14 elemment ui tabs實現思路
- 2022-06-18 C語言簡明講解操作符++和--的使用方法_C 語言
- 2022-07-15 SQL?Server創建用戶定義函數_MsSql
- 2022-11-29 React?中?memo?useMemo?useCallback?到底該怎么用_React
- 2022-04-18 python?如何使用requests下載文件_python
- 2022-12-16 C++?Boost?EnableIf函數使用介紹_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支