နေ့စဉ်အလုပ်အတွက် API ကို အမြန်ရှာဖွေပါ။
ဤစာမျက်နှာသည် miniriverpod_core.dart နှင့် miniriverpod_flutter.dart မှ အသုံးများသော classes နှင့် methods များကို အကျဉ်းချုပ် ဖော်ပြထားသည်။
အဓိက အမျိုးအစားများ
အဓိက state နှင့် provider primitives များ။
AsyncValue<T>
AsyncLoading / AsyncData / AsyncError
Provider<T>
ရွေးချယ်နိုင်သော autoDispose ပါရှိသည့် synchronous provider
AsyncProvider<T>
.future selector ပါရှိသော asynchronous provider
ဖတ်ရှုရန် အကြံ
AsyncValue တွင် when method မပါဝင်ပါ။ switch pattern matching သို့မဟုတ် is checks ကို သုံးပါ။
Ref နှင့် ProviderContainer ၏ နည်းလမ်းများ
refresh, invalidation, lifecycle, နှင့် mutation execution အတွက် ပုံမှန် လုပ်ဆောင်မှု နည်းလမ်းများ။
အသုံးများသော အစီအစဉ်
နည်းလမ်းမြေပုံ
read / watch / listen : providers ကို ဖတ်၍ subscribe လုပ်ပါ။
invalidate / refresh / refreshValue : state ကို ပြန်တွက်ပါ။
onDispose / keepAlive / emit : lifecycle နှင့် stream ချိတ်ဆက်မှု။
mutation / mutate / invoke : ခြေရာခံထားသော write operations ။
scope / overrideWithValue : DI နှင့် testing overrides ။
Flutter API အမြန်မြင်ကွင်း
အက်ပ်ကုဒ်တွင် သုံးသော ProviderScope နှင့် WidgetRef ၏ entry point များ။
// Scope
ProviderScope(
child: const App(),
);
// ConsumerWidget
class Header extends ConsumerWidget {
const Header({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final user = ref.watch(currentUser);
return Text('$user');
}
}
// Mutation execution
await ref.invoke(userProvider.rename('Alice'));
နောက်ထပ် အဆင့်များ
Providers
Provider, AsyncProvider, နှင့် read APIs ၏ လက်တွေ့အသုံးပြုမှုသို့ ပြန်သွားပါ။
Providers ကို ဖွင့်ရန်Mutations
concurrency control ဖြင့် ရှင်းလင်းသော write flows များကို အကောင်အထည်ဖော်ပါ။
Mutations ကို ဖွင့်ရန်