Skip to content

Commit

Permalink
feat(mobile): pull to refresh support in all refreshable list views
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Feb 3, 2023
1 parent 025c1ae commit 9f959ce
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 245 deletions.
4 changes: 3 additions & 1 deletion lib/collections/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';

abstract class Env {
static final String pocketbaseUrl =
dotenv.get('POCKETBASE_URL', fallback: 'http://localhost:8090');
dotenv.get('POCKETBASE_URL', fallback: 'http://127.0.0.1:8090');
static final String username = dotenv.get('USERNAME', fallback: 'root');
static final String password = dotenv.get('PASSWORD', fallback: '12345678');

static configure() async {
if (kReleaseMode) {
await dotenv.load(fileName: ".env");
} else {
dotenv.testLoad();
}
}
}
60 changes: 33 additions & 27 deletions lib/components/library/user_albums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,39 @@ class UserAlbums extends HookConsumerWidget {
return const Center(child: ShimmerPlaybuttonCard(count: 7));
}

return SingleChildScrollView(
child: Material(
type: MaterialType.transparency,
textStyle: PlatformTheme.of(context).textTheme!.body!,
color: PlatformTheme.of(context).scaffoldBackgroundColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
PlatformTextField(
onChanged: (value) => searchText.value = value,
prefixIcon: SpotubeIcons.filter,
placeholder: 'Filter Albums...',
),
const SizedBox(height: 20),
Wrap(
spacing: spacing, // gap between adjacent chips
runSpacing: 20, // gap between lines
alignment: WrapAlignment.center,
children: albums
.map((album) => AlbumCard(
viewType: viewType,
TypeConversionUtils.simpleAlbum_X_Album(album),
))
.toList(),
),
],
return RefreshIndicator(
onRefresh: () async {
await albumsQuery.refetch();
},
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Material(
type: MaterialType.transparency,
textStyle: PlatformTheme.of(context).textTheme!.body!,
color: PlatformTheme.of(context).scaffoldBackgroundColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
PlatformTextField(
onChanged: (value) => searchText.value = value,
prefixIcon: SpotubeIcons.filter,
placeholder: 'Filter Albums...',
),
const SizedBox(height: 20),
Wrap(
spacing: spacing, // gap between adjacent chips
runSpacing: 20, // gap between lines
alignment: WrapAlignment.center,
children: albums
.map((album) => AlbumCard(
viewType: viewType,
TypeConversionUtils.simpleAlbum_X_Album(album),
))
.toList(),
),
],
),
),
),
),
Expand Down
52 changes: 29 additions & 23 deletions lib/components/library/user_artists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,36 @@ class UserArtists extends HookConsumerWidget {
],
),
)
: GridView.builder(
itemCount: filteredArtists.length,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
mainAxisExtent: 250,
crossAxisSpacing: 20,
mainAxisSpacing: 20,
),
padding: const EdgeInsets.all(10),
itemBuilder: (context, index) {
return HookBuilder(builder: (context) {
if (index == artistQuery.pages.length - 1 && hasNextPage) {
return Waypoint(
controller: useScrollController(),
isGrid: true,
onTouchEdge: () {
artistQuery.fetchNextPage();
},
child: ArtistCard(filteredArtists[index]),
);
}
return ArtistCard(filteredArtists[index]);
});
: RefreshIndicator(
onRefresh: () async {
await artistQuery.refetchPages();
},
child: GridView.builder(
itemCount: filteredArtists.length,
physics: const AlwaysScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
mainAxisExtent: 250,
crossAxisSpacing: 20,
mainAxisSpacing: 20,
),
padding: const EdgeInsets.all(10),
itemBuilder: (context, index) {
return HookBuilder(builder: (context) {
if (index == artistQuery.pages.length - 1 && hasNextPage) {
return Waypoint(
controller: useScrollController(),
isGrid: true,
onTouchEdge: () {
artistQuery.fetchNextPage();
},
child: ArtistCard(filteredArtists[index]),
);
}
return ArtistCard(filteredArtists[index]);
});
},
),
),
);
}
Expand Down
50 changes: 27 additions & 23 deletions lib/components/library/user_local_tracks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:spotube/components/shared/shimmers/shimmer_track_tile.dart';
import 'package:spotube/components/shared/sort_tracks_dropdown.dart';
import 'package:spotube/components/shared/track_table/track_tile.dart';
import 'package:spotube/hooks/use_async_effect.dart';
import 'package:spotube/hooks/use_breakpoints.dart';
import 'package:spotube/models/local_track.dart';
import 'package:spotube/provider/playlist_queue_provider.dart';
import 'package:spotube/provider/user_preferences_provider.dart';
Expand Down Expand Up @@ -162,7 +161,6 @@ class UserLocalTracks extends HookConsumerWidget {
trackSnapshot.value ?? [],
);
final isMounted = useIsMounted();
final breakpoint = useBreakpoints();

