-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented go_route shell/nested route
BRIEF DESCRIPTION: - Nested Routes like React-Router/Spotify Web/desktop - Except Login routes everything is nested and wrapped by a Shell - PlayerOverlay is no more a overlay A really simple Sidebar now
- Loading branch information
Showing
24 changed files
with
691 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:fl_query_hooks/fl_query_hooks.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:spotify/spotify.dart'; | ||
import 'package:spotube/components/Category/CategoryCard.dart'; | ||
import 'package:spotube/components/LoaderShimmers/ShimmerCategories.dart'; | ||
import 'package:spotube/components/Shared/Waypoint.dart'; | ||
import 'package:spotube/provider/SpotifyDI.dart'; | ||
import 'package:spotube/provider/SpotifyRequests.dart'; | ||
import 'package:spotube/provider/UserPreferences.dart'; | ||
|
||
class Genres extends HookConsumerWidget { | ||
const Genres({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context, ref) { | ||
final spotify = ref.watch(spotifyProvider); | ||
final recommendationMarket = ref.watch( | ||
userPreferencesProvider.select((s) => s.recommendationMarket), | ||
); | ||
final categoriesQuery = useInfiniteQuery( | ||
job: categoriesQueryJob, | ||
externalData: { | ||
"spotify": spotify, | ||
"recommendationMarket": recommendationMarket, | ||
}, | ||
); | ||
final categories = [ | ||
useMemoized( | ||
() => Category() | ||
..id = "user-featured-playlists" | ||
..name = "Featured", | ||
[], | ||
), | ||
...categoriesQuery.pages | ||
.expand<Category?>( | ||
(page) => page?.items ?? const Iterable.empty(), | ||
) | ||
.toList() | ||
]; | ||
|
||
return Scaffold( | ||
body: ListView.builder( | ||
itemCount: categories.length, | ||
itemBuilder: (context, index) { | ||
final category = categories[index]; | ||
if (category == null) return Container(); | ||
if (index == categories.length - 1) { | ||
return Waypoint( | ||
onEnter: () { | ||
if (categoriesQuery.hasNextPage) { | ||
categoriesQuery.fetchNextPage(); | ||
} | ||
}, | ||
child: const ShimmerCategories(), | ||
); | ||
} | ||
return CategoryCard(category); | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:spotube/components/Home/Sidebar.dart'; | ||
import 'package:spotube/components/Home/SpotubeNavigationBar.dart'; | ||
import 'package:spotube/components/Player/Player.dart'; | ||
import 'package:spotube/components/Shared/PageWindowTitleBar.dart'; | ||
import 'package:spotube/components/Shared/ReplaceDownloadedFileDialog.dart'; | ||
import 'package:spotube/hooks/useUpdateChecker.dart'; | ||
import 'package:spotube/provider/Downloader.dart'; | ||
|
||
const _path = { | ||
0: "/", | ||
1: "/search", | ||
2: "/library", | ||
3: "/lyrics", | ||
}; | ||
|
||
class Shell extends HookConsumerWidget { | ||
final Widget child; | ||
const Shell({ | ||
required this.child, | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context, ref) { | ||
final index = useState(0); | ||
final isMounted = useIsMounted(); | ||
|
||
final downloader = ref.watch(downloaderProvider); | ||
useEffect(() { | ||
downloader.onFileExists = (track) async { | ||
if (!isMounted()) return false; | ||
return await showDialog<bool>( | ||
context: context, | ||
builder: (context) => ReplaceDownloadedFileDialog( | ||
track: track, | ||
), | ||
) ?? | ||
false; | ||
}; | ||
return null; | ||
}, [downloader]); | ||
|
||
// checks for latest version of the application | ||
useUpdateChecker(ref); | ||
|
||
final backgroundColor = Theme.of(context).backgroundColor; | ||
|
||
useEffect(() { | ||
SystemChrome.setSystemUIOverlayStyle( | ||
SystemUiOverlayStyle( | ||
statusBarColor: backgroundColor, // status bar color | ||
statusBarIconBrightness: backgroundColor.computeLuminance() > 0.179 | ||
? Brightness.dark | ||
: Brightness.light, | ||
), | ||
); | ||
return null; | ||
}, [backgroundColor]); | ||
|
||
const pageWindowTitleBar = PageWindowTitleBar(); | ||
return Scaffold( | ||
primary: true, | ||
appBar: _path.values.contains(GoRouter.of(context).location) | ||
? pageWindowTitleBar | ||
: null, | ||
extendBodyBehindAppBar: true, | ||
body: Row( | ||
children: [ | ||
Sidebar( | ||
selectedIndex: index.value, | ||
onSelectedIndexChanged: (selectedIndex) { | ||
index.value = selectedIndex; | ||
GoRouter.of(context).go(_path[selectedIndex]!); | ||
}, | ||
), | ||
Expanded( | ||
child: Column( | ||
children: [ | ||
Expanded(child: child), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
extendBody: true, | ||
bottomNavigationBar: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Player(), | ||
SpotubeNavigationBar( | ||
selectedIndex: index.value, | ||
onSelectedIndexChanged: (selectedIndex) { | ||
index.value = selectedIndex; | ||
GoRouter.of(context).go(_path[selectedIndex]!); | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.