问题描述
我正在使用在线布告栏应用程序,我使用以下代码从我的通知Firebase集合中检索通知列表。
viewnotice.dart
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
return StreamBuilder(
stream:UserService(uid: user.uid).userData,builder: (context,snapshot){
if(snapshot.hasData){
User userData=snapshot.data;
Stream getdept(){
if(userData.department=='all'){
return NoticeService().allnotices;
}else{
if(userData.department=='fst'){
return NoticeService().fstnotices;
}else if(userData.department=='cis'){
return NoticeService().cisnotices;
}else if(userData.department=='pst'){
return NoticeService().pstnotices;
}else if(userData.department=='sport'){
return NoticeService().sportnotices;
}else {
return NoticeService().nrnotices;
}
}
}
return StreamProvider<List<Notice>>.value(
value: getdept(),child: Scaffold(
appBar: AppBar(
elevation: 0.0,title: Text('Notices',style: TextStyle(
fontFamily: 'Montserrat',fontWeight: FontWeight.bold,color: Colors.white,),backgroundColor: Colors.blue[800],actions: <Widget>[
IconButton(
icon: Icon(Icons.search,onpressed: (){}
),],body:NoticeList(),);
}else if(snapshot.hasError){
return Text('${snapshot.error}');
}
return CircularProgressIndicator();
});
}
}
这是noticelist.dart,我用来将通知作为列表检索
Widget build(BuildContext context) {
final notices = Provider.of<List<Notice>>(context) ?? [];
return StreamBuilder<List<Notice>>(
stream: NoticeService().allnotices,snapshot) {
if(snapshot.hasData){
return GridView.builder (
itemCount: notices.length,gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 1),// ignore: missing_return
itemBuilder: (context,index){
return ShowNotice(
notice:notices[index]
);
}
);
}else if(snapshot.hasError){
return Text('${snapshot.error}');
}
return CircularProgressIndicator();
}
);
}
}
,但会出现以下错误,并且应用程序屏幕打印type "Timestamp" is not a subtype of typr "String"
。它不显示通知列表。我该怎么解决。
════════ Exception caught by provider ══════════════════════════════════════════
The following assertion was thrown:
An exception was throw by _MapStream<QuerySnapshot,List<Notice>> listened by
StreamProvider<List<Notice>>,but no `catchError` was provided.
Exception:
type 'Timestamp' is not a subtype of type 'String'
══════════════════════════════════════════════════════════════════════════════
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)