fix dialogs

This commit is contained in:
Salvatore Giordano
2021-03-05 12:29:06 +01:00
parent 8b3c46527f
commit 5933929399
2 changed files with 124 additions and 214 deletions
@@ -251,7 +251,8 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
void _showFlagDialog() async { void _showFlagDialog() async {
final client = StreamChat.of(context).client; final client = StreamChat.of(context).client;
var answer = await showConfirmationDialog(context, final answer = await showConfirmationDialog(
context,
title: 'Flag Message', title: 'Flag Message',
icon: StreamSvgIcon.flag( icon: StreamSvgIcon.flag(
color: StreamChatTheme.of(context).colorTheme.accentRed, color: StreamChatTheme.of(context).colorTheme.accentRed,
@@ -260,15 +261,35 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
question: question:
'Do you want to send a copy of this message to a\nmoderator for further investigation?', 'Do you want to send a copy of this message to a\nmoderator for further investigation?',
okText: 'FLAG', okText: 'FLAG',
cancelText: 'CANCEL'); cancelText: 'CANCEL',
);
if (answer) { final theme = StreamChatTheme.of(context);
if (answer == true) {
try { try {
await client.flagMessage(widget.message.id); 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) { } catch (err) {
if (json.decode(err?.body ?? {})['code'] == 4) { 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 { } else {
_showErrorAlert(); _showErrorAlert();
} }
@@ -306,133 +327,16 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
} }
} }
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() { void _showErrorAlert() {
showModalBottomSheet( showInfoDialog(
backgroundColor: StreamChatTheme.of(context).colorTheme.white, context,
context: context, icon: StreamSvgIcon.error(
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, color: StreamChatTheme.of(context).colorTheme.accentRed,
size: 24.0, size: 24.0,
), ),
SizedBox( details: 'The operation couldn\'t be completed.',
height: 26.0, title: 'Something went wrong',
), okText: 'OK',
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();
},
),
],
),
],
);
},
); );
} }
+37 -31
View File
@@ -58,9 +58,14 @@ Future<bool> showConfirmationDialog(
height: 1, height: 1,
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
TextButton( Flexible(
child: Container(
alignment: Alignment.center,
child: TextButton(
onPressed: () {
Navigator.of(context).pop(false);
},
child: Text( child: Text(
cancelText, cancelText,
style: StreamChatTheme.of(context) style: StreamChatTheme.of(context)
@@ -72,11 +77,16 @@ Future<bool> showConfirmationDialog(
.black .black
.withOpacity(0.5)), .withOpacity(0.5)),
), ),
onPressed: () {
Navigator.of(context).pop(false);
},
), ),
TextButton( ),
),
Flexible(
child: Container(
alignment: Alignment.center,
child: TextButton(
onPressed: () {
Navigator.pop(context, true);
},
child: Text( child: Text(
okText, okText,
style: StreamChatTheme.of(context) style: StreamChatTheme.of(context)
@@ -87,9 +97,8 @@ Future<bool> showConfirmationDialog(
.colorTheme .colorTheme
.accentRed), .accentRed),
), ),
onPressed: () { ),
Navigator.pop(context, true); ),
},
), ),
], ],
), ),
@@ -103,13 +112,13 @@ Future<bool> showInfoDialog(
BuildContext context, { BuildContext context, {
String title, String title,
Widget icon, Widget icon,
String question, String details,
String okText, String okText,
StreamChatThemeData theme, StreamChatThemeData theme,
}) { }) {
return showModalBottomSheet( return showModalBottomSheet(
backgroundColor: backgroundColor: theme?.colorTheme?.white ??
theme.colorTheme.white ?? StreamChatTheme.of(context).colorTheme.white, StreamChatTheme.of(context).colorTheme.white,
context: context, context: context,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
@@ -117,7 +126,8 @@ Future<bool> showInfoDialog(
topRight: Radius.circular(16.0), topRight: Radius.circular(16.0),
)), )),
builder: (context) { builder: (context) {
return Column( return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
SizedBox( SizedBox(
@@ -129,42 +139,38 @@ Future<bool> showInfoDialog(
), ),
Text( Text(
title, title,
style: theme.textTheme.headlineBold ?? style: theme?.textTheme?.headlineBold ??
StreamChatTheme.of(context).textTheme.headlineBold, StreamChatTheme.of(context).textTheme.headlineBold,
), ),
SizedBox( SizedBox(
height: 7.0, height: 7.0,
), ),
Text(question), Text(details),
SizedBox( SizedBox(
height: 36.0, height: 36.0,
), ),
Container( Container(
color: theme.colorTheme.black.withOpacity(.08) ?? color: theme?.colorTheme?.black?.withOpacity(.08) ??
StreamChatTheme.of(context).colorTheme.black.withOpacity(.08), StreamChatTheme.of(context).colorTheme.black.withOpacity(.08),
height: 1.0, height: 1.0,
), ),
Row( Center(
mainAxisAlignment: MainAxisAlignment.spaceBetween, child: TextButton(
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),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: Text(
okText,
style: TextStyle(
color: theme?.colorTheme?.black?.withOpacity(0.5) ??
StreamChatTheme.of(context).colorTheme.accentBlue,
fontWeight: FontWeight.w400,
),
),
),
), ),
], ],
), ),
],
); );
}, },
); );