flutter_bloc state management extension that integrates sealed_unions.

Overview

Sealed Flutter Bloc

build codecov Star on Github style: effective dart Flutter Website Awesome Flutter Flutter Samples License: MIT Discord Bloc Library

flutter_bloc meets sealed_unions


Sponsors

Our top sponsors are shown below! [Become a Sponsor]


Try the Flutter Chat Tutorial   💬

Quick Start

Extend UnionNImpl

class MyState extends Union4Impl<Initial, Loading, Success, Failure> {
  static final unions = const Quartet<Initial, Loading, Success, Failure>();

  MyState._(Union4<Initial, Loading, Success, Failure> union) : super(union);

  factory MyState.initial() => MyState._(unions.first(Initial()));

  factory MyState.loading() => MyState._(unions.second(Loading()));

  factory MyState.success({required String data}) =>
      MyState._(unions.third(Success(data: data)));

  factory MyState.failure({required String error}) =>
      MyState._(unions.fourth(Failure(error: error)));
}

class Initial {}

class Loading {}

class Success {
  final String data;

  Success({required this.data});
}

class Failure {
  String error;

  Failure({required this.error});
}

Use SealedBlocBuilder

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SealedBlocBuilder4<MyBloc, MyState, Initial, Loading, Success,
        Failure>(
      builder: (context, states) => states(
        (initial) => Text('Initial'),
        (loading) => CircularProgressIndicator(),
        (success) => Text('Success: ${success.data}'),
        (failure) => Text('Failure: ${failure.error}'),
      ),
    );
  }
}

Additional Examples

More examples can be found at sealed_flutter_bloc_samples.

