
// 색상을 관리하는 뷰모델
class ColorState {
Color color;
ColorState(this.color);
}
class ColorViewModel extends Notifier<ColorState> {
ColorState build() {
return ColorState(Colors.yellow);
}
}
// Notifier는 똑같음
final colorViewModel = NotifierProvider<ColorViewModel, ColorState>(() {
return ColorViewModel();
});
// AutoDisposeNotifier
final colorViewModel2 = NotifierProvider<ColorViewModel, ColorState>(() {
return ColorViewModel();
}, isAutoDispose: true);
//FamilyNotifier
class ColorViewModel2 extends Notifier<ColorState> {
final String pageName;
ColorViewModel2(this.pageName);
ColorState build() {
return ColorState(Colors.yellow);
}
}
final colorViewModel3 =
NotifierProvider.family<ColorViewModel2, ColorState, String>((String arg) {
return ColorViewModel2(arg);
}, isAutoDispose: true);
// true 하면 AutoDisposeFamilyNotifier
// false 하면 FamilyNotifier
패키지 추가
<dict>
*****하단 영역에 입력하기******
<key>NSPhotoLibraryUsageDescription</key>
<String>사진 업로드를 위한 라이브러리 권한을 허용해 주세요</String>
