From cb53848b0ca85fd0a50110c05fc2709cf983c0fa Mon Sep 17 00:00:00 2001 From: apoleon33 Date: Wed, 3 Jan 2024 20:08:17 +0100 Subject: [PATCH] cleaner way of creating cards on startup --- lib/albumCard/albumCard.dart | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/albumCard/albumCard.dart b/lib/albumCard/albumCard.dart index 2390b7a..07f202e 100644 --- a/lib/albumCard/albumCard.dart +++ b/lib/albumCard/albumCard.dart @@ -7,12 +7,10 @@ class AlbumCard extends StatefulWidget { late DateTime date; bool isCard; - AlbumCard({super.key, required DateTime time, required this.isCard}) { - date = time; - } + AlbumCard({super.key, required this.date, required this.isCard}); @override - State createState() => _AlbumCardState(time: date); + State createState() => _AlbumCardState(); } class _AlbumCardState extends State { @@ -24,10 +22,13 @@ class _AlbumCardState extends State { String genre = "genre"; double averageRating = 5.0; - _AlbumCardState({required DateTime time}) { - date = time; - - _getAlbumByDate(); + @override + void initState() { + super.initState(); + date = widget.date; + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + _getAlbumByDate(); + }); } void _getAlbumByDate() async {