Cubit仅适用于无状态小部件吗?

发布于 2025-01-31 08:48:17 字数 438 浏览 5 评论 0原文

我正在尝试应用此状态管理,但我无法实施它。如果我使用无状态小部件,我可以轻松地实施它,但是说明它很复杂,我无法实现它。在哪里实施肘?这是我的代码零件=>

class MaintenanceScreen extends StatefulWidget {
  int? locId;
  MaintenanceScreen({required this.locId, Key? key}) : super(key: key);

  @override
  _MaintenanceScreenState createState() => _MaintenanceScreenState();
}

class _MaintenanceScreenState extends State<MaintenanceScreen> {
  final colFr = FrenchColors();

I am trying to apply this state management but i cannot implement it. If I use stateless widget, i can easily implement it but stateful it is complicated and i cannot achieve it. Where to implement cubits? Here is my code part =>

class MaintenanceScreen extends StatefulWidget {
  int? locId;
  MaintenanceScreen({required this.locId, Key? key}) : super(key: key);

  @override
  _MaintenanceScreenState createState() => _MaintenanceScreenState();
}

class _MaintenanceScreenState extends State<MaintenanceScreen> {
  final colFr = FrenchColors();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2025-02-07 08:48:17

如果您是说要访问locid in _MaintenancesCreenstate
简而言之,您可以在构建功能内使用widget.locid,而颤动将与小部件类绑定。

if you mean you want to access locId in _MaintenanceScreenState
simply you can use widget.locId inside the build function and flutter will bind this with the widget class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文