flutter_bloc_wrapper 0.0.1 flutter_bloc_wrapper: ^0.0.1 copied to clipboard
A flutter package that wrap flutter_bloc package for clearer, easy implementation
flutter_bloc_wrapper #
Getting Started #
This package is use to develop app which use Bloc pattern clearer, quicker, easier by wrapping complicated bloc usage.
Usage #
Using ProcessorProvider instead of BlockProvider for providing
+ event processor instance or
+ create processor instance for use in child widget.
Example:
void main() {
runApp(
ProcessorProvider<AuthenticationEventProcessor>(
create: (BuildContext context) => AuthenticationEventProcessor(),
child: const App(),
),
);
}
Implement screen widget
-
Create State extends ScreenDataState class. For ex: LoginScreenState
-
Create Event extends ScreenEvent class. For ex: LoginScreenEvent
-
Create Login screen and implement 4 function
class LoginScreen extends CoreScreen<LoginScreenEvent, LoginScreenState, LoginEventProcessor>
3.1handleDataStateChange
: handle state change after processor handle event and change widget state. For ex: press login button --> process by processor --> processor change state to LoginFailure because of invalid of login data so we want to show Alert dialog for example, do it in this function.if (newState.error != null) { showAlertDialog(context, Text(state.error.message)); }
3.2
createEventProcessor(State state)
: returnEventToStateProcessor
for use in this widget or its child. For ex just:return LoginEventProcessor(state);
3.3initScreenState
: state of screen when initialif (state.isLoading) LoadingIndicatorWidget() else Container()
3.4buildScreen
: for build screen ui base on data state. For ex: if state isstate.isLoading
is true then show ProgressBar```if (state.isLoading) LoadingIndicatorWidget() else Container()```
3.5 Other 2 method
initScreen
anddisposeScreen
2 call back when init state screen and dispose state of Screen.
Dart Versions #
- Dart 2: >= 2.8.0