第4章常用组件-长列表组件

防采集标记:亢少军老师的课程和资料

import 'package:flutter/material.dart';

void main() => runApp(new MyApp(
  //使用generate方法产生500条数据
  items: new List.generate(500, (i) => "Item $i"),
));

class MyApp extends StatelessWidget {

  //列表数据集
  final List items;

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

  @override
  Widget build(BuildContext context) {
    final title = "长列表示例";

    return MaterialApp(
      title: title,
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text(title),
        ),
        //使用ListView.builder来构造列表项
        body: new ListView.builder(
          //列表长度
          itemCount: items.length,
          //列表项构造器
          itemBuilder: (context,index) {
            return new ListTile(
              leading: new Icon(Icons.phone),
              title: new Text('${items[index]}'),
            );
          },
        ),
      ),
    );
  }
}

@作者: 亢少军

第4章常用组件-长列表组件