以前天天写js,突然切换到dart,真不习惯,下面是报错的代码:
import 'package:flutter/material.dart';
import './ClockWidget.dart';
import './ControlWidget.dart';
import './MusicWidget.dart';
import './TestScrollNotification.dart';
class MyHomePage extends StatefulWidget {
final String title;
MyHomePage({this.title});
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int num = 0;
List<Map<String, dynamic>> pages = [
{"page": ControlWidget(), "icon": Icon(Icons.settings), "title": "控制台"},
{"page": ColockWidget(), "icon": Icon(Icons.settings), "title": "时钟列表"},
{"page": MusickWidget(), "icon": Icon(Icons.settings), "title": "音乐控制"},
{
"page": TestScrollNotification(),
"icon": Icon(Icons.settings),
"title": "测试页面"
}
];
void showPage(int n) {
setState(() {
num = n;
print(num);
});
}
List<Widget> renderList(
int num, List<Map<String, dynamic>> data, Function showPage) {
List<Widget> list = [];
for (var i = 0; i < data.length; i++) {
print(data[i]['icon']);
list.add(ListTile(
tileColor: num == i ? Colors.blue : null,
leading: data[i]['icon'],
title: Text(data[i]['title']),
trailing: new Icon(Icons.arrow_forward_ios),
onTap: () => {showPage(i)},
));
}
return list;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("标准时钟系统")),
body: Row(
children: [
Container(
width: 200,
child: ListView(children: renderList(num, pages, showPage)),
),
// Expanded(flex: 1, child: pages[num])
],
));
}
}
报错信息如图:
我按字面翻译说是动态List不是 静态List<Map<String, dynamic>> 的子类型 所以不太明白,万望朋友们帮忙解惑,万分感激
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…