第一种
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: new AppBar(title: new Text ('mystudys')),
body: GridView.count(
padding: const EdgeInsets.all(20.0), //页面外边距
crossAxisSpacing:10.0, //网格边距
crossAxisCount: 3, // 一行显示多少列
children: <Widget>[
const Text('i love ncuhome'),
const Text('i love running'),
const Text('i love running'),
const Text('i love ncuhome'),
const Text('i love running'),
const Text('i love running'),
const Text('i love ncuhome'),
const Text('i love running'),
const Text('i love running'),
],
)
),
);
}
}
第二种
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: new AppBar(title: new Text ('mystudys')),
body: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,//一行展示个数
mainAxisSpacing: 4.0,//行间距
crossAxisSpacing: 2.0,//列间距
childAspectRatio: 0.8// 横竖比
),
children: <Widget>[
new Image.network('https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2399609660,3433792887&fm=58&s=BEB5B0AE44339FF9062DEE8C03008087', fit: BoxFit.cover,),
new Image.network('https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3921574999,1717079445&fm=58&s=19C8EF5D8F426E4D18C824780300807E', fit: BoxFit.cover,),
new Image.network('https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3640626071,901694792&fm=58&s=03F05A906A197EC45C9D4D51030070E2', fit: BoxFit.cover,),
new Image.network('https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1138506920,2521439042&fm=58&s=251E3FD7F8D133F91EBC977B03003064', fit: BoxFit.cover,),
new Image.network('https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3640626071,901694792&fm=58&s=03F05A906A197EC45C9D4D51030070E2', fit: BoxFit.cover,),
new Image.network('https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=3197691219,1079587509&fm=58&s=4D1E5C9B189A1FE97A1CF4CF03007033', fit: BoxFit.cover,),
new Image.network('https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3259142462,2413291210&fm=58&s=EC2000D610DF37FFCD009112030060D3', fit: BoxFit.cover,),
new Image.network('https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3640626071,901694792&fm=58&s=03F05A906A197EC45C9D4D51030070E2', fit: BoxFit.cover,),
new Image.network('https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3640626071,901694792&fm=58&s=03F05A906A197EC45C9D4D51030070E2', fit: BoxFit.cover,),
],
)
)
);
}
}