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]}'),
                  );
                }),
          ),
        );
      }
    }
  • 相关阅读:
    CCF CSP 题解
    CCF CSP 2019032 二十四点
    CCF CSP 2018121 小明上学
    CCF CSP 2019092 小明种苹果(续)
    CCF CSP 2019091 小明种苹果
    CCF CSP 2019121 报数
    CCF CSP 2019031 小中大
    CCF CSP 2020061 线性分类器
    CCF CSP 2020062 稀疏向量
    利用国家气象局的webservice查询天气预报(转载)
  • 原文地址:https://www.cnblogs.com/timba1322/p/12486562.html
Copyright © 2011-2022 走看看