presented_bloc library

Cubits, views and view models that are presented as routes, dialogs and bottom sheets, adapted to the design language of the app.

Classes

AdaptiveDataWidget<D>
A DataWidget that builds itself for the design language of the app, see AdaptiveBuild.
AdaptiveWidget
A widget that builds itself for the design language of the app, see AdaptiveBuild.
Allow
Allows the navigation to proceed.
AncestorCubitPresenter<ParentCubit extends Cubit, C extends AncestorFinder<ParentCubit, State>, State>
AppCubit<State extends AppState, RouteSettings extends PresenterSettings>
Manages app-wide state, repositories, navigation and messages.
AppRoutes<C extends AppCubit<AppState, PresenterSettings>, RouteSettings extends PresenterSettings>
The route tree of an app, built by PresentedApp.
AppState
Base state for an application managed by AppCubit.
AppView<Cubit extends AppCubit<State, PresenterSettings>, State extends AppState, ViewModel extends AppViewModel<Cubit, State>>
A reusable view wrapper that binds an AppCubit, AppState, and AppViewModel to a Flutter widget tree.
AppViewModel<C extends AppCubit<State, PresenterSettings>, State extends AppState>
The view model of an AppView, created with its AppCubit.
Bloc<Event, State>
Takes a Stream of Events as input and transforms them into a Stream of States as output.
BlocBase<State>
An interface for the core functionality implemented by both Bloc and Cubit.
BlocBuilder<B extends StateStreamable<S>, S>
BlocBuilder handles building a widget in response to new states. BlocBuilder is analogous to StreamBuilder but has simplified API to reduce the amount of boilerplate code needed as well as bloc-specific performance improvements. Please refer to BlocListener if you want to "do" anything in response to state changes such as navigation, showing a dialog, etc...
BlocBuilderBase<B extends StateStreamable<S>, S>
Base class for widgets that build themselves based on interaction with a specified bloc.
BlocConsumer<B extends StateStreamable<S>, S>
BlocConsumer exposes a builder and listener in order react to new states. BlocConsumer is analogous to a nested BlocListener and BlocBuilder but reduces the amount of boilerplate needed. BlocConsumer should only be used when it is necessary to both rebuild UI and execute other reactions to state changes in the bloc.
BlocEventSink<Event extends Object?>
An ErrorSink that supports adding events.
Block
Blocks the navigation from proceeding.
BlocListener<B extends StateStreamable<S>, S>
Takes a BlocWidgetListener and an optional bloc and invokes the listener in response to state changes in the bloc. It should be used for functionality that needs to occur only in response to a state change such as navigation, showing a SnackBar, showing a Dialog, etc... The listener is guaranteed to only be called once for each state change unlike the builder in BlocBuilder.
BlocListenerBase<B extends StateStreamable<S>, S>
Base class for widgets that listen to state changes in a specified bloc.
BlocObserver
An interface for observing the behavior of Bloc instances.
BlocProvider<T extends StateStreamableSource<Object?>>
Takes a create function that is responsible for creating the Bloc or Cubit and a child which will have access to the instance via BlocProvider.of(context). It is used as a dependency injection (DI) widget so that a single instance of a Bloc or Cubit can be provided to multiple widgets within a subtree.
BlocSelector<B extends StateStreamable<S>, S, T>
BlocSelector is analogous to BlocBuilder but allows developers to filter updates by selecting a new value based on the bloc state. Unnecessary builds are prevented if the selected value does not change.
CancellationToken
Signals that an asynchronous operation is no longer needed, e.g. because a newer request replaced it or its cubit was closed.
Change<State>
A Change represents the change from one State to another. A Change consists of the currentState and nextState.
Closable
An object that must be closed when no longer in use.
Cubit<State>
A Cubit is similar to Bloc but has no notion of events and relies on methods to emit new states.
CubitContentBuilder<C extends PresentedCubit>
Contract for widgets that render content using a cubit.
CubitView<C extends PresentedCubit<State>, State, VM extends ViewModel<State>>
A view that renders a cubit's state through a ViewModel.
CubitViewModel<C extends StateStreamable<State>, State>
A ViewModel with access to its cubit.
CustomParameterCodec
annotation to define a custom parameter decoder/encoder this is useful when the is encoded/decoded in a non-standard way like base64Url this must be used as an annotation on a field
CustomTransitionPage<T>
Page with custom transition functionality.
DataWidget<D>
A widget that shows the content of one data model.
DesignLanguageScope
Provides the DesignLanguage of the app to the widget tree.
Emittable<State extends Object?>
An object that can emit new states.
EmittableStateStreamableSource<State>
A StateStreamableSource that can emit new states.
Emitter<State>
An Emitter is a class which is capable of emitting new states.
ErrorSink
A generic destination for errors.
FocusDetector
Fires callbacks every time the widget appears or disappears from the screen.
FocusDetectorState
GoRoute Get started Configuration Redirection Transition animations Named routes
A route that is displayed visually above the matching parent route using the Navigator.
GoRouteData Type-safe routes
A class to represent a GoRoute in Type-safe routing.
GoRouteInformationParser
Converts between incoming URLs and a RouteMatchList using RouteMatcher.
GoRouteInformationProvider
The RouteInformationProvider created by go_router.
GoRouter Get started Upgrading Configuration Navigation Redirection Web Deep linking Named routes Error handling State restoration
The route configuration for the app.
GoRouterDelegate
GoRouter implementation of RouterDelegate.
GoRouterState
The route state during routing.
ImperativeRouteMatch
The route match that represent route pushed through GoRouter.push.
InheritedGoRouter
GoRouter implementation of InheritedWidget.
LogRepository
Optional service for recording errors and diagnostic messages.
MultiBlocListener
Merges multiple BlocListener widgets into one widget tree.
MultiBlocObserver
A BlocObserver which supports registering multiple BlocObserver instances. This is useful when maintaining multiple BlocObserver instances for different functions e.g. LoggingBlocObserver, ErrorReportingBlocObserver.
MultiBlocProvider
Merges multiple BlocProvider widgets into one widget tree.
MultiRepositoryProvider
Merges multiple RepositoryProvider widgets into one widget tree.
NoTransitionPage<T>
Custom transition page with no transition.
OnEnterResult
The result of an onEnter callback.
PresentedApp<C extends AppCubit<S, PresenterSettings>, S extends AppState, V extends CubitView<C, S, VM>, VM extends AppViewModel<C, S>>
The root widget of an app that can be restarted at runtime, e.g. to apply a new design language.
PresentedCubit<State>
A cubit with presentation lifecycle hooks and managed resources.
Presenter<C extends PresentedCubit<State>, State>
Presents a cubit-backed view as a route, dialog, bottom sheet or widget.
PresenterBuilder
Defines the contract for building presentation UI components used by the presented_bloc package.
PresenterDataSource
Inherited access to the metadata of the current presentation.
PresenterDataSourceData
Presentation metadata made available to a presented view subtree.
PresenterDialogSettings
Settings of a dialog, see Presenter.showDialog.
PresenterPageSettings
Settings of a view presented as a page or a plain widget.
PresenterSettings
The name and title of a presented view. Routes usually pass an enum that implements it, see AppRoutes.buildRoute.
PresenterSheetSettings
Settings of a bottom sheet, see Presenter.showBottomSheet.
RelativeGoRouteData Type-safe routes
A class to represent a relative GoRoute in Type-safe routing.
RepositoryEntry<Key, Value>
Registers a service under an explicit lookup key.
RepositoryProvider<T>
Takes a create function that is responsible for creating the repository and a child which will have access to the repository via RepositoryProvider.of(context). It is used as a dependency injection (DI) widget so that a single instance of a repository can be provided to multiple widgets within a subtree.
RestoredNavigation
The navigation stack of a GoRouter, saved so it can be rebuilt on a new router after the app tree was restarted.
RouteBase
The base class for GoRoute and ShellRoute.
RouteBuilder
Builds the top-level Navigator for GoRouter.
RouteConfiguration
The route configuration for GoRouter configured by the app.
RouteData
Baseclass for supporting Type-safe routing.
RouteInformationState<T>
The data class to be stored in RouteInformation.state to be used by GoRouteInformationParser.
RouteMatch
An matched result by matching a GoRoute against a location.
RouteMatchBase
The base class for various route matches.
RouteMatchList
The list of RouteMatchBase objects.
RoutingConfig Configuration
A set of parameters that defines routing in GoRouter.
ShellRoute Configuration
A route that displays a UI shell around the matching child route.
ShellRouteBase
Base class for classes that act as shells for sub-routes, such as ShellRoute and StatefulShellRoute.
ShellRouteContext
Context object used when building the shell and Navigator for a shell route.
ShellRouteData
A class to represent a ShellRoute in Type-safe routing.
ShellRouteMatch
An matched result by matching a ShellRoute against a location.
StatefulNavigationShell
Widget for managing the state of a StatefulShellRoute.
StatefulNavigationShellState
State for StatefulNavigationShell.
StatefulShellBranch
Representation of a separate branch in a stateful navigation tree, used to configure StatefulShellRoute.
StatefulShellBranchData
Base class for supporting StatefulShellRoute
StatefulShellRoute Configuration
A route that displays a UI shell with separate Navigators for its sub-routes.
StatefulShellRouteData
Base class for supporting StatefulShellRoute
StateStreamable<State>
A Streamable that provides synchronous access to the current state.
StateStreamableSource<State>
A StateStreamable that must be closed when no longer in use.
Streamable<State extends Object?>
An object that provides access to a stream of states over time.
TrackingEvent
An event associated with a presented view.
TrackingRepository
Optional service for presentation and error analytics.
Transition<Event, State>
A Transition is the change from one state to another. Consists of the currentState, an event, and the nextState.
TypedGoRoute<T extends GoRouteData>
A superclass for each typed go route descendant
TypedQueryParameter<T>
Annotation to override the URI name for a route parameter.
TypedRelativeGoRoute<T extends RelativeGoRouteData>
A superclass for each typed relative go route descendant
TypedRoute<T extends RouteData>
A superclass for each typed route descendant
TypedShellRoute<T extends ShellRouteData>
A superclass for each typed shell route descendant
TypedStatefulShellBranch<T extends StatefulShellBranchData>
A superclass for each typed shell route descendant
TypedStatefulShellRoute<T extends StatefulShellRouteData>
A superclass for each typed shell route descendant
ViewModel<State>
Formats the state of a view for display.
WaitingObjectState<WaitingObject extends Enum>
State contract for cubits that expose asynchronous waiting indicators.

