mirror of
https://github.com/KRTirtho/spotube.git
synced 2026-05-08 16:24:36 +00:00
fix: remove direct access to provider.value
This commit is contained in:
parent
51710d5aee
commit
aea4bd7d16
@ -18,10 +18,10 @@ class HomeFeaturedSection extends HookConsumerWidget {
|
||||
return Skeletonizer(
|
||||
enabled: featuredPlaylists.isLoadingAndEmpty,
|
||||
child: HorizontalPlaybuttonCardView<PlaylistSimple>(
|
||||
items: featuredPlaylists.value?.items ?? [],
|
||||
items: featuredPlaylists.asData?.value.items ?? [],
|
||||
title: Text(context.l10n.featured),
|
||||
isLoadingNextPage: featuredPlaylists.isLoadingNextPage,
|
||||
hasNextPage: featuredPlaylists.value?.hasMore ?? false,
|
||||
hasNextPage: featuredPlaylists.asData?.value.hasMore ?? false,
|
||||
onFetchMore: featuredPlaylistsNotifier.fetchMore,
|
||||
),
|
||||
);
|
||||
|
||||
@ -15,7 +15,8 @@ class HomePageFriendsSection extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, ref) {
|
||||
final friendsQuery = ref.watch(friendsProvider);
|
||||
final friends = friendsQuery.value?.friends ?? FakeData.friends.friends;
|
||||
final friends =
|
||||
friendsQuery.asData?.value.friends ?? FakeData.friends.friends;
|
||||
|
||||
final groupCount = useBreakpointValue(
|
||||
sm: 3,
|
||||
@ -50,7 +51,8 @@ class HomePageFriendsSection extends HookConsumerWidget {
|
||||
},
|
||||
);
|
||||
|
||||
if (friendsQuery.isLoading || friendsQuery.value?.friends.isEmpty == true) {
|
||||
if (friendsQuery.isLoading ||
|
||||
friendsQuery.asData?.value.friends.isEmpty == true) {
|
||||
return const SliverToBoxAdapter(
|
||||
child: SizedBox.shrink(),
|
||||
);
|
||||
|
||||
@ -20,7 +20,7 @@ class HomeNewReleasesSection extends HookConsumerWidget {
|
||||
|
||||
if (auth == null ||
|
||||
newReleases.isLoading ||
|
||||
newReleases.value?.items.isEmpty == true) {
|
||||
newReleases.asData?.value.items.isEmpty == true) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ class HomeNewReleasesSection extends HookConsumerWidget {
|
||||
items: albums,
|
||||
title: Text(context.l10n.new_releases),
|
||||
isLoadingNextPage: newReleases.isLoadingNextPage,
|
||||
hasNextPage: newReleases.value?.hasMore ?? false,
|
||||
hasNextPage: newReleases.asData?.value.hasMore ?? false,
|
||||
onFetchMore: newReleasesNotifier.fetchMore,
|
||||
);
|
||||
}
|
||||
|
||||
@ -33,9 +33,9 @@ class UserAlbums extends HookConsumerWidget {
|
||||
|
||||
final albums = useMemoized(() {
|
||||
if (searchText.value.isEmpty) {
|
||||
return albumsQuery.value?.items ?? [];
|
||||
return albumsQuery.asData?.value.items ?? [];
|
||||
}
|
||||
return albumsQuery.value?.items
|
||||
return albumsQuery.asData?.value.items
|
||||
.map((e) => (
|
||||
weightedRatio(e.name!, searchText.value),
|
||||
e,
|
||||
@ -104,7 +104,7 @@ class UserAlbums extends HookConsumerWidget {
|
||||
TypeConversionUtils.simpleAlbum_X_Album(album),
|
||||
),
|
||||
if (albums.isNotEmpty &&
|
||||
albumsQuery.value?.hasMore == true)
|
||||
albumsQuery.asData?.value.hasMore == true)
|
||||
Waypoint(
|
||||
controller: controller,
|
||||
isGrid: true,
|
||||
|
||||
@ -28,7 +28,7 @@ class UserArtists extends HookConsumerWidget {
|
||||
final searchText = useState('');
|
||||
|
||||
final filteredArtists = useMemoized(() {
|
||||
final artists = artistQuery.value?.items ?? [];
|
||||
final artists = artistQuery.asData?.value.items ?? [];
|
||||
|
||||
if (searchText.value.isEmpty) {
|
||||
return artists.toList();
|
||||
@ -42,7 +42,7 @@ class UserArtists extends HookConsumerWidget {
|
||||
.where((e) => e.$1 > 50)
|
||||
.map((e) => e.$2)
|
||||
.toList();
|
||||
}, [artistQuery.value?.items, searchText.value]);
|
||||
}, [artistQuery.asData?.value.items, searchText.value]);
|
||||
|
||||
final controller = useScrollController();
|
||||
|
||||
@ -66,7 +66,7 @@ class UserArtists extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
body: artistQuery.value?.items.isEmpty == true
|
||||
body: artistQuery.asData?.value.items.isEmpty == true
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
|
||||
@ -178,7 +178,7 @@ class UserLocalTracks extends HookConsumerWidget {
|
||||
FilledButton(
|
||||
onPressed: trackSnapshot.value != null
|
||||
? () async {
|
||||
if (trackSnapshot.value?.isNotEmpty == true) {
|
||||
if (trackSnapshot.asData?.value.isNotEmpty == true) {
|
||||
if (!isPlaylistPlaying) {
|
||||
await playLocalTracks(
|
||||
ref,
|
||||
|
||||
@ -54,12 +54,12 @@ class UserPlaylists extends HookConsumerWidget {
|
||||
if (searchText.value.isEmpty) {
|
||||
return [
|
||||
likedTracksPlaylist,
|
||||
...?playlistsQuery.value?.items,
|
||||
...?playlistsQuery.asData?.value.items,
|
||||
];
|
||||
}
|
||||
return [
|
||||
likedTracksPlaylist,
|
||||
...?playlistsQuery.value?.items,
|
||||
...?playlistsQuery.asData?.value.items,
|
||||
]
|
||||
.map((e) => (weightedRatio(e.name!, searchText.value), e))
|
||||
.sorted((a, b) => b.$1.compareTo(a.$1))
|
||||
@ -130,7 +130,7 @@ class UserPlaylists extends HookConsumerWidget {
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
if (playlists.isNotEmpty && index == playlists.length) {
|
||||
if (playlistsQuery.value?.hasMore != true) {
|
||||
if (playlistsQuery.asData?.value.hasMore != true) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ class PlaylistCard extends HookConsumerWidget {
|
||||
final playlistNotifier = ref.watch(ProxyPlaylistNotifier.notifier);
|
||||
final playing =
|
||||
useStream(audioPlayer.playingStream).data ?? audioPlayer.isPlaying;
|
||||
final tracks = useState<List<TrackSimple>?>(null);
|
||||
bool isPlaylistPlaying = useMemoized(
|
||||
() => playlistQueue.containsCollection(playlist.id!),
|
||||
[playlistQueue, playlist.id],
|
||||
@ -51,7 +50,8 @@ class PlaylistCard extends HookConsumerWidget {
|
||||
isPlaying: isPlaylistPlaying,
|
||||
isLoading:
|
||||
(isPlaylistPlaying && playlistQueue.isFetching) || updating.value,
|
||||
isOwner: playlist.owner?.id == me.value?.id && me.value?.id != null,
|
||||
isOwner: playlist.owner?.id == me.asData?.value.id &&
|
||||
me.asData?.value.id != null,
|
||||
onTap: () {
|
||||
ServiceUtils.push(
|
||||
context,
|
||||
@ -74,7 +74,6 @@ class PlaylistCard extends HookConsumerWidget {
|
||||
|
||||
await playlistNotifier.load(fetchedTracks, autoPlay: true);
|
||||
playlistNotifier.addCollection(playlist.id!);
|
||||
tracks.value = fetchedTracks;
|
||||
} finally {
|
||||
if (context.mounted) {
|
||||
updating.value = false;
|
||||
@ -92,10 +91,9 @@ class PlaylistCard extends HookConsumerWidget {
|
||||
|
||||
playlistNotifier.addTracks(fetchedTracks);
|
||||
playlistNotifier.addCollection(playlist.id!);
|
||||
tracks.value = fetchedTracks;
|
||||
if (context.mounted) {
|
||||
final snackbar = SnackBar(
|
||||
content: Text("Added ${tracks.value?.length} tracks to queue"),
|
||||
content: Text("Added ${fetchedTracks.length} tracks to queue"),
|
||||
action: SnackBarAction(
|
||||
label: "Undo",
|
||||
onPressed: () {
|
||||
|
||||
@ -65,7 +65,9 @@ UseTrackToggleLike useTrackToggleLike(Track track, WidgetRef ref) {
|
||||
final savedTracksNotifier = ref.watch(likedTracksProvider.notifier);
|
||||
|
||||
final isLiked = useMemoized(
|
||||
() => savedTracks.value?.any((element) => element.id == track.id) ?? false,
|
||||
() =>
|
||||
savedTracks.asData?.value.any((element) => element.id == track.id) ??
|
||||
false,
|
||||
[savedTracks.value, track.id],
|
||||
);
|
||||
|
||||
|
||||
@ -8,10 +8,10 @@ bool useIsUserPlaylist(WidgetRef ref, String playlistId) {
|
||||
|
||||
return useMemoized(
|
||||
() =>
|
||||
userPlaylistsQuery.value?.items.any((e) =>
|
||||
userPlaylistsQuery.asData?.value.items.any((e) =>
|
||||
e.id == playlistId &&
|
||||
me.value != null &&
|
||||
e.owner?.id == me.value?.id) ??
|
||||
e.owner?.id == me.asData?.value.id) ??
|
||||
false,
|
||||
[userPlaylistsQuery.value, playlistId, me.value],
|
||||
);
|
||||
|
||||
@ -30,9 +30,9 @@ class AlbumPage extends HookConsumerWidget {
|
||||
title: album.name!,
|
||||
description:
|
||||
"${context.l10n.released} • ${album.releaseDate} • ${album.artists!.first.name}",
|
||||
tracks: tracks.value?.items ?? [],
|
||||
tracks: tracks.asData?.value.items ?? [],
|
||||
pagination: PaginationProps(
|
||||
hasNextPage: tracks.value?.hasMore ?? false,
|
||||
hasNextPage: tracks.asData?.value.hasMore ?? false,
|
||||
isLoading: tracks.isLoading,
|
||||
onFetchMore: () async {
|
||||
await tracksNotifier.fetchMore();
|
||||
|
||||
@ -82,7 +82,7 @@ class ArtistPageFooter extends ConsumerWidget {
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () async {
|
||||
await launchUrlString(
|
||||
"http://en.wikipedia.org/wiki?curid=${summary.value?.pageid}",
|
||||
"http://en.wikipedia.org/wiki?curid=${summary.asData?.value?.pageid}",
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@ -94,7 +94,7 @@ class GenrePlaylistsPage extends HookConsumerWidget {
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: mediaQuery.mdAndDown ? 12 : 24,
|
||||
),
|
||||
sliver: playlists.value?.items.isNotEmpty != true
|
||||
sliver: playlists.asData?.value.items.isNotEmpty != true
|
||||
? Skeletonizer.sliver(
|
||||
child: SliverToBoxAdapter(
|
||||
child: Wrap(
|
||||
@ -114,13 +114,14 @@ class GenrePlaylistsPage extends HookConsumerWidget {
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: (playlists.value?.items.length ?? 0) + 1,
|
||||
itemCount:
|
||||
(playlists.asData?.value.items.length ?? 0) + 1,
|
||||
itemBuilder: (context, index) {
|
||||
final playlist =
|
||||
playlists.value?.items.elementAtOrNull(index);
|
||||
final playlist = playlists.asData?.value.items
|
||||
.elementAtOrNull(index);
|
||||
|
||||
if (playlist == null) {
|
||||
if (playlists.value?.hasMore == false) {
|
||||
if (playlists.asData?.value.hasMore == false) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Skeletonizer(
|
||||
|
||||
@ -30,7 +30,7 @@ class PlaylistGenerateResultPage extends HookConsumerWidget {
|
||||
final generatedPlaylist = ref.watch(generatePlaylistProvider(state));
|
||||
|
||||
final selectedTracks = useState<List<String>>(
|
||||
generatedPlaylist.value?.map((e) => e.id!).toList() ?? [],
|
||||
generatedPlaylist.asData?.value.map((e) => e.id!).toList() ?? [],
|
||||
);
|
||||
|
||||
useEffect(() {
|
||||
@ -41,8 +41,8 @@ class PlaylistGenerateResultPage extends HookConsumerWidget {
|
||||
return null;
|
||||
}, [generatedPlaylist.value]);
|
||||
|
||||
final isAllTrackSelected =
|
||||
selectedTracks.value.length == (generatedPlaylist.value?.length ?? 0);
|
||||
final isAllTrackSelected = selectedTracks.value.length ==
|
||||
(generatedPlaylist.asData?.value.length ?? 0);
|
||||
|
||||
return Scaffold(
|
||||
appBar: const PageWindowTitleBar(leading: BackButton()),
|
||||
|
||||
@ -95,9 +95,9 @@ class PlainLyrics extends HookConsumerWidget {
|
||||
}
|
||||
|
||||
final lyrics =
|
||||
lyricsQuery.value?.lyrics.mapIndexed((i, e) {
|
||||
final next =
|
||||
lyricsQuery.value?.lyrics.elementAtOrNull(i + 1);
|
||||
lyricsQuery.asData?.value.lyrics.mapIndexed((i, e) {
|
||||
final next = lyricsQuery.asData?.value.lyrics
|
||||
.elementAtOrNull(i + 1);
|
||||
if (next != null &&
|
||||
e.time - next.time >
|
||||
const Duration(milliseconds: 700)) {
|
||||
|
||||
@ -35,7 +35,7 @@ class PlaylistPage extends HookConsumerWidget {
|
||||
placeholder: ImagePlaceholder.collection,
|
||||
),
|
||||
pagination: PaginationProps(
|
||||
hasNextPage: tracks.value?.hasMore ?? false,
|
||||
hasNextPage: tracks.asData?.value.hasMore ?? false,
|
||||
isLoading: tracks.isLoading,
|
||||
onFetchMore: tracksNotifier.fetchMore,
|
||||
onRefresh: () async {
|
||||
@ -47,7 +47,7 @@ class PlaylistPage extends HookConsumerWidget {
|
||||
),
|
||||
title: playlist.name!,
|
||||
description: playlist.description,
|
||||
tracks: tracks.value?.items ?? [],
|
||||
tracks: tracks.asData?.value.items ?? [],
|
||||
routePath: '/playlist/${playlist.id}',
|
||||
isLiked: isFavoritePlaylist.value ?? false,
|
||||
shareUrl: playlist.externalUrls?.spotify ?? "",
|
||||
|
||||
@ -19,7 +19,7 @@ class SearchAlbumsSection extends HookConsumerWidget {
|
||||
final notifier = ref.watch(searchProvider(SearchType.album).notifier);
|
||||
final albums = useMemoized(
|
||||
() =>
|
||||
query.value?.items
|
||||
query.asData?.value.items
|
||||
.cast<AlbumSimple>()
|
||||
.map(TypeConversionUtils.simpleAlbum_X_Album)
|
||||
.toList() ??
|
||||
@ -29,7 +29,7 @@ class SearchAlbumsSection extends HookConsumerWidget {
|
||||
|
||||
return HorizontalPlaybuttonCardView(
|
||||
isLoadingNextPage: query.isLoadingNextPage,
|
||||
hasNextPage: query.value?.hasMore == true,
|
||||
hasNextPage: query.asData?.value.hasMore == true,
|
||||
items: albums,
|
||||
onFetchMore: notifier.fetchMore,
|
||||
title: Text(context.l10n.albums),
|
||||
|
||||
@ -16,11 +16,11 @@ class SearchArtistsSection extends HookConsumerWidget {
|
||||
final query = ref.watch(searchProvider(SearchType.artist));
|
||||
final notifier = ref.watch(searchProvider(SearchType.artist).notifier);
|
||||
|
||||
final artists = query.value?.items.cast<Artist>() ?? [];
|
||||
final artists = query.asData?.value.items.cast<Artist>() ?? [];
|
||||
|
||||
return HorizontalPlaybuttonCardView<Artist>(
|
||||
isLoadingNextPage: query.isLoadingNextPage,
|
||||
hasNextPage: query.value?.hasMore == true,
|
||||
hasNextPage: query.asData?.value.hasMore == true,
|
||||
items: artists,
|
||||
onFetchMore: notifier.fetchMore,
|
||||
title: Text(context.l10n.artists),
|
||||
|
||||
@ -15,11 +15,12 @@ class SearchPlaylistsSection extends HookConsumerWidget {
|
||||
final playlistsQuery = ref.watch(searchProvider(SearchType.playlist));
|
||||
final playlistsQueryNotifier =
|
||||
ref.watch(searchProvider(SearchType.playlist).notifier);
|
||||
final playlists = playlistsQuery.value?.items.cast<PlaylistSimple>() ?? [];
|
||||
final playlists =
|
||||
playlistsQuery.asData?.value.items.cast<PlaylistSimple>() ?? [];
|
||||
|
||||
return HorizontalPlaybuttonCardView(
|
||||
isLoadingNextPage: playlistsQuery.isLoadingNextPage,
|
||||
hasNextPage: playlistsQuery.value?.hasMore == true,
|
||||
hasNextPage: playlistsQuery.asData?.value.hasMore == true,
|
||||
items: playlists,
|
||||
onFetchMore: playlistsQueryNotifier.fetchMore,
|
||||
title: Text(context.l10n.playlists),
|
||||
|
||||
@ -20,7 +20,7 @@ class SearchTracksSection extends HookConsumerWidget {
|
||||
final searchTrackNotifier =
|
||||
ref.watch(searchProvider(SearchType.track).notifier);
|
||||
|
||||
final tracks = searchTrack.value?.items.cast<Track>() ?? [];
|
||||
final tracks = searchTrack.asData?.value.items.cast<Track>() ?? [];
|
||||
final playlistNotifier = ref.watch(ProxyPlaylistNotifier.provider.notifier);
|
||||
final playlist = ref.watch(ProxyPlaylistNotifier.provider);
|
||||
final theme = Theme.of(context);
|
||||
@ -71,7 +71,7 @@ class SearchTracksSection extends HookConsumerWidget {
|
||||
},
|
||||
);
|
||||
}),
|
||||
if (searchTrack.value?.hasMore == true && tracks.isNotEmpty)
|
||||
if (searchTrack.asData?.value.hasMore == true && tracks.isNotEmpty)
|
||||
Center(
|
||||
child: TextButton(
|
||||
onPressed: searchTrack.isLoadingNextPage
|
||||
|
||||
@ -75,9 +75,9 @@ final userArtistAlbumReleasesProvider = Provider<List<Album>>((ref) {
|
||||
}
|
||||
|
||||
final userArtists =
|
||||
userArtistsQuery.value?.map((s) => s.id!).toList() ?? const [];
|
||||
userArtistsQuery.asData?.value.map((s) => s.id!).toList() ?? const [];
|
||||
|
||||
final allReleases = newReleases.value?.items;
|
||||
final allReleases = newReleases.asData?.value.items;
|
||||
final userArtistReleases = allReleases?.where((album) {
|
||||
return album.artists?.any((artist) => userArtists.contains(artist.id!)) ==
|
||||
true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user