-
main.dart
代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp(
items: new List<String>.generate(100, (i)=>"Item1 $i")
// List(1000): 1000条数据 List<String>(): 数组内容必须是 String 类型
));
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: 'Link World!',
home: Scaffold(
appBar: new AppBar(title: new Text('ListView'),),
body: new ListView.builder(
itemCount: items.length,
itemBuilder: (context,index){
return new ListTile(
title: new Text('${items[index]} abc'),
);
},
)
)
);
}
}
【注】:有时候会有缓存问题,需要关闭虚拟机中的软件,重新运行程序
【动态列表】效果展示:
网友评论