I am making a demo for learning basis...where I have created a Custom widget with the use of LISTTILE..
I have actually 3 BottomNvigatationBarItem [ alimonies, favmovies and deletedMovies] which all showing list of movies
but I want trailing different in all 3 screens like
all movies with Delete and Fav icon, Fav movies with only Fav Icon, and Deleted Movies with restore and delete icon
here is my custom widget code
class MyCard extends StatelessWidget {
final Movie e;
final VoidCallback taponfav;
final VoidCallback tapondel;
//todo delete should be optional
MyCard({required this.e,required this.taponfav,required this.tapondel});
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
title: Text(e.name.toString()),
subtitle: Text(e.language),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: userlist[0].favmovies.contains(e) == true
? Icon(Icons.favorite)
: Icon(Icons.favorite_outline),
onPressed: taponfav),
IconButton(
icon: Icon(Icons.delete),
onPressed: tapondel),
],
),
leading: CircleAvatar(
backgroundImage: NetworkImage(e.imageurl),
),
),
);
}
}
and here is a single screen code to show how I use my card
body: ListView(
children: movielist
.map((e) => MyCard(e: e, taponfav: (){
if(userlist[0].favmovies.contains(e)==true)
userlist[0].favmovies.remove(e);
else
userlist[0].favmovies.add(e);
setState(() {
});
},tapondel: (){
showDialog(context: context, builder: (ctx){
return AlertDialog(
title: Text('Are u sure to delete?...'),
actions: [TextButton(onPressed: (){
Navigator.of(ctx).pop();
userlist[0].deletedmovies.add(e);
movielist.remove(e);
setState(() {
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: Duration(seconds: 4),
content: Text(e.name+' Is Deleted'),));
},child: Text('Yes'),),
TextButton(onPressed: (){
Navigator.of(ctx).pop();
}, child: Text('No')),
],
);
});
setState(() {
});
},),)
.toList(),
),