zoukankan      html  css  js  c++  java
  • listView 动态加载

    代码:
    import 'package:flutter/material.dart';
    void main() => runApp(MyTestApp(

    items:new List<String>.generate(100, (i)=>"计数 $i")
    ));

    class MyTestApp extends StatelessWidget{
    final List<String> items;
    MyTestApp({Key key,@required this.items}) : super (key:key);

    @override
    Widget build(BuildContext context){
    return MaterialApp(
    title: 'Flutter test',
    home: Scaffold(
    appBar: new AppBar(title: new Text('ListView')),
    body: ListView.builder(
    itemCount: items.length,
    itemBuilder: (context,index){
    return new ListTile(
    title: new Text('${items[index]}'),
    );
    },
    ),
    ),
     
    总结:
     

    new ListView.builder(

    itemCount : 集合个数

    itemBuilder : (context,index){//集合类型 可以是文字 图片

    return new ListTitle(

    title : new Text(‘$(items[index])’)//items是传入的集合

    )

    }

    )

     

    );
    }
    }

    在方法体传参

    //100 是元素个数

     i 是每个元素

    传入的是string 类型

    TextApp(

     

    items: new List<String>.gererate(100,(i)=>”计数 $i”)

    ) 

    在方法体中实例化

     

    final List<String> items;

    //构造函数 必须传入一个集合 Key 是固定的 继承super(也构造个原先没有的key)

    TextApp({Key key,@required this.items}):super(key,key);

     
  • 相关阅读:
    linux软件安装
    shell脚本
    ssh密钥登录及远程执行命令
    shell编程
    vi编辑器
    linux入门
    《玩转Bootstrap(JS插件篇)》笔记
    SharePoint BI
    Apache-ActiveMQ transport XmlMessage
    C#操作AD及Exchange Server总结(二)
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12160787.html
Copyright © 2011-2022 走看看