I'm trying to create a list that initializes the same cubit per item in the list. Each item in the list has a button that will change its label based on its state. Ex. edit -> submit. What im trying to accomplish is if when I click on any button and there exists any other button which state is not edit make that state edit so that only the button I just pressed is submit. I posted what I have so far. Any help is much appreciated thank you!
return Scaffold(
appBar: AppBar(
title: Text('Editable List'),
),
body: ListView.builder(
itemCount: 4,
itemBuilder: (BuildContext context, int index) {
return BlocProvider<Cubit1>(
create: (context) => Cubit1(),
child:
BlocConsumer<Cubit1, State1>(
listener: (context, state) {
if(state == State1.editing) {
//CHECK IF THERE ARE OTHER TILES
//WITH STATES OTHER THAN EDIT
//CHANGE IT BACK TO EDIT IF TRUE
}
},
builder: (context, state) {
return ListTile(
title: Text('List Tile ${index + 1}'),
trailing: ElevatedButton(
onPressed: () {
_toggleEditing();
},
child: Text(state == State1.initial ? 'Submit' : 'Edit'),
),
);
},
);
},
),
);
},
),
);