[英]Flutter widget.snapshot.data vs snapshot.data
I'm confused about widget.snapshot.data["info"]
and snapshot.data["info"].
我对widget.snapshot.data["info"]
和snapshot.data["info"].
感到困惑snapshot.data["info"].
Can anyone explain me this.谁能给我解释一下。
widget.snapshot.data["info"] should be used when a StatefulWidget is used and the snapshot is from the StatefulWidget当使用StatefulWidget并且快照来自StatefulWidget时,应使用 widget.snapshot.data["info"]
Example例子
class ViewDocuments extends StatefulWidget {
DocumentSnapshot snapshot;
ViewDocuments(this.snapshot);
@override
_ViewDocumentsState createState() => _ViewDocumentsState();
}
class _ViewDocumentsState extends State<ViewDocuments> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("${widget.snapshot.data["info"]}"),
),
);
}
}
Basically you use widget.--- to access fields in a StatefulWidget class State, it is a way for a StatefulWidget and its State to communicate基本上你使用widget.---来访问StatefulWidget类State中的字段,这是StatefulWidget和它的State进行通信的一种方式
For snapshot.data["info"] , it should be used in StatelessWidget since it doesn't have a State对于snapshot.data["info"] ,它应该在StatelessWidget 中使用,因为它没有状态
For Example例如
class ViewDocuments extends StatelessWidget {
DocumentSnapshot snapshot;
ViewDocuments(this.snapshot);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("${snapshot.data["info"]}"),
),
);
}
}
I hope this helps you.我希望这可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.