Comments
  • more example

    more example

    Hello @felangel ,

    Still guessing. Could you please provide us more samples, things related to changes in state data such as the use of copyWith ?

    Thank's.

    documentation enhancement 
    opened by semutnest 7
  • Unable to import BlocProvider

    Unable to import BlocProvider

    Describe the bug Unable to import BlocProvider.

    To Reproduce Empty project with sealed_flutter_bloc as the only bloc related packages in pubspec.yaml.

    Expected behavior As this package depends on bloc, flutter, flutter_bloc and sealed_unions, i expect BlocProvider from flutter_bloc to be present, i.e., i don't have to also include the flutter_bloc package in my pubspec.yaml.

    Screenshots If applicable, add screenshots to help explain your problem.

    **Logs ** Run flutter analyze and attach any output of that command below. If there are any analysis errors, try resolving them before filing this issue.

    Paste the output of running flutter doctor -v here.

    Additional context Add any other context about the problem here.

    question 
    opened by livingmine 4
  • Please update to flutter_bloc ^6.0.1

    Please update to flutter_bloc ^6.0.1

    sealed_flutter_bloc ^4.0.0 which depends on flutter_bloc ^4.0.0 and my project depends on flutter_bloc ^6.0.1, version solving failed

    Please upgrade with flutter_bloc ^6.0.1

    enhancement 
    opened by waqasakram117 2
  • Question: Print type

    Question: Print type

    I can't seem to wrap my head around how you would print which type MyState would represent. I guess that overriding toString in Inital, Loading, Success or Failure would not give anything. Overriding toString in MyState makes me change the output from:

    emit an event that TaskState:<MyState>

    to

    emit an event that TaskState:<My custom state message>

    Trying to write tests a toy project with your example gives me the following

    final expected = [ TaskState.Inital(), TaskState.Failure(error: "MyError"), ]; expectLater(bloc.state, emitsInOrder(expected));

    ERROR: Expected: should do the following in order: • emit an event that TaskState:<MyState> • emit an event that TaskState:<MyState>

    Would be nice to print something like

    ERROR: Expected: should do the following in order: • emit an event that TaskState:<Initial> • emit an event that TaskState:<Failure>

    question 
    opened by hkirk 2
  • feat: v5.0.0

    feat: v5.0.0

    Status

    READY

    Breaking Changes

    YES

    Description

    • Updated to bloc: ^5.0.0
    • Updated to flutter_bloc: ^5.0.0
    • Use flutter_cubit

    Todos

    • [X] Tests
    • [X] Documentation
    • [X] Examples
    enhancement 
    opened by felangel 1
  • v4.0.0

    v4.0.0

    Status

    READY

    Breaking Changes

    YES

    Description

    • Updated to bloc: ^4.0.0
    • Updated to flutter_bloc: ^4.0.0

    Todos

    • [X] Tests
    • [X] Documentation
    • [X] Examples
    enhancement 
    opened by felangel 1
  • upgrade to bloc/flutter_bloc v3.0.0

    upgrade to bloc/flutter_bloc v3.0.0

    Status

    IN DEVELOPMENT

    Breaking Changes

    YES

    Description

    Upgrade to bloc v3.0.0 and flutter_bloc v3.0.0 (https://github.com/felangel/bloc/pull/700)

    Todos

    • [X] Tests
    • [X] Documentation
    • [X] Examples

    Impact to Remaining Code Base

    • Breaking change which will be released in sealed_flutter_bloc v3.0.0
    enhancement 
    opened by felangel 1
  • feat!: migrate to null safety

    feat!: migrate to null safety

    Status

    READY

    Breaking Changes

    YES

    Description

    • closes #13
    • BREAKING: rename cubit parameter to bloc
    • Upgrade to null safety
    • Updated to bloc: ^7.0.0
    • Updated to flutter_bloc: ^7.0.0

    Todos

    • [X] Tests
    • [X] Documentation
    • [X] Examples
    enhancement 
    opened by felangel 0
  • fix: correct pub link for sealed_unions

    fix: correct pub link for sealed_unions

    Status

    READY

    Breaking Changes

    NO

    Description

    Correct pub link for sealed_unions from sealed_union to sealed_unions.

    Todos

    • [ ] Tests
    • [ ] Documentation
    • [ ] Examples

    Steps to Test or Reproduce

    Outline the steps to test or reproduce the PR here.

    • Click on the old link that will redirect to 404.

    Impact to Remaining Code Base

    This PR will affect: N/A *

    bug documentation 
    opened by piedcipher 0
  • sealed_flutter_bloc v1.0.0

    sealed_flutter_bloc v1.0.0

    Status

    READY

    Breaking Changes

    YES

    Description

    • Update to bloc v1.0.0

    Todos

    • [X] Tests
    • [X] Documentation
    • [X] Examples

    Impact to Remaining Code Base

    • Breaking changes included in sealed_flutter_bloc v1.0.0
    enhancement 
    opened by felangel 0
  • Update to use bloc v0.16.0

    Update to use bloc v0.16.0

    Status

    READY

    Breaking Changes

    YES

    Description

    • Update to use bloc ^0.16.0

    Todos

    • [X] Tests
    • [X] Documentation
    • [X] Examples

    Impact to Remaining Code Base

    None

    enhancement 
    opened by felangel 0
  • BlocListener?

    BlocListener?

    Is there a way to use this with bloc listener? currently, I'm literally just taking the state and doing:

    BlocListener<MyCubit, MyState>(
          listener: (context, state) {
              state.join(
                  (_) {}, //empty here, as we don't do anything with this state
                  (wantedState) => print(wantedState.wantedProperty); //do something here
             );
        }
    )
    

    Is it possible to have a function on on a state like:

    state.on<WantedState>((wantedState) => print(wantedState.wantedProperty));
    

    so that you can choose to only react to a single state as opposed to needing to put a voider function on every unwanted state?

    enhancement 
    opened by antholeole 0
Releases(v1.0.0)
Owner
Felix Angelov
software engineer by day, software engineer by night.
Felix Angelov
An extension to the bloc state management library which automatically persists and restores bloc states.

⚠️ Attention: This repository has been moved to https://github.com/felangel/bloc and is now read-only! An extension to the bloc state management libra

Felix Angelov 189 Nov 17, 2022
Flutter application that integrates with Spotify API

Storify Add captions to songs in your Spotify playlists Download Screenshots Features Sign in using Spotify Load playlists from Spotify Add captions t

Gyeongmin Lee 33 Nov 15, 2022
State Persistence - Persist state across app launches. By default this library store state as a local JSON file called `data.json` in the applications data directory. Maintainer: @slightfoot

State Persistence Persist state across app launches. By default this library store state as a local JSON file called data.json in the applications dat

Flutter Community 70 Sep 28, 2022
A powerful state machine for MobX management, that can be used in almost any application state.

A powerful state machine for MobX management, which can be used in almost any application state. It has 3 states - loading, success, error - and is pe

Daniel Magri 8 Oct 31, 2022
Practice building basic animations in apps along with managing app state by BLoC State Management, Flutter Slider.

Practice building basic animations in apps along with managing app state by BLoC State Management including: Cubit & Animation Widget, Flutter Slider.

TAD 1 Jun 8, 2022
Shopify Tag and Product Management App using Flutter and Riverpod State Management

Myshopify App A Simple Flutter Application project to get List of Tags, Products and Product Details from shopify https://shopicruit.myshopify.com/adm

Idowu Tomiwa 5 Nov 12, 2022
Basic implementation of flutter_bloc with firebase auth and other related stuff :)

