fetch_result_bloc 1.1.0
fetch_result_bloc: ^1.1.0 copied to clipboard
Abstract BLoC/Cubit components for simplified data fetching and state management.
A Dart package providing FetchResultBloc
and FetchResultCubit
to simplify
managing states for asynchronous data fetching operations.
Features #
- ✨ Simplifies state management for asynchronous data fetching operations.
- 🧱 Provides
FetchResultBloc
for event-driven state management. - 🧊 Offers
FetchResultCubit
for simpler, direct state management. - 🚦 Clearly defines states for loading, success (with data), and error (with details).
Getting started #
- Add dependency: Add
fetch_result_bloc
to yourpubspec.yaml
:dependencies: fetch_result_bloc: ^1.0.0 # Replace with the latest version
- Install: Run
dart pub get
orflutter pub get
. - Import: Import the package in your Dart code:
import 'package:fetch_result_bloc/fetch_result_bloc.dart';
Usage #
Here's a basic example of using FetchResultCubit
to fetch a value:
import 'package:fetch_result_bloc/fetch_result_bloc.dart';
import 'package:result_flow/result_flow.dart';
// Define your Cubit
class CounterCubit extends FetchResultCubit<int, void> {
CounterCubit() : super(const FetchResultStateInitial());
@override
Future<void> fetch({void param}) => super.fetch(param: null);
@override
FutureResult<int> getResult({void param}) async {
await Future.delayed(const Duration(seconds: 1));
return Result.success(42);
}
}
void main() async {
final cubit = CounterCubit();
cubit.stream.listen(print);
// call fetch when required
await cubit.fetch();
await Future.delayed(const Duration(seconds: 2));
cubit.close();
}
For more detailed examples, including FetchResultBloc
usage please see the /example
folder.
Related Packages #
fetch_result_bloc
is built on top of result_flow
to simplify asynchronous fetch operations ins a safe way
Package | Pub.dev Link |
---|---|
fetch_result_bloc |
|
result_flow |
|
result_flow_dio |