final searchText = useState<String>("");

Expand Down Expand Up @@ -261,28 +259,34 @@ class UserLocalTracks extends HookConsumerWidget {
}, [searchText.value, sortedTracks]);

return Expanded(
child: ListView.builder(
itemCount: filteredTracks.length,
itemBuilder: (context, index) {
final track = filteredTracks[index];
return TrackTile(
playlist,
duration:
"${track.duration?.inMinutes.remainder(60)}:${PrimitiveUtils.zeroPadNumStr(track.duration?.inSeconds.remainder(60) ?? 0)}",
track: MapEntry(index, track),
isActive: playlist?.activeTrack.id == track.id,
isChecked: false,
showCheck: false,
isLocal: true,
onTrackPlayButtonPressed: (currentTrack) {
return playLocalTracks(
playlistNotifier,
sortedTracks,
currentTrack: track,
);
},
);
child: RefreshIndicator(
onRefresh: () async {
ref.refresh(localTracksProvider);
},
child: ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemCount: filteredTracks.length,
itemBuilder: (context, index) {
final track = filteredTracks[index];
return TrackTile(
playlist,
duration:
"${track.duration?.inMinutes.remainder(60)}:${PrimitiveUtils.zeroPadNumStr(track.duration?.inSeconds.remainder(60) ?? 0)}",
track: MapEntry(index, track),
isActive: playlist?.activeTrack.id == track.id,
isChecked: false,
showCheck: false,
isLocal: true,
onTrackPlayButtonPressed: (currentTrack) {
return playLocalTracks(
playlistNotifier,
sortedTracks,
currentTrack: track,
);
},
);
},
),
),
);
},
Expand Down
58 changes: 31 additions & 27 deletions lib/components/library/user_playlists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,38 @@ class UserPlaylists extends HookConsumerWidget {
))
.toList(),
];
return SingleChildScrollView(
child: Material(
type: MaterialType.transparency,
textStyle: PlatformTheme.of(context).textTheme!.body!,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
PlatformTextField(
onChanged: (value) => searchText.value = value,
placeholder: "Filter your playlists...",
prefixIcon: SpotubeIcons.filter,
),
const SizedBox(height: 20),
if (playlistsQuery.isLoading || !playlistsQuery.hasData)
const Center(child: ShimmerPlaybuttonCard(count: 7))
else
Center(
child: Wrap(
spacing: spacing, // gap between adjacent chips
runSpacing: 20, // gap between lines
alignment: breakpoint.isSm
? WrapAlignment.center
: WrapAlignment.start,
children: children,
),
return RefreshIndicator(
onRefresh: () => playlistsQuery.refetch(),
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Material(
type: MaterialType.transparency,
textStyle: PlatformTheme.of(context).textTheme!.body!,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
PlatformTextField(
onChanged: (value) => searchText.value = value,
placeholder: "Filter your playlists...",
prefixIcon: SpotubeIcons.filter,
),
],
const SizedBox(height: 20),
if (playlistsQuery.isLoading || !playlistsQuery.hasData)
const Center(child: ShimmerPlaybuttonCard(count: 7))
else
Center(
child: Wrap(
spacing: spacing, // gap between adjacent chips
runSpacing: 20, // gap between lines
alignment: breakpoint.isSm
? WrapAlignment.center
: WrapAlignment.start,
children: children,
),
),
],
),
),
),
),
Expand Down
Loading

0 comments on commit 9f959ce

Please sign in to comment.