RhythmBox/lib/screens/explore.dart

70 lines
1.9 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';
2024-08-29 08:42:48 +00:00
import 'package:rhythm_box/widgets/playlist/playlist_tile.dart';
2024-08-28 17:45:33 +00:00
import 'package:rhythm_box/widgets/sized_container.dart';
2024-08-26 12:26:07 +00:00
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),
2024-08-28 17:45:33 +00:00
centerTitle: MediaQuery.of(context).size.width >= 720,
2024-08-26 12:26:07 +00:00
),
2024-08-28 17:45:33 +00:00
body: CenteredContainer(
child: Skeletonizer(
enabled: _isLoading,
child: ListView.builder(
itemCount: _featuredPlaylist?.length ?? 20,
itemBuilder: (context, idx) {
final item = _featuredPlaylist?[idx];
2024-08-29 08:42:48 +00:00
return PlaylistTile(
item: item,
2024-08-28 17:45:33 +00:00
onTap: () {
if (item == null) return;
GoRouter.of(context).pushNamed(
'playlistView',
pathParameters: {'id': item.id!},
);
},
);
},
),
2024-08-26 12:26:07 +00:00
),
),
),
);
2024-08-26 05:29:17 +00:00
}
}