import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:spotify/spotify.dart'; import 'package:spotube/components/Shared/PageWindowTitleBar.dart'; import 'package:spotube/components/Playlist/PlaylistCard.dart'; import 'package:spotube/provider/SpotifyDI.dart'; class PlaylistGenreView extends StatefulWidget { final String genreId; final String genreName; final Iterable? playlists; const PlaylistGenreView( this.genreId, this.genreName, { this.playlists, Key? key, }) : super(key: key); @override _PlaylistGenreViewState createState() => _PlaylistGenreViewState(); } class _PlaylistGenreViewState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: const PageWindowTitleBar( leading: BackButton(), ), body: Column( children: [ Text( widget.genreName, style: Theme.of(context).textTheme.headline4, textAlign: TextAlign.center, ), Consumer( builder: (context, data, child) => Expanded( child: SingleChildScrollView( child: FutureBuilder>( future: widget.playlists == null ? (widget.genreId != "user-featured-playlists" ? data.spotifyApi.playlists .getByCategoryId(widget.genreId) .all() : data.spotifyApi.playlists.featured.all()) : Future.value(widget.playlists), builder: (context, snapshot) { if (snapshot.hasError) { return const Center(child: Text("Error occurred")); } if (!snapshot.hasData) { return const CircularProgressIndicator.adaptive(); } return Center( child: Wrap( children: snapshot.data! .map( (playlist) => Padding( padding: const EdgeInsets.all(8.0), child: PlaylistCard(playlist), ), ) .toList(), ), ); }), ), ), ) ], ), ); } }