Skip to content

Instantly share code, notes, and snippets.

@rubywai
Created June 7, 2025 03:50
Show Gist options
  • Select an option

  • Save rubywai/93b766c83987749f80a1286d2f6bb554 to your computer and use it in GitHub Desktop.

Select an option

Save rubywai/93b766c83987749f80a1286d2f6bb554 to your computer and use it in GitHub Desktop.
import 'package:flutter_bloc/flutter_bloc.dart';
// Define the events
abstract class CounterEvent {}
class CounterIncrement extends CounterEvent {}
class CounterDecrement extends CounterEvent {}
class CounterReset extends CounterEvent {}
// Define the Bloc
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<CounterIncrement>((event, emit) => emit(state + 1));
on<CounterDecrement>((event, emit) => emit(state - 1));
on<CounterReset>((event, emit) => emit(0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment