મિનિટોમાં miniriverpod ઇન્સ્ટોલ કરો.
SDK constraints સેટ કરો, પેકેજ ઉમેરો, અને ખાતરી કરો કે ProviderScope + WidgetRef.watch યોગ્ય રીતે જોડાયેલા છે.
આવશ્યકતાઓ
Analyzer અને runtime mismatch ટાળવા માટે package જેવી જ constraints નો ઉપયોગ કરો.
Dart SDK
>=3.10.0 <4.0.0
Flutter
ટીપ
જો તમારો એપ Dart 3.10 કરતા નીચે pinned હોય, તો પહેલા SDK constraints વધારો અને પછી flutter pub get ચલાવો.
ઇન્સ્ટોલેશન
CLI ઇન્સ્ટોલને પ્રાથમિકતા આપો, પછી વર્ઝનને પેકેજ changelog સાથે સુસંગત રાખો.
CLI
pubspec.yaml
# dependencies માં ઉમેરો
dependencies:
miniriverpod: ^0.0.2
પ્રથમ પગલાં
તમારી એપને 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')),
);
}
}
સિંક્રોનસ મૂલ્યો માટે Provider((ref) => ...) નો ઉપયોગ કરો.
Future માટે AsyncProvider<T>((ref) async => ...) અને Stream માટે ref.emit(stream) નો ઉપયોગ કરો.
જ્યારે તમે mutations અમલમાં મૂકશો ત્યારે ref.invoke(provider.method()) પર સ્વિચ કરો.
આગળનાં પગલાં
મૂળભૂત ખ્યાલો
args આધારિત provider ઓળખ, Scope injection, અને no-codegen ડિઝાઇન પસંદગીઓ સમજો.
મૂળભૂત ખ્યાલો ખોલો