使用Firebase从存储在变量中的字符串获取文档
这是我的密码使用Firebase从存储在变量中的字符串获取文档,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,这是我的密码 return await Firestore.instance.collection('RestaurantData').getDocuments('this.widget.restaurantName'); 我应该放置什么位置来访问上一个屏幕传递的数据,而不是'this.widget.restaurantName'来接收fluttter中firebase的文档。如果要将数据从一个屏幕传递到另一个屏幕,则可以执行以下操作: 第一屏: class FirstRoute exte
return await Firestore.instance.collection('RestaurantData').getDocuments('this.widget.restaurantName');
我应该放置什么位置来访问上一个屏幕传递的数据,而不是'this.widget.restaurantName'来接收fluttter中firebase的文档。如果要将数据从一个屏幕传递到另一个屏幕,则可以执行以下操作: 第一屏:
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute(resturantName : "Easy Meal")),
);
},
),
),
);
}
}
在这里,我们将resturantName
属性传递给SecondRoute
,然后在下一个屏幕中,您可以执行以下操作:
class SecondRoute extends StatefulWidget {
final String resturantName;
SecondRoute({this.resturantName});
@override
_SecondRouteState createState() => _SecondRouteState();
}
class _SecondRouteState extends State<SecondRoute> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.resturantName),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}
class SecondRoute扩展StatefulWidget{
最终字符串resturantName;
第二条路线({this.resturantName});
@凌驾
_SecondRouteState createState()=>\u SecondRouteState();
}
类_secondroutstate扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.resturantName),
),
正文:中(
孩子:升起按钮(
已按下:(){
Navigator.pop(上下文);
},
child:Text('Go back!'),
),
),
);
}
}
使用
widget.resturantName
您可以在下一个屏幕中访问该值。实际上这正是我想要的Firestore.instance.collection('RestaurantData').document('this.widget.restaurantName').snapshots(),
我已经从上一个屏幕中获取了您试图告诉我的名称。我只是想知道Firebase访问文档的语法要检索文档,那么您必须执行Firestore.instance.collection('RestaurantData').document(this.widget.restaurantName).snapshots()
而不引用this.widget.restaurantName