cubit

0.1.2

Cubit is a lightweight state management solution. It is a subset of the bloc package that does not rely on events and instead uses methods to emit new states.

This package is discontinued upstream.

Download archive

Readme

Cubit is a lightweight state management solution. It is a subset of the bloc package that does not rely on events and instead uses methods to emit new states.

Every cubit requires an initial state which will be the state of the cubit before emit has been called. The current state of a cubit can be accessed via the state getter.

Creating a Cubit

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

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

Using a Cubit

void main() async {
  final cubit = CounterCubit()..increment();
  await cubit.close();
}

Observing a Cubit

onTransition can be overridden to observe state changes for a single cubit.

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

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

  @override
  void onTransition(Transition<int> transition) {
    print(transition);
    super.onTransition(transition);
  }
}

CubitObserver can be used to observe state changes for all cubits.

class MyCubitObserver extends CubitObserver {
  @override
  void onTransition(Cubit cubit, Transition transition) {
    print(transition);
    super.onTransition(cubit, transition);
  }
}
void main() {
  Cubit.observer = MyCubitObserver();
  // Use cubits...
}

Dart Versions

  • Dart 2: >= 2.7.0

Maintainers

Supporters

Very Good Ventures

Starware

Cubit is Starware.
This means you're free to use the project, as long as you star its GitHub repository.
Your appreciation makes us grow and glow up. ⭐

Changelog

0.1.2

  • revert: v0.1.1

0.1.1

  • fix: offload state emission to next event loop iteration

0.1.0

  • docs: add onTransition documentation to README
  • docs: add CubitObserver documentation to README

0.0.14

  • feat: add CubitObserver support
  • docs: minor documentation improvements

0.0.13

  • docs: various documentation updates

0.0.12

  • docs: fix coverage badge

0.0.11

  • docs: various documentation updates

0.0.10

  • docs: various documentation updates

0.0.9

  • docs: documentation and logo updates

0.0.8

  • BREAKING: revert named initialState parameter (related issue)
  • docs: minor logo updates

0.0.7

  • feat: add onTransition to cubit
  • feat: Cubit extends CubitStream

0.0.6

  • BREAKING: ignore duplicate states

0.0.5

  • feat: allow initialState to be null

0.0.4

  • BREAKING: use named parameter for initialState

0.0.3

  • BREAKING: remove initialState getter and instead require initial state via constructor

0.0.2

  • BREAKING: update emit to be a void function
  • BREAKING: remove artifical wait to guarantee initialState is emitted
  • BREAKING: close drains the internal Stream
  • tests: 100% test coverage

0.0.1

  • feat: initial release

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add cubit
pubspec.yaml
name: cubit
description: Cubit is a lightweight state management solution. It is a subset of the bloc package that does not rely on events and instead uses methods to emit new states.
repository: https://github.com/felangel/cubit
issue_tracker: https://github.com/felangel/cubit/issues
homepage: https://github.com/felangel/cubit

version: 0.1.2

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  meta: ^1.1.8

dev_dependencies:
  mockito: ^4.1.1
  test: ^1.14.6
  test_coverage: ^0.4.1

Version history

VersionPublishedArchiveSHA-256
0.0.1Cached · Upstream SHA-256 matchedDownload079f57b1…226f99
0.0.2Cached · Upstream SHA-256 matchedDownload550fea81…7922f4
0.0.3Cached · Upstream SHA-256 matchedDownloadab88c201…6c8041
0.0.4Cached · Upstream SHA-256 matchedDownloadf4a67d94…bd5876
0.0.5Cached · Upstream SHA-256 matchedDownloadd5696901…51d93a
0.0.6Cached · Upstream SHA-256 matchedDownload73d84229…2abfc8
0.0.7Cached · Upstream SHA-256 matchedDownloadbc21713e…f5615e
0.0.8Cached · Upstream SHA-256 matchedDownload9f5416e3…c307aa
0.0.9Cached · Upstream SHA-256 matchedDownload97d453a5…16439e
0.0.10Cached · Upstream SHA-256 matchedDownloadbc824229…91c69f
0.0.11Cached · Upstream SHA-256 matchedDownloaddad61f71…848bc4
0.0.12Cached · Upstream SHA-256 matchedDownload272e2aaf…c96e94
0.0.13Cached · Upstream SHA-256 matchedDownload60cce409…c6c812
0.0.14Cached · Upstream SHA-256 matchedDownload57389080…ae54d4
0.1.0Cached · Upstream SHA-256 matchedDownload358b6931…b93b64
0.1.1Cached · Upstream SHA-256 matchedDownloaddbc518db…3ccec2
0.1.2Cached · Upstream SHA-256 matchedDownload87a0e33d…bd48b2
0.2.0-dev.1Cached · Upstream SHA-256 matchedDownload3dce5882…766789

Dependencies

meta "^1.1.8"