如何解决流供应商与扑火中的问题
我有两个提供程序,并且我使用了MultiProvider,ChangeNotifierProvider正常运行,但是StreamProvider的问题是我的示例:
main.dart
class Makani extends StatelessWidget {
@override
Widget build(BuildContext context) {
Db db = Db();
return MultiProvider(
providers: [
StreamProvider(create: (context)=> db.getLocations(),),ChangeNotifierProvider(create: (context) => Model(),],child: MaterialApp(
debugShowCheckedModeBanner: false,home: Directionality(
textDirection: TextDirection.rtl,child: Scaffold(
body: Map(),);
}
}
db.dart
class Db {
FirebaseFirestore locationList =
FirebaseFirestore.instance;
Stream<List<Locations>> getLocations() {
return locationList.collection('locations').snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => Locations.fromFireStore(doc.data()))
.toList());
}
}
location.dart
class Locations{
String title;
String body;
Locations({this.title,this.body});
Locations.fromFireStore(Map<String,dynamic> data)
: title = data['title'],body = data['body'];
}
tile.dart
这里(loc)返回null !!!而且我不知道为什么吗?
class tiles extends StatelessWidget {
@override
Widget build(BuildContext context) {
var loc = Provider.of<List<Locations>>(context);
return Align(
alignment: Alignment.bottomCenter,child: Container(
margin: EdgeInsets.only(bottom: 16.0),height: 140.0,child: Directionality(
textDirection: TextDirection.ltr,child: ScrollablePositionedList.builder(
reverse: true,scrollDirection: Axis.horizontal,itemCount: loc.length,itemScrollController: tilesController,itemBuilder: (context,index) {
addMarker(loc[index]);
return tile(loc[index]);
},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。