Skip to content

Instantly share code, notes, and snippets.

@zohaib304
Last active March 18, 2021 18:18
Show Gist options
  • Save zohaib304/1be65f880d6a1c76185055d2b07e9928 to your computer and use it in GitHub Desktop.
Save zohaib304/1be65f880d6a1c76185055d2b07e9928 to your computer and use it in GitHub Desktop.
dart cubit
// cubit expose its inner functions
// which can be called from outside to update its state
// the cubit functions are not stream which means they are pre defined functions.
import 'package:bloc/bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
void decrement() => emit(state - 1);
}
void main() {
final cubit = CounterCubit();
cubit.increment();
print(cubit.state);
cubit.increment();
print(cubit.state);
cubit.increment();
print(cubit.state);
cubit.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment