- 我正在尝试在 IconData 和 Icon Color 中添加 switch case 语句,当我使用它们时会抛出一些错误
- 必须先分配不可为空的局部变量“iconData”,然后才能使用它。尝试给它一个初始化表达式,或者确保在每个执行路径上都分配了它
TodoAddPage.dart
class TodoCardPage extends StatefulWidget { const TodoCardPage({ Key? key, required this.title, required this.iconData, required this.iconColor, }) : super(key: key); final String title; final IconData iconData; final Color iconColor;
在主页我尝试使用 homePage.dart
ListView.builder(
itemCount: (snapshot.data! as QuerySnapshot).docs.length,
itemBuilder: (context, index) {
IconData iconData;
Color iconColor;
Map<String, dynamic> document =
(snapshot.data! as QuerySnapshot).docs[index].data()
as Map<String, dynamic>;
return TodoCardPage(
title: document["title"] == null
? "Hey There"
: document["title"],
iconData: iconData,
iconColor: iconColor,
time: "10 PM",
value: true,
iconBgColor: Colors.white);
});