0 purchases
bloc pod
Pod #
⚠️ Status: Experimental
A dependency injection and state management library, fast, simple and composable.
Inspired by Riverpod and Jōtai
Package
Pub
pod
flutter_pod
bloc_pod
Quick Start #
import 'package:flutter/material.dart';
import 'package:flutter_pod/flutter_pod.dart';
import 'package:bloc_pod/bloc_pod.dart';
/// Counter Events
sealed class CounterEvent {}
final class CounterIncrementPressed extends CounterEvent {}
/// Counter Bloc
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<CounterIncrementPressed>((event, emit) => emit(state + 1));
}
}
/// Create a Bloc Pod
final counterBloc = blocPod<CounterBloc, int>((_) => CounterBloc());
/// Usage of counter bloc in Widget
///
/// Requires add and import flutter_pod
class Example extends StatelessWidget {
@override
Widget build(BuildContext context) {
final counter = context.watch(counterBloc);
return Scaffold(
appBar: AppBar(),
body: Center(
child: Text('$counter'),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
context.read(counterBloc.notifier).add(CounterIncrementPressed());
},
child: const Icon(Icons.add),
),
);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.