Flutter学习 — 创建一个 grid List

效果图:

在这里插入图片描述

代码+注释:

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

猜你喜欢

转载自blog.csdn.net/qq_27494201/article/details/106840667