问题描述
我有两个提供程序,并且我使用了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 (将#修改为@)