無需 Code Gen
撰寫標準 Dart 類別與 provider,不需要 build_runner。
輕量
體積小於 50KB,適合效能敏感的應用。
熟悉的 API
直接取材自 Riverpod 優雅的狀態讀取語法。
第一步
數分鐘內將 miniriverpod 整合到 Flutter 專案。
安裝
flutter pub add miniriverpod
使用指南
user_provider.dart
import 'package:flutter/widgets.dart';
import 'package:miniriverpod/miniriverpod.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')),
);
}
}
重要提醒
不同於原版 Riverpod, miniriverpod 專注於 Flutter 應用,不支援純 Dart 專案,因此移除了 70% 內部邏輯以提升效能。