flutter class小部件“观看”功能有错误

发布于 2025-02-04 08:22:21 字数 305 浏览 3 评论 0原文

我想通过手表函数制作一个var,但是它不断发生和错误,这是代码:

class Booking extends ConsumerWidget {
  @override
  Widget build(BuildContext context, watch) {
    var step = watch(currentStep).state;
    var mallWatch = watch(selectedMall).state;

var内部的“手表”继续获得红色下划线,错误是“表达式未评估到功能,所以无法调用“请帮忙,谢谢

I want to make a var with watch function, but it keep getting and error this is the code :

class Booking extends ConsumerWidget {
  @override
  Widget build(BuildContext context, watch) {
    var step = watch(currentStep).state;
    var mallWatch = watch(selectedMall).state;

the "watch" inside the var keep getting a red underline, the error is "The expression doesn't evaluate to a function, so it can't be invoked" please help, thank you

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

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

发布评论

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

评论(1

晨与橙与城 2025-02-11 08:22:22

通过

class Booking extends ConsumerWidget {
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // not sure .state is necessary, depends on what you're trying to retrieve
    var step = ref.watch(currentStep).state;
    var mallWatch = watch(selectedMall).state;
    ...
  }
}

Skimmed through Riverpod docs and apparently your code should be:

class Booking extends ConsumerWidget {
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // not sure .state is necessary, depends on what you're trying to retrieve
    var step = ref.watch(currentStep).state;
    var mallWatch = watch(selectedMall).state;
    ...
  }
}

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