Dart & Flutter/궁금했던 것, 몰랐던 것

Riverpod 을 자동생성기로 생성할 때 State Provider 는 지원하지 않음

낭초비 2024. 7. 26. 13:52
반응형

기존에 작성한 코드에서 Riverpod 의 StateProvider 를 이용한 것이 있는데, 이 코드를 Riverpod Generator 를 활용하는 코드로 migration 하려고 보았더니 Generator 에서는 State Provider는 지원하지 않는다. 

 

어떤 질문자가 아래와 같이 문의를 했는데, 

 

레미의 답변은

 

제네레이터에서 StateProvider 같은 것을 추가할 계획은 아직 없고,

사용할 State를 Class 로 선언하고 이 클래스를 이용하여 Notifier 로 프로바이더를 만들어야 한다고 한다. 간단한 예제는 아래 링크에서 참고하면된다 

https://codewithandrea.com/articles/flutter-riverpod-async-notifier/#notifier-with-riverpod-generator

 

How to use Notifier and AsyncNotifier with the new Flutter Riverpod Generator

A step-by-step guide showing how to migrate StateProvider and StateNotifier to the new Notifier and AsyncNotifier classes (StreamNotifier is covered too).

codewithandrea.com

 

 

 

출처: https://github.com/rrousselGit/riverpod/discussions/1725

반응형