flutter_bloc_implementation A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get

Muhammad Hamza 4 Mar 7, 2022
Made with Clean architecture + TDD + GraphQL + flutter_bloc + CodeCov + GitHooks + GitHub Actions (CI/CD) and finally with 💙

Rick and Morty Info A simple app to demonstrate Clean Architecture with GraphQL and flutter_bloc Motivation In Martin Fowler's words, “Any fool can wr

Venkatesh Prasad 473 Dec 25, 2022
A Very Good Blog App using Flutter, flutter_bloc, django rest framework for backend✨

Very Good Blog App - Blog sharing Features Login, register, manage personal information. Compose, edit, post blog to share with everyone. Like, save b

Nguyen Minh Dung 14 Nov 27, 2022
An app to pick, upload and display images from camera and gallery with size and extension constraints.

image_uploader A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Ehmad Saeed⚡ 4 Mar 7, 2022
Superpowers for Dart. Collection of useful static extension methods.

If you miss an extension, please open an issue or pull request Resources: Documentation Pub Package GitHub Repository On this page you can find some o

Simon Leier 955 Jan 8, 2023
"FlutterMoneyFormatter" is a Flutter extension to formatting various types of currencies according to the characteristics you like, without having to be tied to any localization.

FlutterMoneyFormatter FlutterMoneyFormatter is a Flutter extension to formatting various types of currencies according to the characteristics you like

Fadhly Permata 81 Jan 1, 2023
A powerful official extension library of Tab/TabBar/TabView, which support to scroll ancestor or child Tabs when current is overscroll, and set scroll direction and cache extent.

extended_tabs Language: English | 中文简体 A powerful official extension library of Tab/TabBar/TabView, which support to scroll ancestor or child Tabs whe

FlutterCandies 185 Dec 13, 2022
Flutter code extension that provides MediaQuery sizing info directly on the BuildContext instance

Flutter code extension that provides MediaQuery sizing info directly on the BuildContext instance. Also adds some helper methods for sizing and layout.

gskinner team 87 Dec 6, 2022
An extension of the Flutter ListView widget for incrementally loading items upon scrolling

incrementally_loading_listview An extension of the Flutter ListView widget for incrementally loading items upon scrolling. This could be used to load

Michael Bui 174 Sep 27, 2022
A kotlin-style extension collection for dart.

Collection of extensions Dart is good but can be better. Kotlin Style Join QQ Group now: 1003811176 For objects: let run also takeIf takeUnless For st

OpenFlutter 6 Nov 2, 2022
Code generator for Flutter's theme extension classes.

Welcome to Theme Tailor, a code generator and theming utility for supercharging Flutter ThemeExtension classes introduced in Flutter 3.0! The generato

iteo 35 Jan 2, 2023
Music player application for android. It's uses MVVM architecture and Provider & ValueNotifier state management.

music-player-flutter Flutter music player application which is my personal project published to play store. Project structures are as following,

null 30 Jul 10, 2022