flutter_value_bloc 1.3.0-dev flutter_value_bloc: ^1.3.0-dev copied to clipboard
Flutter Widgets that make it easy to implement the ValueBloc for list, table and more.
flutter_value_bloc #
GitHub | pub.dev |
---|---|
value_bloc | value_bloc |
flutter_value_bloc | flutter_value_bloc |
Getting Started #
Create your ui in just a few taps
- Wrap your
MaterialApp
with ViewsProviders to allow your Cubits to auto build loading, empty and error views
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ViewsProvider.value(
value: Views(),
child: CubitViewsProvider.value(
value: CubitViews(),
child: MaterialApp(
home: HomeScreen(),
),
),
);
}
}
- Define your own screen block
- If you need to load data mix it with
LoadCubitModule
- If you need to close of the cubits you can mix
CloserCubitModule
- If you need to close of the stream subscriptions you can mix
CloserStreamSubscriptionModule
class HomeScreenCubit extends ModularCubit<State> with LoadCubitModule {
HomeScreenCubit();
void onLoading() {
// write your code for initializing bloc
emitLoading();
}
}
- Build your screen view.
- Use ModularViewCubitBuilder to make the ui show the loader until the cubit is loaded or has failed to load
class HomeScreen extends StatelessWidget {
const HomeScreen({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => HomeScreenCubit(),
child: Scaffold(
appBar: AppBar(),
body: ModularViewCubitBuilder<HomeScreenCubit, State>(
builder: (context, state) {
final screenCubit = BlocProvider.of<HomeScreenCubit>(context);
return Text('...');
},
),
),
);
}
}
- I add other cubits such as:
ValueCubit
Manage a single valueSingleCubit
Fetch and manage a single valueListCubit
Manage a list valuesSetCubit
Manage a set valuesMultiCubit
Fetch and manage paginated values
class HomeScreenCubit extends ModularCubit<State> with LoadCubitModule, CloseCubitModule {
final userCubit = ValueCubit<Person, Object>();
HomeScreenCubit() {
userCubit.addToCloserCubit(this);
}
void onLoading() async {
// A very long operation
await Future.delay(Duration(seconds: 1));
userCubit.updateValue(User('Piero'));
emitLoading();
}
}
- Build your graphics however you like
Widget build(BuildContext context) {
return ViewCubitBuilder<Person>(
objectCubit: screenCubit.userCubit,
builder: (context, user) {
return Text(user.name);
},
);
}