ຕິດຕັ້ງ miniriverpod ໃນບໍ່ກີ່ນາທີ.

ເຄື່ອງມືຈັດການ state ສະໄຕລ໌ Riverpod ທີ່ບາງໆ ມີ core ໃນໄຟລ໌ດຽວ ແລະ binding Flutter ທີ່ເບົາ.

ຂໍ້ກໍານົດ

ກວດໃຫ້ແນ່ໃຈວ່າໂຄງການຂອງທ່ານມີ SDK ແລະ Flutter ເວີຊັນຕາມຂໍ້ກໍານົດ.

Dart SDK

>=3.10.0 <4.0.0

Flutter

>=3.38.0

ເຄັດລັບ

ຖ້າກໍາລັງອັບເກຣດໂຄງການເກົ່າ, ອັບເດດ SDK constraints ກ່ອນຮັນຄໍາສັ່ງຕິດຕັ້ງ.

ການຕິດຕັ້ງ

ເພີ່ມ package ຜ່ານ Flutter CLI ຫຼື ແກ້ pubspec ດ້ວຍຕົນເອງ.

CLI

flutter pub add miniriverpod

pubspec.yaml

# Add to your dependencies
dependencies:
  miniriverpod: ^0.0.1

ຂັ້ນຕອນທໍາອິດ

ເຊື່ອມ ProviderScope, ກໍານົດ Provider, ແລະ watch ຈາກ 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, subscribe ດ້ວຍ WidgetRef.watch(provider).

ຂັ້ນຕອນຕໍ່ໄປ

ຄູ່ມືການໃຊ້

ຮຽນຮູ້ວ່າເປັນຫຍັງ miniriverpod ຈຶ່ງໃຫ້ຄວາມຮູ້ສຶກຄ້າຍ Riverpod ແຕ່ເບົາກວ່າ.

ເປີດຄູ່ມື

GitHub

ເບິ່ງ source, changelog, ແລະ sample ໃນ repo.

ເປີດ GitHub

API Reference

Quickly lookup methods such as invalidate, refreshValue, keepAlive, and invoke.

Open API Reference