From 3158ada7dbf84b2b0c59bdfcce4490b74e32bae5 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Mon, 27 Jun 2022 00:51:13 -0400 Subject: [PATCH] Convert dialogs to `FrostyDialog` (#90) --- .../chat/emote_menu/recent_emotes_panel.dart | 17 +++-- lib/screens/channel/video_chat.dart | 17 ++--- lib/screens/home/home.dart | 11 +--- .../settings/sections/account_settings.dart | 66 ++++++++----------- .../settings/sections/other_settings.dart | 38 ++++++----- lib/widgets/block_button.dart | 16 +++-- 6 files changed, 80 insertions(+), 85 deletions(-) diff --git a/lib/screens/channel/chat/emote_menu/recent_emotes_panel.dart b/lib/screens/channel/chat/emote_menu/recent_emotes_panel.dart index 23a6c182..9c4479fb 100644 --- a/lib/screens/channel/chat/emote_menu/recent_emotes_panel.dart +++ b/lib/screens/channel/chat/emote_menu/recent_emotes_panel.dart @@ -4,6 +4,7 @@ import 'package:frosty/constants/constants.dart'; import 'package:frosty/screens/channel/stores/chat_store.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:frosty/widgets/button.dart'; +import 'package:frosty/widgets/dialog.dart'; import 'package:frosty/widgets/section_header.dart'; import 'package:provider/provider.dart'; @@ -23,15 +24,10 @@ class _RecentEmotesPanelState extends State { Future _showClearDialog() { return showDialog( context: context, - builder: (context) => AlertDialog( - title: const Text('Clear Recent Emotes'), + builder: (context) => FrostyDialog( + title: 'Clear Recent Emotes', content: const Text('Are you sure you want to clear your recent emotes?'), actions: [ - Button( - onPressed: Navigator.of(context).pop, - color: Colors.red, - child: const Text('Cancel'), - ), Button( onPressed: () { setState(widget.chatStore.assetsStore.recentEmotes.clear); @@ -39,6 +35,12 @@ class _RecentEmotesPanelState extends State { }, child: const Text('Yes'), ), + Button( + fill: true, + onPressed: Navigator.of(context).pop, + color: Colors.red, + child: const Text('Cancel'), + ), ], ), ); @@ -59,6 +61,7 @@ class _RecentEmotesPanelState extends State { SizedBox( height: 25, child: Button( + padding: const EdgeInsets.all(0.0), onPressed: widget.chatStore.assetsStore.recentEmotes.isEmpty ? null : _showClearDialog, color: Theme.of(context).colorScheme.secondary, child: const Text( diff --git a/lib/screens/channel/video_chat.dart b/lib/screens/channel/video_chat.dart index 6ea4038e..7858aaef 100644 --- a/lib/screens/channel/video_chat.dart +++ b/lib/screens/channel/video_chat.dart @@ -19,6 +19,7 @@ import 'package:frosty/screens/channel/stores/video_store.dart'; import 'package:frosty/screens/settings/settings.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:frosty/widgets/button.dart'; +import 'package:frosty/widgets/dialog.dart'; import 'package:frosty/widgets/profile_picture.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -296,8 +297,8 @@ class _VideoOverlay extends StatelessWidget { Future _showSleepTimerDialog(BuildContext context) { return showDialog( context: context, - builder: (context) => AlertDialog( - title: const Text('Sleep Timer'), + builder: (context) => FrostyDialog( + title: 'Sleep Timer', content: Observer( builder: (context) => Column( mainAxisSize: MainAxisSize.min, @@ -343,11 +344,6 @@ class _VideoOverlay extends StatelessWidget { ), ), actions: [ - Button( - onPressed: Navigator.of(context).pop, - color: Colors.red, - child: const Text('Dismiss'), - ), Observer( builder: (context) => Button( onPressed: videoStore.sleepHours == 0 && videoStore.sleepMinutes == 0 @@ -358,6 +354,11 @@ class _VideoOverlay extends StatelessWidget { child: const Text('Set Timer'), ), ), + Button( + onPressed: Navigator.of(context).pop, + color: Colors.red, + child: const Text('Cancel'), + ), ], ), ); @@ -591,7 +592,7 @@ class _VideoOverlay extends StatelessWidget { overflow: TextOverflow.ellipsis, style: const TextStyle( color: Colors.white, - fontWeight: FontWeight.w600, + fontWeight: FontWeight.w500, ), ), ), diff --git a/lib/screens/home/home.dart b/lib/screens/home/home.dart index f138a6e8..c181e689 100644 --- a/lib/screens/home/home.dart +++ b/lib/screens/home/home.dart @@ -11,6 +11,7 @@ import 'package:frosty/screens/home/widgets/streams_list.dart'; import 'package:frosty/screens/settings/settings.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:frosty/widgets/button.dart'; +import 'package:frosty/widgets/dialog.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -36,14 +37,8 @@ class _HomeState extends State { return showDialog( barrierDismissible: false, context: context, - builder: (context) => AlertDialog( - scrollable: true, - title: Text( - 'Frosty v${packageInfo.version} (${packageInfo.buildNumber})', - style: const TextStyle( - fontWeight: FontWeight.bold, - ), - ), + builder: (context) => FrostyDialog( + title: 'Frosty v${packageInfo.version} (${packageInfo.buildNumber})', content: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/screens/settings/sections/account_settings.dart b/lib/screens/settings/sections/account_settings.dart index de9eaa29..5a6ad765 100644 --- a/lib/screens/settings/sections/account_settings.dart +++ b/lib/screens/settings/sections/account_settings.dart @@ -7,6 +7,7 @@ import 'package:frosty/core/auth/auth_store.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:frosty/widgets/block_button.dart'; import 'package:frosty/widgets/button.dart'; +import 'package:frosty/widgets/dialog.dart'; import 'package:webview_flutter/webview_flutter.dart'; class AccountSettings extends StatelessWidget { @@ -132,45 +133,24 @@ class ProfileCard extends StatelessWidget { Future _showLogoutDialog(BuildContext context) { return showDialog( context: context, - builder: (context) => AlertDialog( - title: const Text( - 'Log Out', - style: TextStyle( - fontWeight: FontWeight.bold, + builder: (context) => FrostyDialog( + title: 'Log Out', + content: const Text('Are you sure you want to log out?'), + actions: [ + Button( + onPressed: () { + authStore.logout(); + Navigator.pop(context); + }, + child: const Text('Yes'), ), - ), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Text('Are you sure you want to log out?'), - const SizedBox(height: 50.0), - Column( - children: [ - SizedBox( - width: double.infinity, - child: Button( - fontSize: 16.0, - onPressed: () { - authStore.logout(); - Navigator.pop(context); - }, - child: const Text('Yes'), - ), - ), - const SizedBox(height: 10.0), - SizedBox( - width: double.infinity, - child: Button( - fontSize: 16.0, - onPressed: Navigator.of(context).pop, - color: Colors.red.withOpacity(0.8), - child: const Text('Cancel'), - ), - ), - ], - ) - ], - ), + Button( + fill: true, + onPressed: Navigator.of(context).pop, + color: Colors.red.withOpacity(0.8), + child: const Text('Cancel'), + ) + ], ), ); } @@ -257,8 +237,16 @@ class BlockedUsers extends StatelessWidget { children: authStore.user.blockedUsers.map( (user) { final displayName = regexEnglish.hasMatch(user.displayName) ? user.displayName : '${user.displayName} (${user.userLogin})'; + return ListTile( - title: Text(displayName), + title: Tooltip( + preferBelow: false, + message: displayName, + child: Text( + displayName, + overflow: TextOverflow.ellipsis, + ), + ), trailing: BlockButton( authStore: authStore, targetUser: displayName, diff --git a/lib/screens/settings/sections/other_settings.dart b/lib/screens/settings/sections/other_settings.dart index 2805c692..b1f4f07c 100644 --- a/lib/screens/settings/sections/other_settings.dart +++ b/lib/screens/settings/sections/other_settings.dart @@ -5,6 +5,7 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:frosty/constants/constants.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:frosty/widgets/button.dart'; +import 'package:frosty/widgets/dialog.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -25,15 +26,10 @@ class _OtherSettingsState extends State { Future _showConfirmDialog(BuildContext context) { return showDialog( context: context, - builder: (context) => AlertDialog( - title: const Text('Reset All Settings'), + builder: (context) => FrostyDialog( + title: 'Reset All Settings', content: const Text('Are you sure you want to reset all settings?'), actions: [ - Button( - onPressed: Navigator.of(context).pop, - color: Colors.red, - child: const Text('Cancel'), - ), Button( onPressed: () { widget.settingsStore.resetAllSettings(); @@ -47,6 +43,12 @@ class _OtherSettingsState extends State { }, child: const Text('Yes'), ), + Button( + fill: true, + onPressed: Navigator.of(context).pop, + color: Colors.red, + child: const Text('Cancel'), + ), ], ), ); @@ -55,6 +57,7 @@ class _OtherSettingsState extends State { @override Widget build(BuildContext context) { return ExpansionTile( + childrenPadding: const EdgeInsets.only(bottom: 10.0), leading: const Icon(Icons.help), title: const Text( 'Other', @@ -102,10 +105,8 @@ class _OtherSettingsState extends State { }, ), ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 15.0), - width: double.infinity, - child: Button( + ...[ + Button( icon: const Icon(Icons.delete_sweep), child: const Text('Clear Image Cache'), onPressed: () async { @@ -120,14 +121,19 @@ class _OtherSettingsState extends State { ); }, ), - ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 15.0), - width: double.infinity, - child: Button( + Button( onPressed: () => _showConfirmDialog(context), icon: const Icon(Icons.restore), child: const Text('Reset All Settings'), + ) + ].map( + (button) => Container( + padding: const EdgeInsets.symmetric( + horizontal: 15.0, + vertical: 5.0, + ), + width: double.infinity, + child: button, ), ), ], diff --git a/lib/widgets/block_button.dart b/lib/widgets/block_button.dart index 6a4b0cef..cf955791 100644 --- a/lib/widgets/block_button.dart +++ b/lib/widgets/block_button.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:frosty/core/auth/auth_store.dart'; import 'package:frosty/widgets/button.dart'; +import 'package:frosty/widgets/dialog.dart'; class BlockButton extends StatelessWidget { final AuthStore authStore; @@ -25,16 +26,11 @@ class BlockButton extends StatelessWidget { }) { return showDialog( context: context, - builder: (context) => AlertDialog( - title: isBlocked ? const Text('Unblock') : const Text('Block'), + builder: (context) => FrostyDialog( + title: isBlocked ? 'Unblock' : 'Block', content: Text( 'Are you sure you want to ${isBlocked ? 'unblock $targetUser?' : 'block $targetUser? This will remove them from channel lists, search results, and chat messages.'}'), actions: [ - Button( - onPressed: Navigator.of(context).pop, - color: Colors.red, - child: const Text('Cancel'), - ), Button( onPressed: () { if (isBlocked) { @@ -50,6 +46,12 @@ class BlockButton extends StatelessWidget { }, child: const Text('Yes'), ), + Button( + fill: true, + onPressed: Navigator.of(context).pop, + color: Colors.red, + child: const Text('Cancel'), + ), ], ), );