zoukankan      html  css  js  c++  java
  • ListView

    列表使用

    body: new ListView(
              children: <Widget>[
                /*new Image.network(
                    'https://cdn2.jianshu.io/assets/web/banner-s-club-aa8bdf19f8cf729a759da42e4a96f366.png'),
                new Image.network(
                    'https://cdn2.jianshu.io/assets/web/banner-s-7-1a0222c91694a1f38e610be4bf9669be.png'),
                 */ //图片列表使用
                new ListTile(
                  leading: new Icon(
                    Icons.perm_camera_mic,
                  ),
                  title: new Text('perm_camera_mic'),
                ),
                new ListTile(
                  leading: new Icon(
                    Icons.perm_phone_msg,
                  ),
                  title: new Text('perm_phone_msg'),
                ),
              ],
            ),

    横向列表:ListView组件里加一个scrollDirection属性

    body: new Center(
                child: new Container(
                    height: 200.0,
                    child: new ListView(
                      scrollDirection: Axis.horizontal, //Axis.vertical:纵向列表
                      children: <Widget>[
                        new Container(
                           230.0,
                          color: Colors.lightBlue,
                        ),
                        new Container(
                           230.0,
                          color: Colors.lightGreen,
                        ),
                      ],
                    ))),

    Dart语言List的声明方式:

    • var myList = List(): 非固定长度的声明。
    • var myList = List(2): 固定长度的声明。
    • var myList= List<String>():固定类型的声明方式。
    • var myList = [1,2,3]: 对List直接赋值
    import 'package:flutter/material.dart';
    
    void main() =>
        runApp(MyApp(items: List<String>.generate(1000, (i) => 'item $i')));
    
    class MyApp extends StatelessWidget {
      final List<String> items;
      MyApp({Key key, @required this.items}) : super(key: key);
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'ListView Dome',
          home: new Scaffold(
            appBar: new AppBar(title: new Text('ListView Widget')),
            body: new ListView.builder(
                itemCount: items.length,
                itemBuilder: (context, index) {
                  return new ListTile(
                    title: new Text('${items[index]}'),
                  );
                }),
          ),
        );
      }
    }
  • 相关阅读:
    ES6-11学习笔记--深拷贝与浅拷贝
    ES6-11学习笔记--对象的扩展
    ES6-11学习笔记--箭头函数
    ES6-11学习笔记--扩展运算符与rest参数
    ES6-11学习笔记--函数的参数
    ES6-11学习笔记--数组的扩展
    ES6-11学习笔记--解构赋值
    ES6-11学习笔记--数组遍历
    班课2
    班课1
  • 原文地址:https://www.cnblogs.com/timba1322/p/12486562.html
Copyright © 2011-2022 走看看