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());
    }
  • 相关阅读:
    Facebook的体系结构分析---外文转载
    简易的IOS位置定位服务
    【简易版】IOS仿periscope自制狂赞飘桃心
    The Linux Programming Interface
    freeswitch嵌入lua脚本
    Epoll Tutorial – epoll In 3 Easy Steps!
    基于freeswitch的webrtc与sip终端呼叫
    buildroot添加第三方库
    rfc
    TCP/UDP Server-Client implementation in C
  • 原文地址:https://www.cnblogs.com/xkxf/p/15477729.html
Copyright © 2011-2022 走看看