-
Notifications
You must be signed in to change notification settings - Fork 176
Replace profile popup menu with an account sheet #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mrtnha
wants to merge
1
commit into
koel:master
Choose a base branch
from
mrtnha:feat/profile-sheet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,168 @@ | ||
| import 'package:app/constants/constants.dart'; | ||
| import 'package:app/main.dart'; | ||
| import 'package:app/models/models.dart'; | ||
| import 'package:app/providers/providers.dart'; | ||
| import 'package:app/ui/screens/login.dart'; | ||
| import 'package:app/ui/screens/playable_action_sheet.dart'; | ||
| import 'package:app/ui/widgets/widgets.dart'; | ||
| import 'package:app/utils/preferences.dart' as preferences; | ||
| import 'package:app/utils/route_state.dart'; | ||
| import 'package:flutter/cupertino.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:provider/provider.dart'; | ||
|
|
||
| class ProfileActionSheet extends StatelessWidget { | ||
| final User user; | ||
|
|
||
| const ProfileActionSheet({Key? key, required this.user}) : super(key: key); | ||
|
|
||
| void _logout(BuildContext context) { | ||
| showCupertinoDialog( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return CupertinoAlertDialog( | ||
| title: const Text('Log out?'), | ||
| actions: <Widget>[ | ||
| CupertinoDialogAction( | ||
| child: const Text('Cancel'), | ||
| onPressed: () => Navigator.pop(context), | ||
| ), | ||
| CupertinoDialogAction( | ||
| child: const Text('Confirm'), | ||
| isDestructiveAction: true, | ||
| onPressed: () async { | ||
| await context.read<AuthProvider>().logout(); | ||
| await audioHandler.cleanUpUponLogout(); | ||
| RouteState.clear(); | ||
| Navigator.of( | ||
| context, | ||
| rootNavigator: true, | ||
| ).pushNamedAndRemoveUntil(LoginScreen.routeName, (_) => false); | ||
| }, | ||
| ), | ||
| ], | ||
| ); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return FrostedGlassBackground( | ||
| sigma: 40.0, | ||
| child: SafeArea( | ||
| top: false, | ||
| child: Padding( | ||
| padding: const EdgeInsets.only(top: 16.0, bottom: 8.0), | ||
| child: Column( | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: <Widget>[ | ||
| Padding( | ||
| padding: const EdgeInsets.symmetric(horizontal: 16.0), | ||
| child: IntrinsicHeight( | ||
| child: Row( | ||
| children: [ | ||
| // A DecorationImage has no intrinsic size, unlike Image, | ||
| // so the avatar takes the height of the text next to it. | ||
| ConstrainedBox( | ||
| constraints: const BoxConstraints(maxWidth: 120), | ||
| child: AspectRatio( | ||
| aspectRatio: 1, | ||
| child: DecoratedBox( | ||
| decoration: BoxDecoration( | ||
| shape: BoxShape.circle, | ||
| border: Border.all(color: Colors.white10), | ||
| ), | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(2), | ||
| child: DecoratedBox( | ||
| decoration: BoxDecoration( | ||
| shape: BoxShape.circle, | ||
| color: AppColors.background, | ||
| image: DecorationImage( | ||
| image: user.avatar, | ||
| fit: BoxFit.cover, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| const SizedBox(width: 16), | ||
| Expanded( | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| Text( | ||
| user.name, | ||
| maxLines: 1, | ||
| overflow: TextOverflow.ellipsis, | ||
| style: const TextStyle( | ||
| fontSize: 18, | ||
| fontWeight: FontWeight.w500, | ||
| ), | ||
| ), | ||
| const SizedBox(height: 2), | ||
| Text( | ||
| user.email, | ||
| maxLines: 1, | ||
| overflow: TextOverflow.ellipsis, | ||
| style: const TextStyle(color: Colors.white54), | ||
| ), | ||
| const SizedBox(height: 2), | ||
| Text( | ||
| preferences.host ?? '', | ||
| maxLines: 1, | ||
| overflow: TextOverflow.ellipsis, | ||
| style: const TextStyle(color: Colors.white54), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 16), | ||
| const Divider(indent: 16, endIndent: 16), | ||
| ListView( | ||
| physics: const NeverScrollableScrollPhysics(), | ||
| shrinkWrap: true, | ||
| children: <Widget>[ | ||
| PlayableActionButton( | ||
| text: 'Clear Downloads', | ||
| icon: const Icon( | ||
| CupertinoIcons.cloud_download, | ||
| color: Colors.white30, | ||
| ), | ||
| onTap: () => context.read<DownloadProvider>().clear(), | ||
| ), | ||
| PlayableActionButton( | ||
| text: 'Log Out', | ||
| icon: const Icon(CupertinoIcons.square_arrow_right), | ||
| destructive: true, | ||
| onTap: () => _logout(context), | ||
| hideSheetOnTap: false, | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Future<void> showProfileActionSheet( | ||
| BuildContext context, { | ||
| required User user, | ||
| }) { | ||
| return showModalBottomSheet<void>( | ||
| useRootNavigator: true, | ||
| context: context, | ||
| isScrollControlled: true, | ||
| builder: (_) => ProfileActionSheet(user: user), | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: koel/player
Length of output: 11100
🏁 Script executed:
Repository: koel/player
Length of output: 43319
🌐 Web query:
official Flutter showCupertinoDialog CupertinoDialogRoute barrierDismissible system back dismissal💡 Result:
<search_synthesis>
In Flutter, the barrierDismissible property of showCupertinoDialog and CupertinoDialogRoute controls whether tapping the modal barrier dismisses the dialog [1][2]. By default, barrierDismissible is set to false, meaning the dialog cannot be dismissed by tapping the barrier [1][3]. Regarding the system back button (or back gesture), the barrierDismissible property does not automatically prevent the dialog from being closed when the system back event is triggered [4]. In Flutter, dialog routes are generally dismissible via the system back button unless explicitly restricted [4]. If you need to prevent the dialog from closing when the back button is pressed, you must wrap the dialog content in a PopScope (or the older WillPopScope) widget and return false in the onPopInvoked/onWillPop callback to block the dismissal [4]. Summary of behavior: - Barrier dismissal: Controlled by the barrierDismissible parameter (default is false) [1][2]. - System back button dismissal: barrierDismissible does not prevent this; you must use a PopScope/WillPopScope to intercept and block back button events [4]. For state restoration, it is recommended to use Navigator.restorablePush or Navigator.restorablePushNamed with CupertinoDialogRoute rather than using the showCupertinoDialog function directly [1][2].
</search_synthesis>
<source_evidence>
Citations:
Capture the root navigator before awaiting logout.
The dialog barrier does not dismiss on outside taps, but system back can pop the dialog. If that happens while logout or audio cleanup is pending, the dialog builder context becomes deactivated. The later
Navigator.of(context)lookup can then throw before the login transition.onPressed: () async { + final navigator = Navigator.of(context, rootNavigator: true); await context.read<AuthProvider>().logout(); await audioHandler.cleanUpUponLogout(); RouteState.clear(); - Navigator.of( - context, - rootNavigator: true, - ).pushNamedAndRemoveUntil(LoginScreen.routeName, (_) => false); + if (!navigator.mounted) return; + navigator.pushNamedAndRemoveUntil(LoginScreen.routeName, (_) => false); },📝 Committable suggestion
🤖 Prompt for AI Agents