Skip to content

Commit 47d6218

Browse files
committed
fixed bug where homescreen content was not updating on refresh.
1 parent 2906021 commit 47d6218

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

lib/screens/home_screen/home_screen.dart

-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class _HomeScreenState extends State<HomeScreen> {
5151
nextLoading = false;
5252
});
5353
Map<String, dynamic> home = await ytMusic.browse();
54-
// pprint(home);
5554
if (mounted) {
5655
setState(() {
5756
initialLoading = false;
@@ -61,8 +60,6 @@ class _HomeScreenState extends State<HomeScreen> {
6160
continuation = home['continuation'];
6261
});
6362
}
64-
// pprint(home['sections'][1]['contents']);
65-
// await fetchNext();
6663
}
6764

6865
refresh() async {

lib/screens/home_screen/section_item.dart

+24-28
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,6 @@ class ItemList extends StatefulWidget {
349349
}
350350

351351
class _ItemListState extends State<ItemList> {
352-
late List items;
353-
354-
@override
355-
void initState() {
356-
super.initState();
357-
items = widget.items;
358-
}
359-
360352
@override
361353
Widget build(BuildContext context) {
362354
return LayoutBuilder(builder: (context, constraints) {
@@ -369,8 +361,8 @@ class _ItemListState extends State<ItemList> {
369361
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
370362
scrollDirection: Axis.horizontal,
371363
itemBuilder: (context, index) {
372-
double width = height * (items[index]?['aspectRatio'] ?? 1);
373-
String? subtitle = _buildSubtitle(items[index]);
364+
double width = height * (widget.items[index]?['aspectRatio'] ?? 1);
365+
String? subtitle = _buildSubtitle(widget.items[index]);
374366
return Adaptivecard(
375367
elevation: 0,
376368
borderRadius: BorderRadius.circular(8),
@@ -379,31 +371,33 @@ class _ItemListState extends State<ItemList> {
379371
child: AdaptiveInkWell(
380372
padding: EdgeInsets.all(Platform.isWindows ? 12 : 0),
381373
onTap: () async {
382-
if (items[index]['endpoint'] != null &&
383-
items[index]['videoId'] == null) {
374+
if (widget.items[index]['endpoint'] != null &&
375+
widget.items[index]['videoId'] == null) {
384376
Navigator.push(
385377
context,
386378
AdaptivePageRoute.create(
387-
(context) =>
388-
BrowseScreen(endpoint: items[index]['endpoint']),
379+
(context) => BrowseScreen(
380+
endpoint: widget.items[index]['endpoint']),
389381
));
390382
} else {
391383
await GetIt.I<MediaPlayer>()
392-
.playSong(Map.from(items[index]));
384+
.playSong(Map.from(widget.items[index]));
393385
}
394386
},
395387
onSecondaryTap: () {
396-
if (items[index]['videoId'] != null) {
397-
Modals.showSongBottomModal(context, items[index]);
398-
} else if (items[index]['playlistId'] != null) {
399-
Modals.showPlaylistBottomModal(context, items[index]);
388+
if (widget.items[index]['videoId'] != null) {
389+
Modals.showSongBottomModal(context, widget.items[index]);
390+
} else if (widget.items[index]['playlistId'] != null) {
391+
Modals.showPlaylistBottomModal(
392+
context, widget.items[index]);
400393
}
401394
},
402395
onLongPress: () {
403-
if (items[index]['videoId'] != null) {
404-
Modals.showSongBottomModal(context, items[index]);
405-
} else if (items[index]['playlistId'] != null) {
406-
Modals.showPlaylistBottomModal(context, items[index]);
396+
if (widget.items[index]['videoId'] != null) {
397+
Modals.showSongBottomModal(context, widget.items[index]);
398+
} else if (widget.items[index]['playlistId'] != null) {
399+
Modals.showPlaylistBottomModal(
400+
context, widget.items[index]);
407401
}
408402
},
409403
borderRadius: BorderRadius.circular(8),
@@ -414,14 +408,14 @@ class _ItemListState extends State<ItemList> {
414408
height: height,
415409
decoration: BoxDecoration(
416410
color: Colors.grey.withOpacity(0.1),
417-
borderRadius: items[index]['type'] == 'ARTIST'
411+
borderRadius: widget.items[index]['type'] == 'ARTIST'
418412
? BorderRadius.circular(height / 2)
419413
: BorderRadius.circular(8),
420414
image: DecorationImage(
421415
fit: BoxFit.cover,
422416
image: CachedNetworkImageProvider(
423417
getEnhancedImage(
424-
items[index]['thumbnails'].first['url'],
418+
widget.items[index]['thumbnails'].first['url'],
425419
dp: MediaQuery.of(context).devicePixelRatio,
426420
width: width),
427421
),
@@ -438,7 +432,9 @@ class _ItemListState extends State<ItemList> {
438432
contentPadding: const EdgeInsets.symmetric(
439433
horizontal: 0, vertical: 4),
440434
title: Text(
441-
items[index]['title'].toString().breakWord,
435+
widget.items[index]['title']
436+
.toString()
437+
.breakWord,
442438
maxLines: 2,
443439
style: const TextStyle(height: 1.3),
444440
overflow: TextOverflow.ellipsis,
@@ -447,7 +443,7 @@ class _ItemListState extends State<ItemList> {
447443
subtitle: Row(
448444
crossAxisAlignment: CrossAxisAlignment.center,
449445
children: [
450-
if (items[index]['explicit'] == true)
446+
if (widget.items[index]['explicit'] == true)
451447
Padding(
452448
padding: const EdgeInsets.only(right: 2),
453449
child: Icon(
@@ -480,7 +476,7 @@ class _ItemListState extends State<ItemList> {
480476
);
481477
},
482478
separatorBuilder: (context, index) => const SizedBox(width: 8),
483-
itemCount: items.length,
479+
itemCount: widget.items.length,
484480
),
485481
);
486482
});

0 commit comments

Comments
 (0)