Last active
February 16, 2020 06:54
-
-
Save ryanlid/d6e9edcee135ad1cffe1df8980a3127f to your computer and use it in GitHub Desktop.
GridView 网格布局
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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