flutter_bloc_page 1.0.0 copy "flutter_bloc_page: ^1.0.0" to clipboard
flutter_bloc_page: ^1.0.0 copied to clipboard

Helper package for creating Bloc for controlling one UI Page.

Helper package for creating Bloc for controlling one UI Page.

Features #

Build on top of flutter_bloc BlocConsumer widget, flutter_bloc_page provides better separation between UI state and UI event.

UI state will be last until bloc emit a new state.

While UI event (e.g. show snackbar, show dialog, open another page) should be handled only once.

Getting started #

Pubspec #

dependencies:
  flutter_bloc_page: ^1.0.0

Usage #

When create a page, define UiEvent class to represent event that can happen.

Let say it will be 2 events: showDialog and openAnotherPage. You can define UiEvent class like this.

sealed class UiEvent {}

class ShowDialog extends UiEvent {
  // Fields
}

class OpenAnotherPage extends UiEvent {
  // Fields
}

Note Avoid having const constructor in UiEvent class. PageBlocConsumer uses identical for checking arrival of new UiEvent.

Create a Bloc with state of type PageBlocState. Implement your Bloc logic as normal bloc.

class YourBloc extends Bloc<Event, PageBlocState<UiEvent, UiState>> {
  // Your implementation
}

Now you can use PageBlocConsumer:

PageBlocConsumer<YourBloc, UiEvent, UiState>
(
uiEventListener: (context, uiEvent) async {
// Handle UiEvent
},
uiBuilder: (context, uiState) {
// Build your widget from UiState  
}
);
0
likes
0
pub points
38%
popularity

Publisher

unverified uploader

Helper package for creating Bloc for controlling one UI Page.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

equatable, flutter, flutter_bloc, nullable_absent

More

Packages that depend on flutter_bloc_page