Skip to content

Commit

Permalink
Open mail or share support mail when clicked
Browse files Browse the repository at this point in the history
Minor UI revision, Dialog -> AlertDialog
  • Loading branch information
erdemyerebasmaz committed May 7, 2024
1 parent fb98c54 commit 4457360
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 110 deletions.
205 changes: 98 additions & 107 deletions lib/routes/close_channels/coop_close_channels_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import 'package:breez/widgets/flushbar.dart';
import 'package:breez/widgets/loader.dart';
import 'package:breez/widgets/loading_animated_text.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:share_plus/share_plus.dart';

final _log = Logger("CoopCloseChannelsDialog");

Expand All @@ -28,7 +30,7 @@ class _CoopCloseChannelsDialogState extends State<CoopCloseChannelsDialog> {
ModalRoute _currentRoute;

String dialogMessage = "";
String failureMessage = "";
bool hasFailed = false;

@override
void initState() {
Expand All @@ -48,121 +50,110 @@ class _CoopCloseChannelsDialogState extends State<CoopCloseChannelsDialog> {
Widget build(BuildContext context) {
final texts = context.texts();
final themeData = Theme.of(context);
final queryData = MediaQuery.of(context);
final loaderThemeData = theme.customData[theme.themeId];

return Dialog(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 64.0,
padding: const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 8.0),
child: LoadingAnimatedText(
return AlertDialog(
title: (dialogMessage.isEmpty && hasFailed == false)
? LoadingAnimatedText(
texts.close_channels_dialog_title,
textStyle: themeData.dialogTheme.titleTextStyle,
textAlign: TextAlign.center,
)
: Text(
texts.close_channels_dialog_title,
style: themeData.dialogTheme.titleTextStyle,
textAlign: TextAlign.center,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 0.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
dialogMessage.isEmpty
? Padding(
padding: const EdgeInsets.symmetric(
vertical: 0.0,
horizontal: 16.0,
),
child: SizedBox(
width: queryData.size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
LoadingAnimatedText(
texts.close_channels_dialog_message,
textStyle:
themeData.dialogTheme.contentTextStyle,
textAlign: TextAlign.center,
),
],
),
),
)
: Text(
dialogMessage,
style: themeData.dialogTheme.contentTextStyle,
textAlign: TextAlign.center,
),
if (failureMessage.isNotEmpty) ...[
Padding(
padding: EdgeInsets.zero,
child: GestureDetector(
onTap: () => launchLinkOnExternalBrowser(
"mailto:[email protected]"),
child: Text(
failureMessage,
textAlign: TextAlign.left,
overflow: TextOverflow.clip,
maxLines: 4,
style: DefaultTextStyle.of(context).style.copyWith(
fontSize: 12,
color: Colors.blue,
),
),
),
)
]
],
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
dialogMessage.isEmpty && hasFailed == false
? LoadingAnimatedText(
texts.close_channels_dialog_message,
textStyle: themeData.dialogTheme.contentTextStyle,
textAlign: TextAlign.center,
)
: Text(
dialogMessage,
style: themeData.dialogTheme.contentTextStyle,
textAlign: TextAlign.center,
),
if (dialogMessage.isEmpty && hasFailed == false) ...[
Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: Image.asset(
loaderThemeData.loaderAssetPath,
height: 64.0,
colorBlendMode:
loaderThemeData.loaderColorBlendMode ?? BlendMode.srcIn,
gaplessPlayback: true,
),
),
),
dialogMessage.isEmpty && failureMessage.isEmpty
? Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: Image.asset(
loaderThemeData.loaderAssetPath,
height: 64.0,
colorBlendMode:
loaderThemeData.loaderColorBlendMode ?? BlendMode.srcIn,
gaplessPlayback: true,
],
if (hasFailed) ...[
RichText(
text: TextSpan(
style: themeData.dialogTheme.contentTextStyle,
text: texts.close_channels_dialog_failure_message_start,
children: [
TextSpan(
text: texts.close_channels_dialog_failure_message_middle,
style: const TextStyle(color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () async {
// If device can't handle mailto: link, share the e-mail
try {
await launchLinkOnExternalBrowser(
"mailto:[email protected]",
);
} catch (e) {
final RenderBox box = context.findRenderObject();
final offset =
box.localToGlobal(Offset.zero) & box.size;
final rect = Rect.fromPoints(
offset.topLeft,
offset.bottomRight,
);
Share.share(
"[email protected]",
subject: texts
.close_channels_dialog_failure_message_middle,
sharePositionOrigin: rect,
);
}
},
),
)
: SizedBox(
height: 64.0,
child: Padding(
padding: const EdgeInsets.only(bottom: 16.0, right: 8.0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
style: ButtonStyle(
overlayColor:
MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.pressed)) {
return Colors.transparent;
}
return null; // Defer to the widget's default.
}),
),
child: Text(
texts.close_channels_dialog_action_close,
style: themeData.primaryTextTheme.labelLarge,
),
onPressed: () =>
Navigator.of(context).removeRoute(_currentRoute),
),
],
),
TextSpan(
text: texts.close_channels_dialog_failure_message_end,
),
)
],
),
),
],
],
),
actions: (dialogMessage.isNotEmpty || hasFailed == true)
? [
TextButton(
style: ButtonStyle(
overlayColor:
MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.pressed)) {
return Colors.transparent;
}
return null; // Defer to the widget's default.
}),
),
child: Text(
texts.close_channels_dialog_action_close,
style: themeData.primaryTextTheme.labelLarge,
),
onPressed: () =>
Navigator.of(context).removeRoute(_currentRoute),
),
]
: null,
);
}

Expand All @@ -184,13 +175,13 @@ class _CoopCloseChannelsDialogState extends State<CoopCloseChannelsDialog> {
);
setState(() {
dialogMessage = texts.close_channels_dialog_success_message;
failureMessage = "";
hasFailed = false;
});
return;
} else {
setState(() {
dialogMessage = "";
failureMessage = texts.close_channels_dialog_failure_message;
hasFailed = true;
});

_log.warning("Failed to close all channels.");
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: d1fc18d547f3d04e71fcc52a4662355c9c8f2a29
resolved-ref: d1fc18d547f3d04e71fcc52a4662355c9c8f2a29
ref: "5091d6b63a830c940abd5f159248ed8064858088"
resolved-ref: "5091d6b63a830c940abd5f159248ed8064858088"
url: "https://github.com/breez/Breez-Translations.git"
source: git
version: "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
breez_translations:
git:
url: https://github.com/breez/Breez-Translations.git
ref: d1fc18d547f3d04e71fcc52a4662355c9c8f2a29
ref: 5091d6b63a830c940abd5f159248ed8064858088
clipboard_watcher: ^0.2.0
collection: ^1.18.0
confetti: ^0.7.0
Expand Down

0 comments on commit 4457360

Please sign in to comment.