From 59339293997090d4802004bce76dacd123de3bdb Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 5 Mar 2021 12:29:06 +0100 Subject: [PATCH] fix dialogs --- .../lib/src/message_actions_modal.dart | 182 +++++------------- .../stream_chat_flutter/lib/src/utils.dart | 156 +++++++-------- 2 files changed, 124 insertions(+), 214 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_actions_modal.dart b/packages/stream_chat_flutter/lib/src/message_actions_modal.dart index 1546e66b..12e465b3 100644 --- a/packages/stream_chat_flutter/lib/src/message_actions_modal.dart +++ b/packages/stream_chat_flutter/lib/src/message_actions_modal.dart @@ -251,24 +251,45 @@ class _MessageActionsModalState extends State { void _showFlagDialog() async { final client = StreamChat.of(context).client; - var answer = await showConfirmationDialog(context, - title: 'Flag Message', - icon: StreamSvgIcon.flag( - color: StreamChatTheme.of(context).colorTheme.accentRed, - size: 24.0, - ), - question: - 'Do you want to send a copy of this message to a\nmoderator for further investigation?', - okText: 'FLAG', - cancelText: 'CANCEL'); + final answer = await showConfirmationDialog( + context, + title: 'Flag Message', + icon: StreamSvgIcon.flag( + color: StreamChatTheme.of(context).colorTheme.accentRed, + size: 24.0, + ), + question: + 'Do you want to send a copy of this message to a\nmoderator for further investigation?', + okText: 'FLAG', + cancelText: 'CANCEL', + ); - if (answer) { + final theme = StreamChatTheme.of(context); + if (answer == true) { try { await client.flagMessage(widget.message.id); - _showDismissAlert(); + await showInfoDialog( + context, + icon: StreamSvgIcon.flag( + color: theme.colorTheme.accentRed, + size: 24.0, + ), + details: 'The message has been reported to a moderator.', + title: 'Message flagged', + okText: 'OK', + ); } catch (err) { if (json.decode(err?.body ?? {})['code'] == 4) { - _showDismissAlert(); + await showInfoDialog( + context, + icon: StreamSvgIcon.flag( + color: theme.colorTheme.accentRed, + size: 24.0, + ), + details: 'The message has been reported to a moderator.', + title: 'Message flagged', + okText: 'OK', + ); } else { _showErrorAlert(); } @@ -306,133 +327,16 @@ class _MessageActionsModalState extends State { } } - void _showDismissAlert() { - showModalBottomSheet( - backgroundColor: StreamChatTheme.of(context).colorTheme.white, - context: context, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(16.0), - topRight: Radius.circular(16.0), - )), - builder: (context) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 26.0, - ), - StreamSvgIcon.flag( - color: StreamChatTheme.of(context).colorTheme.accentRed, - size: 24.0, - ), - SizedBox( - height: 26.0, - ), - Text( - 'Message flagged', - style: StreamChatTheme.of(context).textTheme.headlineBold, - ), - SizedBox( - height: 7.0, - ), - Text('The message has been reported to a moderator.'), - SizedBox( - height: 36.0, - ), - Container( - color: - StreamChatTheme.of(context).colorTheme.black.withOpacity(.08), - height: 1.0, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - child: Text( - 'OK', - style: StreamChatTheme.of(context) - .textTheme - .bodyBold - .copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .accentBlue), - ), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ), - ], - ); - }, - ); - } - void _showErrorAlert() { - showModalBottomSheet( - backgroundColor: StreamChatTheme.of(context).colorTheme.white, - context: context, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(16.0), - topRight: Radius.circular(16.0), - )), - builder: (context) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 26.0, - ), - StreamSvgIcon.error( - color: StreamChatTheme.of(context).colorTheme.accentRed, - size: 24.0, - ), - SizedBox( - height: 26.0, - ), - Text( - 'Something went wrong', - style: StreamChatTheme.of(context).textTheme.headlineBold, - ), - SizedBox( - height: 7.0, - ), - Text('The operation couldn\'t be completed.'), - SizedBox( - height: 36.0, - ), - Container( - color: - StreamChatTheme.of(context).colorTheme.black.withOpacity(.08), - height: 1.0, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - child: Text( - 'OK', - style: StreamChatTheme.of(context) - .textTheme - .bodyBold - .copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .accentBlue), - ), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ), - ], - ); - }, + showInfoDialog( + context, + icon: StreamSvgIcon.error( + color: StreamChatTheme.of(context).colorTheme.accentRed, + size: 24.0, + ), + details: 'The operation couldn\'t be completed.', + title: 'Something went wrong', + okText: 'OK', ); } diff --git a/packages/stream_chat_flutter/lib/src/utils.dart b/packages/stream_chat_flutter/lib/src/utils.dart index 150f4f33..8d59757e 100644 --- a/packages/stream_chat_flutter/lib/src/utils.dart +++ b/packages/stream_chat_flutter/lib/src/utils.dart @@ -58,38 +58,47 @@ Future showConfirmationDialog( height: 1, ), Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - TextButton( - child: Text( - cancelText, - style: StreamChatTheme.of(context) - .textTheme - .bodyBold - .copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .black - .withOpacity(0.5)), + Flexible( + child: Container( + alignment: Alignment.center, + child: TextButton( + onPressed: () { + Navigator.of(context).pop(false); + }, + child: Text( + cancelText, + style: StreamChatTheme.of(context) + .textTheme + .bodyBold + .copyWith( + color: StreamChatTheme.of(context) + .colorTheme + .black + .withOpacity(0.5)), + ), + ), ), - onPressed: () { - Navigator.of(context).pop(false); - }, ), - TextButton( - child: Text( - okText, - style: StreamChatTheme.of(context) - .textTheme - .bodyBold - .copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .accentRed), + Flexible( + child: Container( + alignment: Alignment.center, + child: TextButton( + onPressed: () { + Navigator.pop(context, true); + }, + child: Text( + okText, + style: StreamChatTheme.of(context) + .textTheme + .bodyBold + .copyWith( + color: StreamChatTheme.of(context) + .colorTheme + .accentRed), + ), + ), ), - onPressed: () { - Navigator.pop(context, true); - }, ), ], ), @@ -103,13 +112,13 @@ Future showInfoDialog( BuildContext context, { String title, Widget icon, - String question, + String details, String okText, StreamChatThemeData theme, }) { return showModalBottomSheet( - backgroundColor: - theme.colorTheme.white ?? StreamChatTheme.of(context).colorTheme.white, + backgroundColor: theme?.colorTheme?.white ?? + StreamChatTheme.of(context).colorTheme.white, context: context, shape: RoundedRectangleBorder( borderRadius: BorderRadius.only( @@ -117,54 +126,51 @@ Future showInfoDialog( topRight: Radius.circular(16.0), )), builder: (context) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 26.0, - ), - if (icon != null) icon, - SizedBox( - height: 26.0, - ), - Text( - title, - style: theme.textTheme.headlineBold ?? - StreamChatTheme.of(context).textTheme.headlineBold, - ), - SizedBox( - height: 7.0, - ), - Text(question), - SizedBox( - height: 36.0, - ), - Container( - color: theme.colorTheme.black.withOpacity(.08) ?? - StreamChatTheme.of(context).colorTheme.black.withOpacity(.08), - height: 1.0, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TextButton( - child: Text( - okText, - style: TextStyle( - color: theme.colorTheme.black.withOpacity(0.5) ?? - StreamChatTheme.of(context) - .colorTheme - .black - .withOpacity(0.5), - fontWeight: FontWeight.w400), - ), + return SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 26.0, + ), + if (icon != null) icon, + SizedBox( + height: 26.0, + ), + Text( + title, + style: theme?.textTheme?.headlineBold ?? + StreamChatTheme.of(context).textTheme.headlineBold, + ), + SizedBox( + height: 7.0, + ), + Text(details), + SizedBox( + height: 36.0, + ), + Container( + color: theme?.colorTheme?.black?.withOpacity(.08) ?? + StreamChatTheme.of(context).colorTheme.black.withOpacity(.08), + height: 1.0, + ), + Center( + child: TextButton( onPressed: () { Navigator.of(context).pop(); }, + child: Text( + okText, + style: TextStyle( + color: theme?.colorTheme?.black?.withOpacity(0.5) ?? + StreamChatTheme.of(context).colorTheme.accentBlue, + fontWeight: FontWeight.w400, + ), + ), ), - ], - ), - ], + ), + ], + ), ); }, );