1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DependencyNotFoundException

Posted at

state_notifier内でLocatorMixinをmixinして、Repositoryを使おうと思ったら、DependencyNotFoundExceptionが出てしまう。
原因MultiProviderにちゃんと定義していても順番が重要ということ(あたりまえだけど)
RepositoryState Notifierより前に書かないといけない

以下のような感じ。

修正前

return MultiProvider(
  providers: [
    StateNotifierProvider<HogeNotifier, HogeState>(create: (context) => HogeNotifier()),
    Provider<InterfaceHogeRepository>(create: (context) => InterfaceHogeRepository()),
  ],
);

修正後

return MultiProvider(
  providers: [
    StateNotifierProvider<HogeNotifier, HogeState>(create: (context) => HogeNotifier()),
    Provider<InterfaceHogeRepository>(create: (context) => InterfaceHogeRepository()),
  ],
);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?