gpt4 book ai didi

firebase - 使用Firebase从存储在变量中的字符串中获取文档

转载 作者:行者123 更新时间:2023-12-03 04:40:06 25 4
gpt4 key购买 nike

这是我的代码

  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!'),
),
),
);
}
}
使用 widget.resturantName,您可以在下一个屏幕中访问该值。

关于firebase - 使用Firebase从存储在变量中的字符串中获取文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63389845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com