Skip to main content

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

Cubit state management with MVVM views and presenter-driven navigation: routes, dialogs and bottom sheets get managed cubits and adaptive Material or Cupertino UI.

presented_bloc #

License: MIT Bloc Library

Build Flutter apps with Cubit, MVVM-style views, and presenter-driven navigation—while adapting the UI to your app's design language.

presented_bloc gives screens, dialogs, and bottom sheets a consistent lifecycle and architecture:

  • Cubit owns state and behavior.
  • View model turns state into display-ready values.
  • View renders those values and forwards user input to the cubit.
  • Presenter creates and provides the cubit, connects parent cubits, and frames the view as a route, dialog, or bottom sheet.

What you get #

  • App lifecycle and routing: PresentedApp, AppCubit, and AppRoutes support setup, deep links, nested routes, and navigation-stack restoration when the app tree restarts.
  • Managed route cubits: AppRoutes.buildRoute creates one cubit per route location, resolves parent cubits from the route tree, and closes owned cubits when their pages are removed.
  • Views and view models: CubitView, CubitViewModel, and DataWidget help keep presentation data separate from layout.
  • Reusable presentations: present a view as a page, dialog, or bottom sheet; customize its surrounding UI with PresenterBuilder.
  • Async operations: WaitFor tracks loading state, handles errors, and supports cancellable requests with CancellationToken.
  • Adaptive UI: Material and Cupertino presentations are supported, and the design language can be changed at runtime while preserving app state and navigation.

Fluent, Adwaita, and KDE are represented by DesignLanguage, but are not yet implemented and throw UnimplementedError.

Install #

Add the package to pubspec.yaml:

dependencies:
  presented_bloc: ^1.0.0

Then import it:

import 'package:presented_bloc/presented_bloc.dart';

The package also exports Flutter Material, flutter_bloc, and go_router.

A screen in a few lines #

final class CounterCubit extends PresentedCubit<int> {
  CounterCubit() : super(0);

  void increment() => emit(state + 1);
}

final class CounterViewModel extends CubitViewModel<CounterCubit, int> {
  CounterViewModel(super.cubit);

  String get countLabel => 'Count: $state';
}

Build a CubitView with Watch<CounterCubit> to rebuild when the cubit emits, then present it with AppRoutes.buildRoute or a Presenter. The getting-started guide walks through a complete app, including the route, view, app shell, and Material/Cupertino builder.

Example app #

The example/ directory contains a complete todo app with nested routes, projects, dialogs, bottom sheets, and settings.

cd example
fvm flutter pub get
fvm flutter run -d linux                    # or macos, an emulator, …
fvm flutter run -t lib/web.dart -d chrome   # web, with path URLs

Useful starting points:

  • App entry point
  • Route tree
  • Presenter builder
  • Settings feature
  • Nested project routes

Start a new app from the template #

The template/ directory is a minimal Hello World app with the full project structure: app cubit and state, routes, a presenter builder, domain/ and data/ repository layers, and a hello feature with a cubit, state, view model and Material/Cupertino views. It also includes the .rules file that describes the architecture for AI coding agents.

Quick start: one command #

Run this in the folder where the new app should be created, with your app's package name (snake_case) instead of my_app:

curl -fsSL https://tangled.org/a.sparkle.blue/presented_bloc/raw/main/tool/create_app.sh | bash -s -- my_app

The script clones this repository into a temporary folder, creates an empty Flutter project, copies the template, .rules and .agents/ into it, renames everything after your app, makes presented_bloc a git dependency and runs pub get and analyze.

For example, the template's names become:

Template Your app
package hello_world example
HelloAppCubit, HelloAppState, HelloAppRoutes, … ExampleAppCubit, ExampleAppState, ExampleAppRoutes, …
HelloWorldBuilder, HelloWorldRepository, helloWorldRepository ExampleBuilder, ExampleRepository, exampleRepository
HelloRouteSettings, page title Hello World ExampleRouteSettings, Example
hello feature: HelloCubit, /hello, features/hello/ home feature: HomeCubit, /home, features/home/

