class ContactsState extends State<Contacts>{ List formList; initState() { super.initState(); formList = [ {"icon": Icon(Icons.alarm),"title": '車牌號'}, {"icon": Icon(Icons.album),"title": '全部人'}, {"icon": Icon(Icons.archive),"title": '號牌顏色'}, ]; } Widget buildGrid() { List<Widget> tiles = [];//先建一個數組用於存放循環生成的widget Widget content; //單獨一個widget組件,用於返回須要生成的內容widget for(var item in formList) { tiles.add( new Row( children: <Widget>[ new Icon(Icons.alarm), new Text(item['title']), ] ) ); } content = new Column( children: tiles //重點在這裏,由於用編輯器寫Column生成的children後面會跟一個<Widget>[], //此時若是咱們直接把生成的tiles放在<Widget>[]中是會報一個類型不匹配的錯誤,把<Widget>[]刪了就能夠了 ); return content; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('循環渲染組件案例'), ), body: new Center( child: buildGrid(), ) ); } }