Created
May 14, 2022 21:15
-
-
Save ndungudedan/40671200c5ce6787351f11b444557fa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FavoritesPage extends StatelessWidget { | |
static String routeName = '/favorites_page'; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Favorites'), | |
), | |
body: Consumer<Favorites>( | |
builder: (context, favorite, child) => ListView.builder( | |
key: ValueKey('Favorites Listview'), | |
shrinkWrap: true, | |
itemCount: favorite.items.length, | |
padding: const EdgeInsets.symmetric(vertical: 16), | |
itemBuilder: (context, index) => FavoriteItemTile( | |
() { | |
favorite.remove(index); | |
ScaffoldMessenger.of(context).showSnackBar(SnackBar( | |
content: Text('Note removed'), | |
duration: const Duration(seconds: 1), | |
)); | |
}, | |
favorite.items[index], | |
key: ObjectKey(favorite.items[index]), | |
), | |
), | |
), | |
); | |
} | |
} | |
class FavoriteItemTile extends StatelessWidget { | |
final Note note; | |
final Function() onPressed; | |
FavoriteItemTile(this.onPressed, this.note, {Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Builder(builder: (context) { | |
return Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: ListTile( | |
title: Text( | |
note.title, | |
), | |
subtitle: Text(note.description), | |
trailing: IconButton(onPressed: onPressed, icon: Icon(Icons.delete)), | |
), | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment