mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-17 01:15:17 +00:00

commit e160d4f561ff2e945fd67bf12b223c012da58b1e Author: Kingkor Roy Tirtho <krtirtho@gmail.com> Date: Sat Sep 14 10:48:08 2024 +0600 fix: pagination issues in playlist and album pages
69 lines
1.6 KiB
Dart
69 lines
1.6 KiB
Dart
part of '../spotify.dart';
|
|
|
|
class ArtistAlbumsState extends PaginatedState<Album> {
|
|
ArtistAlbumsState({
|
|
required super.items,
|
|
required super.offset,
|
|
required super.limit,
|
|
required super.hasMore,
|
|
});
|
|
|
|
@override
|
|
ArtistAlbumsState copyWith({
|
|
List<Album>? items,
|
|
int? offset,
|
|
int? limit,
|
|
bool? hasMore,
|
|
}) {
|
|
return ArtistAlbumsState(
|
|
items: items ?? this.items,
|
|
offset: offset ?? this.offset,
|
|
limit: limit ?? this.limit,
|
|
hasMore: hasMore ?? this.hasMore,
|
|
);
|
|
}
|
|
}
|
|
|
|
class ArtistAlbumsNotifier extends AutoDisposeFamilyPaginatedAsyncNotifier<
|
|
Album, ArtistAlbumsState, String> {
|
|
ArtistAlbumsNotifier() : super();
|
|
|
|
@override
|
|
fetch(arg, offset, limit) async {
|
|
final market = ref.read(userPreferencesProvider).market;
|
|
final albums = await spotify.artists
|
|
.albums(arg, country: market)
|
|
.getPage(limit, offset);
|
|
|
|
final items = albums.items?.toList() ?? [];
|
|
|
|
return (
|
|
items: items,
|
|
hasMore: !albums.isLast,
|
|
nextOffset: albums.nextOffset,
|
|
);
|
|
}
|
|
|
|
@override
|
|
build(arg) async {
|
|
ref.cacheFor();
|
|
|
|
ref.watch(spotifyProvider);
|
|
ref.watch(
|
|
userPreferencesProvider.select((s) => s.market),
|
|
);
|
|
final (:items, :hasMore, :nextOffset) = await fetch(arg, 0, 20);
|
|
return ArtistAlbumsState(
|
|
items: items,
|
|
offset: nextOffset,
|
|
limit: 20,
|
|
hasMore: hasMore,
|
|
);
|
|
}
|
|
}
|
|
|
|
final artistAlbumsProvider = AutoDisposeAsyncNotifierProviderFamily<
|
|
ArtistAlbumsNotifier, ArtistAlbumsState, String>(
|
|
() => ArtistAlbumsNotifier(),
|
|
);
|