import 'package:flutter/material.dart';
// class OnlineRepairs extends StatelessWidget{
// @override
// Widget build(BuildContext context) {
// // TODO: implement build
// return Example();
// }
// // @override
// // _ExampleState createState() => _ExampleState();
// }
class OnlineRepairs extends StatefulWidget{
_ExampleState createState() => new _ExampleState();
}
class _ExampleState extends State<OnlineRepairs> {
List formList;
initState() {
super.initState();
formList = [
{"title": '车牌号'},
{"title": '所有人'},
{"title": '号牌颜色'},
];
}
Widget buildGrid() {
List<Widget> tiles = [];//先建一个数组用于存放循环生成的widget
Widget content; //单独一个widget组件,用于返回需要生成的内容widget
for(var item in formList) {
tiles.add(
new Row(
children: <Widget>[
new Text(item['title'])
]
)
);
}
content = new Column(
children: tiles //重点在这里,因为用编辑器写Column生成的children后面会跟一个<Widget>[],
//此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误,把<Widget>[]删了就可以了
);
return content;
}
// Widget ExampleWidget = buildGrid();
@override
Widget build(BuildContext context) {
return Scaffold(
// key: scaffoldKey,
appBar: AppBar(
title: Text('循环渲染组件案例'),
),
body:ListView(
children: [
buildGrid(),
Text("dd")
],
)
// body: new Center(
// child: buildGrid()
// )
);
}
}