Enums

DesignLanguage
The design language (visual style) of the application.
MessageType
The kind of a message shown with AppCubit.showMessage, with the icon and colors of its Material SnackBar.
The type of the navigation.
OperatingSystem
An operating system on which the app is running.
PresenterDataSourceType
The way a view is currently being presented.

Mixins

AdaptiveBuild
Builds a widget for the design language of the app.
AncestorFinder<ParentCubit extends Cubit, State>
Mixin providing parent cubit management and retrieval utilities for PresentedCubit. Enables access to parent cubits, navigation context, and application-level cubit. Supports recursive cubit lookup, parent provider creation, event tracking, and parent cubit watching for state management and dependency injection.
ParentAwareWatch<Cubit extends AncestorFinder>
Mixin for building widgets that automatically watch a Cubit and its parent cubit.
WaitFor<WaitingObject extends Enum, State extends WaitingObjectState<WaitingObject>, ParentCubit extends Cubit>
Offers methods to handle waiting objects, emit state changes, and manage error handling, logging, and error presentation. Supports cancellation of previous requests and custom error handling logic.
Watch<Cubit extends PresentedCubit>
Mixin for building widgets that automatically watch a Cubit
WatchAll<Cubit extends AncestorFinder>
Mixin for building widgets that automatically watch a Cubit and its parent cubits.