A name ending in _app doesn't get a second App (my_app → MyAppCubit). The first screen is called home rather than after your app, so its classes can't clash with the app classes. It uses fvm flutter (with this repository's .fvmrc) when FVM is installed, otherwise flutter.

Options go after the app name:

# bundle id prefix, a specific branch/tag/commit, and no FVM
curl -fsSL https://tangled.org/a.sparkle.blue/presented_bloc/raw/main/tool/create_app.sh \
  | bash -s -- my_app --org dev.example --ref main --no-fvm

# from a local clone instead of downloading (depends on it by path)
bash path/to/presented_bloc/tool/create_app.sh my_app --source path/to/presented_bloc
Option Default Meaning
--org <domain> com.example Reverse domain for the Android/iOS bundle id
--ref <ref> main Branch, tag or commit of presented_bloc to use
--source <dir> Use a local checkout instead of cloning
--no-fvm Use flutter from PATH even if FVM is installed

Requires bash, git, perl and Flutter (or FVM). To read the script before running it, open tool/create_app.sh.

Then continue with step 2.

1. Create the project manually #

If you'd rather not run a remote script, set the name of your app and the path to your clone of this repository, then run the commands from the folder where the new app should be created:

APP=my_app                                   # package name, snake_case
PRESENTED_BLOC=$HOME/src/presented_bloc      # path to your presented_bloc clone

# An empty Flutter project with the Flutter version this package uses
mkdir "$APP" && cd "$APP"
cp "$PRESENTED_BLOC/.fvmrc" .
fvm flutter create --empty --org com.example --project-name "$APP" .

# Copy the template app, the agent rules and the agent skills
cp -R "$PRESENTED_BLOC"/template/{lib,test,pubspec.yaml,analysis_options.yaml,.rules} .
cp -R "$PRESENTED_BLOC/.agents" .

# Rename the package and point the dependency at your clone
perl -pi -e "s/^name: hello_world\$/name: $APP/; s|path: \.\./|path: $PRESENTED_BLOC|" pubspec.yaml
perl -pi -e "s|package:hello_world/|package:$APP/|g" $(grep -rl 'package:hello_world/' lib test)

perl -pi is used instead of sed -i because it works the same on Linux and macOS. Change --org to your reverse domain; it sets the Android and iOS bundle identifiers.

2. Check and run it #

fvm flutter pub get
fvm flutter analyze
fvm flutter test
fvm flutter run -d linux       # or: -d macos, -d chrome, an emulator, …

You should see Hello, world! and a counter button. The app uses Cupertino on iOS and macOS and Material everywhere else.

3. Make it yours #

  • Dependency: the app depends on presented_bloc through git (one-command setup) or your local clone (manual setup or --source). To use the published package instead, replace that entry in pubspec.yaml with presented_bloc: ^1.0.0.
  • Class names: the one-command setup already renames the Hello… classes (see the table above). With the manual setup they are still called HelloApp…, HelloWorld… and Hello…; rename them with your IDE's rename refactoring.
  • First feature: copy lib/app/features/home/ (hello/ with the manual setup) as the starting point for a new screen, then add its route in lib/app/routes.dart. The .rules file explains each part (state, cubit, view model, views, barrels, repositories) and has a checklist for adding a screen.
  • Without FVM: use flutter and dart instead of fvm flutter and fvm dart, skip the .fvmrc copy, and make sure your Flutter version meets the requirements.

Documentation #

Requirements #

Flutter 3.47.0 or later and Dart 3.13.0 or later.

This repository pins its Flutter version with FVM in .fvmrc. The commands in this README use fvm flutter; without FVM, drop the fvm prefix.

License #

MIT. See LICENSE.

0
likes
140
points
117
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

Cubit state management with MVVM views and presenter-driven navigation: routes, dialogs and bottom sheets get managed cubits and adaptive Material or Cupertino UI.

Repository
View/report issues

Topics

#bloc #state-management #mvvm #navigation #architecture

License

MIT (license)

Dependencies

bloc, cupertino_ui, equatable, flutter, flutter_bloc, focus_detector_v2, go_router, material_ui, provider

More

Packages that depend on presented_bloc