RhythmBox/lib/screens/explore.dart

87 lines
2.6 KiB
Dart
Raw Normal View History

2024-08-26 05:29:17 +00:00
import 'package:flutter/material.dart';
2024-08-26 12:26:07 +00:00
import 'package:get/get.dart';
import 'package:go_router/go_router.dart';
import 'package:rhythm_box/providers/spotify.dart';
import 'package:rhythm_box/widgets/auto_cache_image.dart';
import 'package:skeletonizer/skeletonizer.dart';
import 'package:spotify/spotify.dart';
2024-08-26 05:29:17 +00:00
class ExploreScreen extends StatefulWidget {
const ExploreScreen({super.key});
@override
State<ExploreScreen> createState() => _ExploreScreenState();
}
class _ExploreScreenState extends State<ExploreScreen> {
2024-08-26 12:26:07 +00:00
late final SpotifyProvider _spotify = Get.find();
bool _isLoading = true;
List<PlaylistSimple>? _featuredPlaylist;
Future<void> _pullPlaylist() async {
_featuredPlaylist =
2024-08-27 06:35:16 +00:00
(await _spotify.api.playlists.featured.getPage(20)).items!.toList();
2024-08-26 12:26:07 +00:00
setState(() => _isLoading = false);
}
@override
void initState() {
super.initState();
_pullPlaylist();
}
2024-08-26 05:29:17 +00:00
@override
Widget build(BuildContext context) {
2024-08-26 12:26:07 +00:00
return Material(
color: Theme.of(context).colorScheme.surface,
child: Scaffold(
appBar: AppBar(
title: Text('explore'.tr),
),
body: Skeletonizer(
enabled: _isLoading,
child: ListView.builder(
itemCount: _featuredPlaylist?.length ?? 20,
itemBuilder: (context, idx) {
final item = _featuredPlaylist?[idx];
return ListTile(
leading: ClipRRect(
2024-08-27 06:35:16 +00:00
borderRadius: const BorderRadius.all(Radius.circular(8)),
2024-08-26 12:26:07 +00:00
child: item != null
? AutoCacheImage(
item.images!.first.url!,
width: 64.0,
height: 64.0,
)
: const SizedBox(
width: 64,
height: 64,
child: Center(
child: Icon(Icons.image),
),
),
),
title: Text(item?.name ?? 'Loading...'),
subtitle: Text(
item?.description ?? 'Please stand by...',
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
onTap: () {
if (item == null) return;
GoRouter.of(context).pushNamed(
'playlistView',
pathParameters: {'id': item.id!},
);
},
);
},
),
),
),
);
2024-08-26 05:29:17 +00:00
}
}