Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Last active February 16, 2020 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlid/d6e9edcee135ad1cffe1df8980a3127f to your computer and use it in GitHub Desktop.
Save ryanlid/d6e9edcee135ad1cffe1df8980a3127f to your computer and use it in GitHub Desktop.
GridView 网格布局
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: "GridView 网格布局",
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<Container> _build(int count) {
return List<Container>.generate(
count,
(int index) => Container(
child: Image.network(
'https://static.lidong.me/file/expression/emoji/google/${index + 1}.gif'),
));
}
Widget buildGrid() {
return GridView.extent(
maxCrossAxisExtent: 150.0,
padding: EdgeInsets.all(4.0),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
children: _build(9),
);
}
return Scaffold(
appBar: AppBar(
title: Text("GridView 网格布局示例"),
),
body: Center(
child: buildGrid(),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment