I want to show an icon if bool editI == true and don't show it if editI == false. But I can't change the value of editI in cubit.dart and pass to page.dart
I have this
cubit
class LayoutCubit extends Cubit<LayoutStates> {
LayoutCubit() : super(LayoutInitState());
static LayoutCubit get(context) => BlocProvider.of(context);
...
bool editI = false;
void changeEditI(editI) {
print(editI);
editI = !editI;
emit(LayoutChangeEditIState());
print(editI);
}
page
class ProfileScreen extends StatelessWidget {
final String? id;
const ProfileScreen({Key? key, required this.id}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocConsumer<LayoutCubit, LayoutStates>(
listener: (context, state) {},
builder: (context, state) {
var cubit = LayoutCubit.get(context);
cubit.getUserDataById(id!);
return Scaffold(
...
IconButton(
onPressed: (() {
cubit.changeEditI(editI);
}),
icon: const Icon( Icon.edit,size: 20))
...
child: ListTile(
...
trailing: editI == true ? IconButton(
onPressed: () {},
icon:const Icon(Icon.delete)): null,
...