From 36c5e02f18374100f61cc3f2957c27bfc0d8511f Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 4 Nov 2022 12:09:27 +0600 Subject: [PATCH] feat: change default platform option and platform specific back button --- lib/components/Artist/ArtistProfile.dart | 2 +- lib/components/Login/TokenLogin.dart | 2 +- lib/components/Player/PlayerView.dart | 2 +- .../Playlist/PlaylistGenreView.dart | 2 +- lib/components/Settings/Settings.dart | 37 +++++++++++++++++++ lib/components/Shared/AdaptiveListTile.dart | 1 + .../Shared/TrackCollectionView.dart | 4 +- lib/main.dart | 14 ++++++- 8 files changed, 58 insertions(+), 6 deletions(-) diff --git a/lib/components/Artist/ArtistProfile.dart b/lib/components/Artist/ArtistProfile.dart index b16d011a9..bf9150c19 100644 --- a/lib/components/Artist/ArtistProfile.dart +++ b/lib/components/Artist/ArtistProfile.dart @@ -55,7 +55,7 @@ class ArtistProfile extends HookConsumerWidget { return SafeArea( child: PlatformScaffold( appBar: const PageWindowTitleBar( - leading: BackButton(), + leading: PlatformBackButton(), ), body: HookBuilder( builder: (context) { diff --git a/lib/components/Login/TokenLogin.dart b/lib/components/Login/TokenLogin.dart index e7a816578..ad5b51d73 100644 --- a/lib/components/Login/TokenLogin.dart +++ b/lib/components/Login/TokenLogin.dart @@ -16,7 +16,7 @@ class TokenLogin extends HookConsumerWidget { return SafeArea( child: Scaffold( - appBar: const PageWindowTitleBar(leading: BackButton()), + appBar: const PageWindowTitleBar(leading: PlatformBackButton()), body: SingleChildScrollView( child: Center( child: Container( diff --git a/lib/components/Player/PlayerView.dart b/lib/components/Player/PlayerView.dart index 15bcb0710..0878a2967 100644 --- a/lib/components/Player/PlayerView.dart +++ b/lib/components/Player/PlayerView.dart @@ -75,7 +75,7 @@ class PlayerView extends HookConsumerWidget { child: Column( children: [ PageWindowTitleBar( - leading: const BackButton(), + leading: const PlatformBackButton(), backgroundColor: Colors.transparent, foregroundColor: paletteColor.titleTextColor, ), diff --git a/lib/components/Playlist/PlaylistGenreView.dart b/lib/components/Playlist/PlaylistGenreView.dart index a9191b6a3..94fb89c5f 100644 --- a/lib/components/Playlist/PlaylistGenreView.dart +++ b/lib/components/Playlist/PlaylistGenreView.dart @@ -21,7 +21,7 @@ class PlaylistGenreView extends ConsumerWidget { Widget build(BuildContext context, ref) { return Scaffold( appBar: const PageWindowTitleBar( - leading: BackButton(), + leading: PlatformBackButton(), ), body: Column( children: [ diff --git a/lib/components/Settings/Settings.dart b/lib/components/Settings/Settings.dart index 908c13300..1049365f9 100644 --- a/lib/components/Settings/Settings.dart +++ b/lib/components/Settings/Settings.dart @@ -10,6 +10,7 @@ import 'package:spotube/components/Settings/ColorSchemePickerDialog.dart'; import 'package:spotube/components/Shared/AdaptiveListTile.dart'; import 'package:spotube/components/Shared/PageWindowTitleBar.dart'; import 'package:spotube/hooks/useBreakpoints.dart'; +import 'package:spotube/main.dart'; import 'package:spotube/models/SpotifyMarkets.dart'; import 'package:spotube/models/SpotubeTrack.dart'; import 'package:spotube/provider/Auth.dart'; @@ -204,6 +205,42 @@ class Settings extends HookConsumerWidget { }, ), ), + AdaptiveListTile( + leading: const Icon(Icons.ad_units_rounded), + title: const PlatformText("Mimic Platform"), + trailing: (context, update) => + PlatformDropDownMenu( + value: Spotube.of(context).appPlatform, + items: [ + PlatformDropDownMenuItem( + value: TargetPlatform.android, + child: const PlatformText("Android (Material You)"), + ), + PlatformDropDownMenuItem( + value: TargetPlatform.iOS, + child: const PlatformText("iOS (Cupertino)"), + ), + PlatformDropDownMenuItem( + value: TargetPlatform.macOS, + child: const PlatformText("macOS (Aqua)"), + ), + PlatformDropDownMenuItem( + value: TargetPlatform.linux, + child: const PlatformText("Linux (GTK+Libadwaita)"), + ), + PlatformDropDownMenuItem( + value: TargetPlatform.windows, + child: const PlatformText("Windows 11 (Fluent UI)"), + ), + ], + onChanged: (value) { + if (value != null) { + Spotube.of(context).changePlatform(value); + update?.call(() {}); + } + }, + ), + ), PlatformListTile( leading: const Icon(Icons.palette_outlined), title: const PlatformText("Accent Color Scheme"), diff --git a/lib/components/Shared/AdaptiveListTile.dart b/lib/components/Shared/AdaptiveListTile.dart index e2a0eeae4..9bb07bcdd 100644 --- a/lib/components/Shared/AdaptiveListTile.dart +++ b/lib/components/Shared/AdaptiveListTile.dart @@ -37,6 +37,7 @@ class AdaptiveListTile extends HookWidget { onTap?.call(); showPlatformAlertDialog( context, + barrierDismissible: true, builder: (context) { return StatefulBuilder(builder: (context, update) { return PlatformAlertDialog( diff --git a/lib/components/Shared/TrackCollectionView.dart b/lib/components/Shared/TrackCollectionView.dart index b29f1281c..c4bbb6082 100644 --- a/lib/components/Shared/TrackCollectionView.dart +++ b/lib/components/Shared/TrackCollectionView.dart @@ -115,7 +115,9 @@ class TrackCollectionView extends HookConsumerWidget { backgroundColor: color?.color, foregroundColor: color?.titleTextColor, leading: Row( - children: [BackButton(color: color?.titleTextColor)], + children: [ + PlatformBackButton(color: color?.titleTextColor) + ], ), ) : null, diff --git a/lib/main.dart b/lib/main.dart index 73df95998..e3ef5f70e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -141,6 +141,11 @@ class Spotube extends StatefulHookConsumerWidget { @override SpotubeState createState() => SpotubeState(); + + /// ↓↓ ADDED + /// InheritedWidget style accessor to our State object. + static SpotubeState of(BuildContext context) => + context.findAncestorStateOfType()!; } class SpotubeState extends ConsumerState with WidgetsBindingObserver { @@ -181,6 +186,13 @@ class SpotubeState extends ConsumerState with WidgetsBindingObserver { prevSize = appWindow.size; } + TargetPlatform appPlatform = TargetPlatform.android; + + void changePlatform(TargetPlatform targetPlatform) { + appPlatform = targetPlatform; + setState(() {}); + } + @override Widget build(BuildContext context) { final themeMode = @@ -199,7 +211,7 @@ class SpotubeState extends ConsumerState with WidgetsBindingObserver { }; }, []); - platform = TargetPlatform.macOS; + platform = appPlatform; return PlatformApp.router( routeInformationParser: router.routeInformationParser,