flutter学习笔记-MVVM模式学习解决报错

最近学习flutter,进行mvvm模式学习的时候,报了一错:

[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Error: Could not find the correct Provider<MvvmDemoViewmodel> above this MvvmDemoView Widget
This happens because you used a `BuildContext` that does not include the provider
of your choice. There are a few common scenarios:
- You added a new provider in your `main.dart` and performed a hot-reload.
  To fix, perform a hot-restart.
- The provider you are trying to read is in a different route.
  Providers are "scoped". So if you insert of provider inside a route, then
  other routes will not be able to access that provider.
- You used a `BuildContext` that is an ancestor of the provider you are trying to read.
  Make sure that MvvmDemoView is under your MultiProvider/Provider<MvvmDemoViewmodel>.
  This usually happens when you are creating a provider and trying to read it immediately.
  For example, instead of:
  Widget build(BuildContext context) {
    return Provider<Example>(
      create: (_) => Example(),
      // Will throw a P<…>

网上说的方法都试了,没丁点儿用,该报错还是报错。
后面我一步一步的看,终于:
在这里插入图片描述
原来是引的包,一个字母大写了。

所以大家如果遇到和我一样的错误,一定要先检查一下,包的引入对不对,以免走弯路。

以此为鉴,没有下次。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值