1.列表的内容是String类型的
image.pngclass Home extends StatelessWidget {
List<String> datas = ["文本一", "文本二", "文本三"];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"列表",
style: TextStyle(fontSize: 20, color: Colors.amber),
),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: datas.map((data) {
return Text(data);
}).toList(),
),
),
);
}
}
2.列表的内容是对象类型的
image.pngDatasBean
class DatasBean{
String name;
int age;
DatasBean(this.name, this.age);
}
import 'package:flutter/material.dart';
import 'DatasBean.dart';
void main() => runApp(MaterialApp(
//第二步
home: Home(),
));
class Home extends StatelessWidget {
List<DatasBean> datas = [
DatasBean("张三",23),
DatasBean("李四",24),
DatasBean("王五",25)
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"列表",
style: TextStyle(fontSize: 20, color: Colors.amber),
),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: datas.map((data) {
return Text("${data.name} ${data.age}");
}).toList(),
),
),
);
}
}
网友评论