gpt4 book ai didi

dart - 如何确定我的变量是否应该在扩展 StatefulWidget 或 Starte<> 的类中?

转载 作者:IT王子 更新时间:2023-10-29 06:54:38 25 4
gpt4 key购买 nike

我有一个类 QuizPage extends StatefulWidget,

和另一个类 _QuizPageState extends State< QuizPage>

class QuizPage extends StatefulWidget {
var HERE; // or over there ?
@override
_QuizPageState createState() => _QuizPageState();
}

class _QuizPageState extends State<QuizPage> {
var HERE; // or over there ?
@override
Widget build(BuildContext context) {return Container();}
}

有什么区别?

I'm new to flutter, but I noticed through the examples I encountered that if I want to send anything through the constructor, it has to be in the StatefulWidget and I can access it inside the State by widget.anything

最佳答案

StatefulWidget 中的变量子类不能随时间变化。它们必须声明为 final , 否则你会收到警告。

在这里添加变量应该只为参数完成:与此通信的其他小部件。

State<T>子类在该主题上有更多的自由。这是您应该放置所有内部变量的地方。是否随时间变化。

关于dart - 如何确定我的变量是否应该在扩展 StatefulWidget 或 Starte<> 的类中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52858531/

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