티스토리 뷰
반응형
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' 카테고리의 다른 글
Deferred Components (0) | 2023.03.20 |
---|---|
카메라 사용하기 (0) | 2023.02.16 |
iOS 와 안드로이드에서의 파일 저장 위치 (0) | 2023.02.08 |
month의 week number를 계산하는 extention (0) | 2022.08.09 |
Getx 정리 (0) | 2022.04.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 플러터
- position
- 디자인
- 다트
- addPostFrameCallback
- DART
- firebase
- 에러
- Chrome
- BLE
- error
- IOS
- 크롬
- Bluetooth
- 앱 프로그래밍
- 인사이트
- Flutter
- Syncfusion
- 문제 해결
- 앱
- 이미지
- hide
- UX
- UI
- 한빛미디어
- plugin
- 앱개발
- TextField
- SizedBox
- TextFormField
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함