flutter基础之Grid List

作者: iCloudEnd | 来源:发表于2019-02-13 05:23 被阅读24次

    有时我们需要Grid式的列表,例如我们打算做个手机淘宝或者网上商城一类的App。

    使用方法

    GridView.count(
      // Create a grid with 2 columns. If you change the scrollDirection to
      // horizontal, this would produce 2 rows.
      crossAxisCount: 2,
      // Generate 100 Widgets that display their index in the List
      children: List.generate(100, (index) {
        return Center(
          child: Text(
            'Item $index',
            style: Theme.of(context).textTheme.headline,
          ),
        );
      }),
    );
    

    Sample 代码

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        final title = 'Grid List';
    
        return MaterialApp(
          title: title,
          home: Scaffold(
            appBar: AppBar(
              title: Text(title),
            ),
            body: GridView.count(
              // Create a grid with 2 columns. If you change the scrollDirection to
              // horizontal, this would produce 2 rows.
              crossAxisCount: 2,
              // Generate 100 Widgets that display their index in the List
              children: List.generate(100, (index) {
                return Center(
                  child: Text(
                    'Item $index',
                    style: Theme.of(context).textTheme.headline,
                  ),
                );
              }),
            ),
          ),
        );
      }
    }
    

    运行效果


    Jietu20190213-051906@2x.jpg

    相关文章

      网友评论

        本文标题:flutter基础之Grid List

        本文链接:https://www.haomeiwen.com/subject/vbtreqtx.html