reusable_bloc

Creator: coderz1093

Last updated:

0 purchases

reusable_bloc Image
reusable_bloc Images
Add to Cart

Description:

reusable bloc

Generic Refreshable Data Blocs which are easily extendible to fetch data from network
Features #

implement whole bloc by extending the DataBloc class and overriding the fetch data function
implements optionally to refresh the data, calling the fetch the data again
remembers the previous data when on refresh error and rollback to DataLoaded State again
uses Equatable class from equatable package to add comparison of the state class
the fetch data function returns Either<Failure,Data> from dartz package, making it fully compatible with clean-architecture

Getting started #

This generic bloc package is an extended and flexible version from this blog-part1 and blog-part2. If you want to learn bloc as a state machine, head on to this blog.

Usage #
class GreetBloc extends DataBloc<String> {
GreetBloc() : super(DataUninitialized());

@override
Future<Either<Failure, String>> fetchAndParseData<Failure>(
DataState<String> oldState, FetchData event) async{
final p = event.param as GreetFetchParam;
await Future.delayed(Duration(seconds:2)); // network call place holder
return Right(p.name);
}
}


/// [FetchParam] is a class that holds the optional parameters for the [FetchData] event.
class GreetFetchParam extends FetchParam {
final String name;
const GreetFetchParam(this.name);

@override
List<Object?> get props => [name];
}

void main() {
final bloc = GreetBloc();
bloc.add(FetchData<String>(GreetFetchParam('ajeet')));
bloc.stream.listen((event) {
print(event);
});
}
copied to clipboard
Additional information #
You liked this package? then hit a like. I don't want you to buy me a coffee. Just use this package if you feel the need. And if you need a feel... contribute and let's make something better together.

Star this repository
Create a Pull Request with new features
Share this package
Create issues if you find a Bug or want to suggest something

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.

Related Products

More From This Creator