miniriverpod ကို မိနစ်အနည်းငယ်အတွင်း ထည့်သွင်းပါ။
SDK constraints များကို သတ်မှတ်ပြီး၊ package ကို ထည့်သွင်းကာ ProviderScope + WidgetRef.watch တို့ မှန်ကန်စွာ ချိတ်ဆက်ထားကြောင်း အတည်ပြုပါ။
လိုအပ်ချက်များ
Analyzer နှင့် runtime မကိုက်ညီမှုကို ရှောင်ရှားရန် package နှင့် အတူတူသော constraints များကို အသုံးပြုပါ။
Dart SDK
>=3.10.0 <4.0.0
Flutter
အကြံပြုချက်
သင့် app ကို Dart 3.10 အောက်တွင် lock လုပ်ထားပါက ပထမဦးစွာ SDK constraints များကို မြှင့်တင်ပြီး၊ ထို့နောက် flutter pub get ကို run ပါ။
တပ်ဆင်ခြင်း
CLI ဖြင့် ထည့်သွင်းခြင်းကို ဦးစားပေးပြီး၊ ထို့နောက် version ကို package changelog နှင့် ကိုက်ညီအောင် ထိန်းထားပါ။
CLI
pubspec.yaml
# dependencies ထဲသို့ ထည့်ပါ
dependencies:
miniriverpod: ^0.0.2
ပထမအဆင့်များ
သင့် app ကို ProviderScope အတွင်း ထားပြီး Provider ကို သတ်မှတ်ကာ ConsumerWidget မှ state ကို ပြသပါ။
import 'package:flutter/widgets.dart';
import 'package:miniriverpod/miniriverpod.dart';
final counterProvider = Provider<int>((ref) => 0);
void main() {
runApp(const ProviderScope(child: CounterApp()));
}
class CounterApp extends ConsumerWidget {
const CounterApp({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.watch(counterProvider);
return Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Text('$count')),
);
}
}
နောက်တစ်ဆင့်များ
အခြေခံအယူအဆများ
args အခြေပြု provider identity, Scope injection, နှင့် codegen မလိုသော design ရွေးချယ်မှုများကို နားလည်ပါ။
Core Concepts ဖွင့်ရန်Provider များနှင့် ဖတ်ရှုခြင်း
watch/read/listen အပြုအမူနှင့် AsyncProvider refresh ပုံစံများကို လေ့လာပါ။
Providers ဖွင့်ရန်API ကိုးကားချက်
invalidate, refreshValue, keepAlive, invoke စသည့် methods များကို အမြန် ရှာဖွေပါ။
API Reference ဖွင့်ရန်