A dart package that helps implements basic states for BLoC library.

pub package Test codecov License: MIT

Features

  • Provides all states to handle init, waiting, value/no value and error states
  • A ValueCubit class to manage standards states and refreshing capabilities

Usage

class MyCubit extends ValueCubit<int> {
  @override
  Future<void> emitValues() async {
    final result = await getMyValueFromRepository();

    emit(ValueState(result));
  }
}

main() async {
  final myCubit = MyCubit();

  myCubit.refresh();

  await for (final state in myCubit.stream) {
    if (state is WaitingState<int>) {
      // do stuff for waiting
    } else if (state is ValueState<int>) {
      // do stuff with value
    } else if (state is ErrorState<int>) {
      // handle error
    }
  }

  // you can refresh values
}

Feedback

Please file any issues, bugs or feature requests as an issue on the Github page.

Libraries

value_cubit