miniriverpod काही मिनिटांत इंस्टॉल करा.
SDK constraints सेट करा, package जोडा, आणि ProviderScope + WidgetRef.watch योग्यरीत्या जोडले आहेत याची खात्री करा.
आवश्यकता
Analyzer आणि runtime mismatch टाळण्यासाठी package प्रमाणेच constraints वापरा.
Dart SDK
>=3.10.0 <4.0.0
Flutter
टीप
जर तुमचे app Dart 3.10 खाली pin झाले असेल, तर आधी SDK constraints वाढवा, मग flutter pub get चालवा.
इंस्टॉलेशन
CLI install पसंत करा, आणि नंतर version package changelog शी जुळवून ठेवा.
CLI
pubspec.yaml
# Add to dependencies
dependencies:
miniriverpod: ^0.0.2
पहिले पाऊल
तुमचे ॲप ProviderScope मध्ये wrap करा, Provider परिभाषित करा, आणि ConsumerWidget मधून state render करा.
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 identity, Scope injection, आणि no-codegen design choices समजून घ्या.
मुख्य संकल्पना उघडाAPI संदर्भ
invalidate, refreshValue, keepAlive, आणि invoke यांसारख्या पद्धती पटकन शोधा.
API संदर्भ उघडा