zoukankan      html  css  js  c++  java
  • flutter ListView横向列表&不定长列表&网格

    ListView横向列表

    效果:

    (可以左右滑动)

    代码形式1:

    main.dart

    import 'package:flutter/material.dart';
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'dasldjalsdjasldj',
          home: Scaffold(
            appBar: new AppBar(title: new Text('new texrdasdasd'),),
            body: Center(
              child: Container(
                height: 200.0,
                child: new ListView(
                  scrollDirection: Axis.horizontal,
                  children: [
                    new Container(
                       120,
                      color: Colors.lime,
                    ),
                    new Container(
                       120,
                      color: Colors.pinkAccent,
                    ),
                    new Container(
                       120,
                      color: Colors.purpleAccent,
                    ),
                    new Container(
                       120,
                      color: Colors.deepPurple,
                    ),                                                
                  ],
                ),
              ),
            )
          ),
        );
      }
    }
    
    void main() {
      runApp(MyApp());
    }

    代码形式2:

    main.dart

    import 'package:flutter/material.dart';
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'dasldjalsdjasldj',
          home: Scaffold(
            appBar: new AppBar(title: new Text('new texrdasdasd'),),
            body: Center(
              child: Container(
                height: 200.0,
                child: Mylist(),
              ),
            )
          ),
        );
      }
    }
    
    
    class Mylist extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return ListView(
          scrollDirection: Axis.horizontal,
          children: [
            new Container(
               120,
              color: Colors.lime,
            ),
            new Container(
               120,
              color: Colors.pinkAccent,
            ),
            new Container(
               120,
              color: Colors.purpleAccent,
            ),
            new Container(
               120,
              color: Colors.deepPurple,
            ),
          ],
        );
      }
    }
    void main() {
      runApp(MyApp());
    }

    ListView不定长列表

    效果:

    代码:

    main.dart

    import 'package:flutter/material.dart';
    
    class MyApp extends StatelessWidget {
    
      final List<String> items;
      MyApp({required this.items});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'dasldjalsdjasldj',
          home: Scaffold(
            appBar: new AppBar(title: new Text('new texrdasdasd'),),
            body: new ListView.builder(
              itemCount: items.length,
              itemBuilder: (context, index) {
              return new ListTile(
                title: new Text('${items[index]}'),
              );
            })
          ),
        );
      }
    }
    void main() {
      runApp(MyApp(items: new List<String>.generate(20, (index) => "物品 $index"),));
    }

    网格

    import 'package:flutter/material.dart';
    
    class MyApp extends StatelessWidget {
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'dasldjalsdjasldj',
          home: Scaffold(
            appBar: new AppBar(title: new Text('new texrdasdasd'),),
            body: GridView.count(
              crossAxisCount: 3,
              children: [
                const Text('hello'),
                const Text('23'),
                const Text('2323'),
                const Text('323'),
                const Text('he2323llo'),
                const Text('h322ello'),
                const Text('he23llo'),
                const Text('he23llo'),
                const Text('2323'),
                const Text('LAST'),
              ],)
          ),
        );
      }
    }
    void main() {
      runApp(MyApp());
    }
  • 相关阅读:
    ExtJs之表单(form)
    tf.where
    kuiper流式计算完整实例演示
    centos下搭建kuiper以及kuiper-manager
    Centos搭建EMQX和EMQ-Dashboard(踩坑精华版)
    代码生成器
    [MIT新技术大会]Jeff Bezos把EC2、S3和土耳其机器人描述为亚马逊“11年来的大规模万维网计算”方面的结晶,强调把后台基础设施作为服务
    《商业周刊》封面文章《谷歌和云的智慧》,讲到谷歌的新战略是“把惊人的计算能力放到众人手里”
    C# 连接 Sqlserver2005 Analysis Service的总结
    POJ_1064 二分搜索
  • 原文地址:https://www.cnblogs.com/xkxf/p/15477729.html
Copyright © 2011-2022 走看看