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(List<String> args) {
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)),
),
);
}
}
效果如下:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。