Last active
March 18, 2021 18:18
-
-
Save zohaib304/1be65f880d6a1c76185055d2b07e9928 to your computer and use it in GitHub Desktop.
dart cubit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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