티스토리 뷰
When are providers initialized?
All Riverpod providers are lazy-loaded. (링크)
- The provider's state is initailized when the first listener is registered
- Every time the state changes, all listeners will be notified so they can update/rebuild themselves
Both ref.watch() and ref.listen() can be used to register as a listener to a provider. This is in contrast with ref.read(), which only does a one-time read and does not register a listener.
When and how do they get disposed?
If we declare a provider without autoDispose, its state will remain alive until the enclosing ProviderScope is disposed (unless we explicitly dispose it in some other way)
If we declare a provider with autoDispose, its state will be disposed as soon as the last listener is removed(typically when the widget is unmounted)
Providers are auto-disposed by default if we use the @riverpod syntax, meaning that we don't keep the state once it's no longer needed
Provider Lifecycle Callbacks?
- ref.onDispose: triggered right before the porvider is desroyed
- ref.onCancel: triggered when the last listener of the provider is removed
- ref.onResume: triggered when a provider is listened again after it was paused
- ref.onAddListener: triggered whenever a new listener is added to the provider
- ref.onRemoveListener: triggered whenever a newlistener is removed from the provider
'Dart & Flutter > Widget & Package' 카테고리의 다른 글
앱 시작 시 필요한 변수나 초기 값들을 로딩하는 프로세스 구현 방법 (0) | 2025.03.17 |
---|---|
Deferred Components (0) | 2023.03.20 |
카메라 사용하기 (0) | 2023.02.16 |
iOS 와 안드로이드에서의 파일 저장 위치 (0) | 2023.02.08 |
month의 week number를 계산하는 extention (0) | 2022.08.09 |
- Total
- Today
- Yesterday
- IOS
- Chrome
- 플러터
- hide
- Bluetooth
- TextFormField
- error
- 디자인
- 크롬
- 인사이트
- 앱
- 앱개발
- UI
- Flutter
- Syncfusion
- plugin
- 에러
- DART
- firebase
- BLE
- 한빛미디어
- TextField
- UX
- position
- 문제 해결
- 다트
- SizedBox
- addPostFrameCallback
- 이미지
- 앱 프로그래밍
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |