• flutter-ListView(列表组件)


    1.纵向列表

    import 'package:flutter/material.dart';
    
    void main ()=>runApp(MyApp());
    
    class MyApp extends StatelessWidget{
      @override
      Widget build(BuildContext context){
        return MaterialApp(
          title:"listView",
          home:Scaffold(
            appBar: new AppBar(
              title:Text("listView Widget")
            ),
            body: ListView(
              children: <Widget>[
                new ListTile(
                  leading:new Icon(Icons.access_time),
                  title: Text("access_time"),
                ),
                new ListTile(
                  leading:Icon(Icons.accessible_forward),
                  title:Text("forward")
                ),
                Image.asset('images/2222.png',
                  alignment: Alignment.topLeft,
                ),
                new ListTile(
                  leading: new CircleAvatar(
                    child: new Text("牛"),
                    backgroundColor: Colors.blue[400],
                  ),
                  title: new Text("牛牛牛"),
                  subtitle: new Text("牛是真的牛"),
                ),
                new ListTile(
                  leading: new CircleAvatar(
                    child: new Text("牛"),
                    backgroundColor: Colors.blue[400],
                  ),
                  title: new Text("牛牛牛"),
                  subtitle: new Text("牛是真的牛"),
                ),
                new Container(
                  100.0,
                  height:100.0,
                  child: Text("data"),
                  color:Colors.greenAccent
                )
              ],
            )
          )
        );
      }
    }

    2.横向列表+组件化写法

    import 'package:flutter/material.dart';
    
    void main()=>runApp(MyApp());
    
    class MyApp extends StatelessWidget{
      @override
      Widget build(BuildContext content){
        return MaterialApp(
          title:'listView',
          home:Scaffold(
            appBar: AppBar(
              title:Text("listView")
            ),
            body: Container(
              height: 200.0,
              child: MyList()
            ),
          )
        );
      }
    }
    
    
    class MyList extends StatelessWidget{
      @override
      Widget build(BuildContext context){
        return ListView(
          scrollDirection:Axis.horizontal,
          children: <Widget>[
            Container(
              180.0,
              color:Colors.indigo[200],
              child: Image(
                image: AssetImage('images/2222.png'),
                fit: BoxFit.cover,
              ),
            ),
            Container(
              180.0,
              color:Colors.yellowAccent[100],
              child: Image(
                image: AssetImage('images/2222.png'),
                fit: BoxFit.cover,
              ),
            ),
            Container(
              180.0,
              color:Colors.deepOrange[100],
              child: Image(
                image: AssetImage('images/2222.png'),
                fit: BoxFit.cover,
              ),
            ),
            Container(
              180.0,
              color:Colors.blue[100],
              child: Image(
                image: AssetImage('images/2222.png'),
                fit: BoxFit.cover,
              ),
            )
          ],
        );
      }
    }

    3.动态加载列表

    import 'package:flutter/material.dart';
    
    void main()=>runApp(MyApp(
      // generate 生成 生成1000个
      items:new List<String>.generate(1000, (i) => "item $i")
    ));
    
    class MyApp extends StatelessWidget{
    
      //接收参数
      final List<String> items;
      //required的意思是必须的
      MyApp({Key key,@required this.items}):super(key:key);
    
      @override
      Widget build(BuildContext context){
        return MaterialApp(
          title:'listView',
          home:Scaffold(
            appBar: AppBar(
              title:Text("listView")
            ),
            // ListView.builder就是动态生成列表
            body:Container(
              child: new ListView.builder(
              //列表生成的长度
                itemCount: items.length,
                itemBuilder: (context,index){
                  return new ListTile(
                    title:new Text('${items[index]}'),
                  );
                },
              ),
            ) 
          ),
        );
      }
    }
  • 相关阅读:
    Why Visual Studio Team System Isn't A LoadRunner Killer[转载]
    从键盘判断电脑主人
    LoadRunner中添加weblogic监视器(JMX)
    winrunner事务概念的代码应用(毫秒级)
    Delphi中的线程类
    换工作时如何提高自身的待遇(转贴)
    牛人是怎样用函数实现本地化测试的
    肯德基的见闻
    由 12306.cn 谈谈网站性能技术
    20个优秀的 CSS 网格系统(CSS Grid Systems)推荐
  • 原文地址:https://www.cnblogs.com/lxz-blogs/p/13224238.html
Copyright © 2020-2023  润新知