မိနစ်ပိုင်းအတွင်း miniriverpod ကို တပ်ဆင်ပါ။
single-file core နှင့် သက်သာသော Flutter binding ပါဝင်သည့် Riverpod-style state management toolkit.
လိုအပ်ချက်များ
သင့်ပရောဂျက်သည် အနည်းဆုံး SDK နှင့် Flutter ဗားရှင်းများကို ကိုက်ညီသေချာပါစေ။
Dart SDK
>=3.10.0 <4.0.0
Flutter
>=3.38.0
အကြံပြုချက်
ရှိပြီးသား ပရောဂျက်ကို အပ်ဒိတ်လုပ်နေပါက တပ်ဆင်အမိန့်ကို မလုပ်ခင် SDK constraints များကို အပ်ဒိတ်လုပ်ပါ။
တပ်ဆင်ခြင်း
Flutter CLI ဖြင့် ပက်ကေ့ချ်ကို ထည့်ပါ သို့မဟုတ် pubspec ကို လက်ဖြင့် ပြင်ပါ။
CLI
flutter pub add miniriverpod
pubspec.yaml
# Add to your dependencies
dependencies:
miniriverpod: ^0.0.1
ပထမဆုံး အဆင့်များ
ProviderScope ကို ချိတ်ဆက်ပြီး Provider ကို သတ်မှတ်ကာ UI မှ စောင့်ကြည့်ပါ။
main.dart
// 1) Wrap your app with ProviderScope
void main() {
runApp(
const ProviderScope(
child: MyApp(),
),
);
}
// 2) Define a Provider
final counterProvider = Provider<int>((ref) => 0);
// 3) Watch from UI
class MyApp extends ConsumerWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.watch(counterProvider);
return Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Text('$count')),
);
}
}
Provider((ref) => ...) သည် synchronous ဖြစ်သည်။
AsyncProvider<T>((ref) async => ...) သည် Future သို့မဟုတ် Stream ကို စီမံပေးသည်။
UI မှ WidgetRef.watch(provider) ဖြင့် subscribe လုပ်ပါ။
နောက်တစ်ဆင့်များ
အသုံးပြုမှုလမ်းညွှန်
miniriverpod သည် Riverpod ကဲ့သို့ ခံစားရသော်လည်း အလေးချိန်နည်းကြောင်း လေ့လာပါ။
လမ်းညွှန် ဖွင့်ရန်API Reference
Quickly lookup methods such as invalidate, refreshValue, keepAlive, and invoke.
Open API Reference