mirror of
https://github.com/KRTirtho/spotube.git
synced 2026-05-08 16:24:36 +00:00
fix: glitching when loading
This commit is contained in:
parent
aea4bd7d16
commit
3081237999
@ -13,10 +13,10 @@ class HomeFeaturedSection extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, ref) {
|
||||
final featuredPlaylists = ref.watch(featuredPlaylistsProvider);
|
||||
final featuredPlaylistsNotifier =
|
||||
ref.read(featuredPlaylistsProvider.notifier);
|
||||
ref.watch(featuredPlaylistsProvider.notifier);
|
||||
|
||||
return Skeletonizer(
|
||||
enabled: featuredPlaylists.isLoadingAndEmpty,
|
||||
enabled: featuredPlaylists.isLoading,
|
||||
child: HorizontalPlaybuttonCardView<PlaylistSimple>(
|
||||
items: featuredPlaylists.asData?.value.items ?? [],
|
||||
title: Text(context.l10n.featured),
|
||||
|
||||
@ -80,7 +80,7 @@ class UserAlbums extends HookConsumerWidget {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
controller: controller,
|
||||
child: Skeletonizer(
|
||||
enabled: albumsQuery.isLoadingAndEmpty,
|
||||
enabled: albumsQuery.isLoading,
|
||||
child: Center(
|
||||
child: Wrap(
|
||||
runSpacing: 20,
|
||||
|
||||
@ -84,11 +84,11 @@ class HorizontalPlaybuttonCardView<T> extends HookWidget {
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
|
||||
return switch (item.runtimeType) {
|
||||
PlaylistSimple =>
|
||||
return switch (item) {
|
||||
PlaylistSimple() =>
|
||||
PlaylistCard(item as PlaylistSimple),
|
||||
Album => AlbumCard(item as Album),
|
||||
Artist => Padding(
|
||||
Album() => AlbumCard(item as Album),
|
||||
Artist() => Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12.0),
|
||||
child: ArtistCard(item as Artist),
|
||||
|
||||
@ -33,7 +33,7 @@ class AlbumPage extends HookConsumerWidget {
|
||||
tracks: tracks.asData?.value.items ?? [],
|
||||
pagination: PaginationProps(
|
||||
hasNextPage: tracks.asData?.value.hasMore ?? false,
|
||||
isLoading: tracks.isLoading,
|
||||
isLoading: tracks.isLoadingNextPage,
|
||||
onFetchMore: () async {
|
||||
await tracksNotifier.fetchMore();
|
||||
},
|
||||
|
||||
@ -39,7 +39,7 @@ class ArtistPage extends HookConsumerWidget {
|
||||
return Center(child: Text(artistQuery.error.toString()));
|
||||
}
|
||||
return Skeletonizer(
|
||||
enabled: artistQuery.isLoadingAndEmpty,
|
||||
enabled: artistQuery.isLoading,
|
||||
child: CustomScrollView(
|
||||
controller: scrollController,
|
||||
slivers: [
|
||||
|
||||
@ -36,7 +36,7 @@ class PlaylistPage extends HookConsumerWidget {
|
||||
),
|
||||
pagination: PaginationProps(
|
||||
hasNextPage: tracks.asData?.value.hasMore ?? false,
|
||||
isLoading: tracks.isLoading,
|
||||
isLoading: tracks.isLoadingNextPage,
|
||||
onFetchMore: tracksNotifier.fetchMore,
|
||||
onRefresh: () async {
|
||||
ref.invalidate(playlistTracksProvider(playlist.id!));
|
||||
|
||||
@ -37,7 +37,7 @@ class SearchTracksSection extends HookConsumerWidget {
|
||||
style: theme.textTheme.titleLarge!,
|
||||
),
|
||||
),
|
||||
if (searchTrack.isLoadingAndEmpty)
|
||||
if (searchTrack.isLoading)
|
||||
const CircularProgressIndicator()
|
||||
else if (searchTrack.hasError)
|
||||
Text(searchTrack.error.toString())
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
part of '../spotify.dart';
|
||||
|
||||
extension PaginationExtension<T> on AsyncValue<T> {
|
||||
bool get isLoadingAndEmpty => value == null && isLoading;
|
||||
bool get isLoadingNextPage => value != null && isLoading;
|
||||
bool get isLoadingNextPage => this is AsyncData && this is AsyncLoadingNext;
|
||||
}
|
||||
|
||||
@ -1,17 +1,25 @@
|
||||
part of '../spotify.dart';
|
||||
|
||||
// ignore: subtype_of_sealed_class
|
||||
class AsyncLoadingNext<T> extends AsyncData<T> {
|
||||
const AsyncLoadingNext(super.value);
|
||||
}
|
||||
|
||||
abstract class PaginatedAsyncNotifier<K, T extends BasePaginatedState<K, int>>
|
||||
extends AsyncNotifier<T> with SpotifyMixin<T> {
|
||||
Future<List<K>> fetch(int offset, int limit);
|
||||
|
||||
Future<void> fetchMore() async {
|
||||
if (state.value == null || !state.value!.hasMore) return;
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
state = AsyncLoadingNext(state.asData!.value);
|
||||
|
||||
state = await AsyncValue.guard(
|
||||
() async {
|
||||
final items = await fetch(
|
||||
state.value!.offset + state.value!.limit, state.value!.limit);
|
||||
state.value!.offset + state.value!.limit,
|
||||
state.value!.limit,
|
||||
);
|
||||
return state.value!.copyWith(
|
||||
hasMore: items.length == state.value!.limit,
|
||||
items: [
|
||||
@ -57,7 +65,7 @@ abstract class CursorPaginatedAsyncNotifier<K,
|
||||
Future<void> fetchMore() async {
|
||||
if (state.value == null || !state.value!.hasMore) return;
|
||||
|
||||
state = const AsyncValue.loading();
|
||||
state = AsyncLoadingNext(state.asData!.value);
|
||||
|
||||
state = await AsyncValue.guard(
|
||||
() async {
|
||||
@ -105,7 +113,7 @@ abstract class FamilyPaginatedAsyncNotifier<
|
||||
Future<void> fetchMore() async {
|
||||
if (state.value == null || !state.value!.hasMore) return;
|
||||
|
||||
state = const AsyncLoading();
|
||||
state = AsyncLoadingNext(state.asData!.value);
|
||||
|
||||
state = await AsyncValue.guard(
|
||||
() async {
|
||||
@ -165,7 +173,7 @@ abstract class FamilyCursorPaginatedAsyncNotifier<
|
||||
Future<void> fetchMore() async {
|
||||
if (state.value == null || !state.value!.hasMore) return;
|
||||
|
||||
state = const AsyncLoading();
|
||||
state = AsyncLoadingNext(state.asData!.value);
|
||||
|
||||
state = await AsyncValue.guard(
|
||||
() async {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user