when i press the add or minus button the number doesn't change and the bloc consumer doesn't listen to states i don't know the reason i tried every thing but nothing worked with me i want to know how to listen to changes and make the number change when i press the buttons add or minus
`
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
ColorsCubit cubit = ColorsCubit();
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => ColorsCubit(),
child: BlocConsumer<ColorsCubit, ColorsStates>(
listener: (context,ColorsStates state) {
if (state is InitialState) print("in initial state");
if(state is AddState)print('add state');
},
builder: (context,ColorsStates state) {
return Scaffold(
body: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(onPressed: ()=>cubit.add(), child: Text("add")),
Text(cubit.count.toString()),
TextButton(onPressed: ()=>cubit.minus(), child: Text("minus")),
],
),
),
);
},
));
}
}
// this is cubit class
class ColorsCubit extends Cubit<ColorsStates>{
ColorsCubit() : super(InitialState());
static ColorsCubit get(context)=>BlocProvider.of(context);
int count=0;
void add(){
count++;
emit(AddState());
}
void minus(){
count++;
emit(MinusState());
}
}
// this is states class
abstract class ColorsStates{}
class InitialState extends ColorsStates{}
class AddState extends ColorsStates{}
class MinusState extends ColorsStates{}
`