I'm getting data from the api and show them as list then choose particular index to delete data from the list and from the database too. actually that particular Item is being deleted from the database but need to trigger get data api again then list will be updated.
Oh sorry I forgot to mention that I'm using flutter_bloc.
PIECE OF CODE:
List<AlertData> recordings;
class RecordingsScreen extends StatelessWidget {
final void Function() onPop;
const RecordingsScreen({Key key, this.onPop}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: MyTheme.white,
appBar: AppBar(
elevation: 0,
backgroundColor: MyTheme.primaryColor,
automaticallyImplyLeading: false,
title: Row(
children: [
IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: MyTheme.secondryColor,
),
onPressed: onPop),
Text(
"RECORDINGS",
style: TextStyle(
color: MyTheme.secondryColor,
),
),
],
),
),
body: BlocProvider(
create: (context) => AlertBloc()..add(GetOldAlerts()),
child: BlocBuilder<AlertBloc, AlertState>(
builder: (BuildContext context, AlertState state) {
if (state.alertStatus == AlertStatus.gettingOldAlertsFailed ||
state.alertStatus == AlertStatus.deletionAlertFailed) {
return _OldAlertFailed(
error: state.res['message'],
);
}
if (state.alertStatus == AlertStatus.gotOldAlerts ||
state.alertStatus == AlertStatus.deletedAlert ||
state.alertStatus == AlertStatus.deletionAlert) {
recordings = [];
recordings =
BlocProvider.of<AlertBloc>(context).oldAlertModel;
return _bodyForm(state);
}
return Center(
child: ProcessingIndicator(),
);
},
),
),
);
}
_bodyForm(AlertState state ){
return Stack(
children: [
_RecordingsForm(),
state.alertStatus == AlertStatus.deletionAlert
? _DeletionProcessBar()
:Container()
],
);
}
}
List of items which are being fetched from the api
class _RecordingsForm extends StatefulWidget {
@override
__RecordingsFormState createState() => __RecordingsFormState();
}
class __RecordingsFormState extends State<_RecordingsForm> {
@override
Widget build(BuildContext context) {
return Container(
child: ListView.builder(
itemCount: recordinds.length,
itemBuilder: (context, index) {
return ListTile(
trailing: recordinds[index].isPlaying
? Image.asset(
PLAYING_ASSET,
height: 20,
width: 20,
)
: PopupMenuButton(
elevation: 3,
child: Image.asset(
VERTICAL_MENU_ASSET,
height: 20,
width: 20,
),
itemBuilder: (_) => <PopupMenuEntry<String>>[
new PopupMenuItem(
value: "DELETE",
height: 10,
child: Row(
children: [
Text(
"DELETE",
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.bold),
),
SizedBox(width: 4),
Image.asset(
DELETE_ASSET,
height: 13,
width: 13,
),
],
))
],
onSelected: (val) => BlocProvider.of<AlertBloc>(context).add(DeleteAlert(
recordinds[index].alertId.toString()))), //HERE DELETE ITEM EVENT GOT TRIGGERED.
contentPadding: ...,
leading: ...,
title: ...);
}));
}
}
Here is the short_video of issue