效果图:

Flutter学习 — 创建一个 grid List_android

代码+注释:

import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final title = 'Grid List';

    return new MaterialApp(
      title: title,
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text(title),
        ),
        body: new GridView.count(
          // Create a grid with 2 columns. If you change the scrollDirection to
          // horizontal, this would produce 2 rows.
          /**
           * 创建一个包含2列的网格。 如果将scrollDirection更改为水平,这将产生2行。
           */
          crossAxisCount: 2,
          // Generate 100 Widgets that display their index in the List
          // 生成100个在列表中显示其索引的小部件,参数一: 数量,参数二: 下标
          children: new List.generate(100, (index) {
            return new Center(
              child: new Text(
                'Item $index',
                style: Theme.of(context).textTheme.headline,
              ),
            );
          }),
        ),
      ),
    );
  }
}

 

更多原理请参考谷歌官网:创建一个 grid List