Extensions

AdaptiveDesignLanguage on DesignLanguage
AppPresenter on Presenter<C, State>
DesignLanguageContext on BuildContext
GoRouterHelper on BuildContext
Dart extension to add navigation function to a BuildContext object, e.g. context.go('/');
ReadContext on BuildContext
Exposes the read method.
RouteCubitContext on BuildContext
SelectContext on BuildContext
Adds a select method on BuildContext.
WatchContext on BuildContext
Exposes the watch method.

Functions

selectPlatform({void onError(Object, StackTrace)?, void web(DesignLanguage defaultDesignLanguage)?, void android(DesignLanguage defaultDesignLanguage)?, void ios(DesignLanguage defaultDesignLanguage)?, void macos(DesignLanguage defaultDesignLanguage)?, void windows(DesignLanguage defaultDesignLanguage)?, void linux(DesignLanguage defaultDesignLanguage)?, void fallback(DesignLanguage defaultDesignLanguage)?, ZoneSpecification? zoneSpecification, Map<Object?, Object?>? zoneValues}) → void
Runs the provided callback based on the current operating system.

Typedefs

AppCubitFactory<C, State> = C Function(State initialState, RestoredNavigation? restoredNavigation)
Creates the AppCubit of a PresentedApp.
AppRoutesFactory<C extends AppCubit<AppState, PresenterSettings>> = AppRoutes<C, PresenterSettings> Function(C app)
Creates the AppRoutes of a PresentedApp for an AppCubit.
BlocBuilderCondition<S> = bool Function(S previous, S current)
Signature for the buildWhen function which takes the previous state and the current state and is responsible for returning a bool which determines whether to rebuild BlocBuilder with the current state.
BlocListenerCondition<S> = bool Function(S previous, S current)
Signature for the listenWhen function which takes the previous state and the current state and is responsible for returning a bool which determines whether or not to call BlocWidgetListener of BlocListener with the current state.
BlocWidgetBuilder<S> = Widget Function(BuildContext context, S state)
Signature for the builder function which takes the BuildContext and state and is responsible for returning a widget which is to be rendered. This is analogous to the builder function in StreamBuilder.
BlocWidgetListener<S> = void Function(BuildContext context, S state)
Signature for the listener function which takes the BuildContext along with the state and is responsible for executing in response to state changes.
BlocWidgetSelector<S, T> = T Function(S state)
Signature for the selector function which is responsible for returning a selected value, T, based on state.
EventHandler<Event, State> = FutureOr<void> Function(Event event, Emitter<State> emit)
An event handler is responsible for reacting to an incoming Event and can emit zero or more states via the Emitter.
EventMapper<Event> = Stream<Event> Function(Event event)
Signature for a function which converts an incoming event into an outbound stream of events. Used when defining custom EventTransformers.
EventTransformer<Event> = Stream<Event> Function(Stream<Event> events, EventMapper<Event> mapper)
Used to change how events are processed. By default events are processed concurrently.
ExitCallback = FutureOr<bool> Function(BuildContext context, GoRouterState state)
Signature for function used in RouteBase.onExit.
GoExceptionHandler = void Function(BuildContext context, GoRouterState state, GoRouter router)
The function signature of GoRouter.onException.
GoRouterBuilderWithNav = Widget Function(BuildContext context, Widget child)
Signature of a go router builder function with navigator.
GoRouterPageBuilder = Page Function(BuildContext context, GoRouterState state)
The page builder for GoRoute.
GoRouterRedirect = FutureOr<String?> Function(BuildContext context, GoRouterState state)
The signature of the redirect callback.
GoRouterWidgetBuilder = Widget Function(BuildContext context, GoRouterState state)
The widget builder for GoRoute.
The function signature for navigation callbacks in _OnEnterHandler.
Signature for functions used to build Navigators
OnEnter = FutureOr<OnEnterResult> Function(BuildContext context, GoRouterState currentState, GoRouterState nextState, GoRouter goRouter)
The signature for the top-level onEnter callback.
OnEnterThenCallback = FutureOr<void> Function()
Signature for callbacks invoked after an OnEnterResult is resolved.
ParserExceptionHandler = RouteMatchList Function(BuildContext context, RouteMatchList routeMatchList)
The function signature of GoRouteInformationParser.onParserException.
PopPageWithRouteMatchCallback = bool Function(Route route, dynamic result, RouteMatchBase match)
Signature for a function that takes in a route to be popped with the result and returns a boolean decision on whether the pop is successful.
QueryParameterDecoder<T> = T Function(String value)
Signature for custom query parameter decoding functions.
QueryParameterEncoder<T> = String Function(T value)
Signature of custom query parameter encoding.
RouteInfoState = RouteInformationState
Type alias for route information state with dynamic type parameter.
RouteMatchVisitor = bool Function(RouteMatchBase)
The function signature for RouteMatchList.visitRouteMatches
ShellNavigationContainerBuilder = Widget Function(BuildContext context, StatefulNavigationShell navigationShell, List<Widget> children)
Builder for a custom container for the branch Navigators of a StatefulShellRoute.
ShellRouteBuilder = Widget Function(BuildContext context, GoRouterState state, Widget child)
The widget builder for ShellRoute.
ShellRoutePageBuilder = Page Function(BuildContext context, GoRouterState state, Widget child)
The page builder for ShellRoute.
StatefulShellRouteBuilder = Widget Function(BuildContext context, GoRouterState state, StatefulNavigationShell navigationShell)
The widget builder for StatefulShellRoute.
StatefulShellRoutePageBuilder = Page Function(BuildContext context, GoRouterState state, StatefulNavigationShell navigationShell)
The page builder for StatefulShellRoute.
ViewFactory<V, C, VM> = V Function({required ViewModelFactory<C, VM> createViewModel})
Creates a view with its ViewModelFactory, e.g. MyView.new. Used as createView by routes, dialogs and bottom sheets.
ViewModelFactory<C, VM> = VM Function(C cubit)
Creates the view model of a view from its cubit, e.g. MyViewModel.new.

Exceptions / Errors

BlockedInitialNavigationException
Raised when Block is returned from onEnter but there is no prior route configuration to restore (e.g., an initial deep link was blocked).
CancelledException
Thrown by CancellationToken.throwIfCancelled. WaitFor treats it as a cancellation, not as an error.
GoError
Thrown when GoRouter is used incorrectly.
GoException
Thrown when GoRouter can not handle a user request.
ProviderNotFoundException
The error that will be thrown if Provider.of fails to find a Provider as an ancestor of the BuildContext used.