安卓——为什么我的小部件的构建方法认为我返回NULL?
发布时间:2022-04-29 19:38:47 226
相关标签: # java# xcode
我不明白为什么这是一个错误。我所有的if/else路径都会返回一些东西,但代码似乎认为有一条路径以NULL结尾?
错误是:
生成时引发了以下_TypeError:类型“Null”不是类型“Widget”的子类型
@override
Widget build(BuildContext context) {
final messageDao = MessageDao(groupIDPath: widget.groupIDPath);
var msg;
return Scaffold(
body: Container(
child: ListView.builder(
itemCount: data?.length ?? 0,
itemBuilder: (context, index) {
return data?.forEach((key, value) { //ERROR POINTS HERE
msg = Message.fromJson(value);
dataList?.add(msg);
if (dataList?[index] == null) {
return Text('dataList[index] is NULL');
} else {
var receivedType = dataList?[index].type.toString();
var receivedUid = dataList?[index].uid.toString();
var receivedTimestamp = dataList?[index].timestamp.toString();
var receivedText = dataList?[index].text.toString();
var receivedFilterID = dataList?[index].filterID.toString();
var receivedM2URL = dataList?[index].m2URL.toString();
if (dataList?[index].type == '1') { //message type 1
return messageDao.m1Widget(receivedType!, receivedUid!, receivedTimestamp!, receivedText!);
} else if (dataList?[index].type == '2') { //message type 2
return messageDao.m2Widget(receivedType!, receivedUid!, receivedTimestamp!, receivedFilterID!, receivedM2URL!);
} else {
return Text('UNKNOWN MESSAGE TYPE!');
}
}
});
}
),
)
);
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报