Skip to content

Commit d14c43a

Browse files
fix: Uri.toString() for "mailto" does not encode spaces properly
dart-lang/sdk#43838
1 parent 8f8db52 commit d14c43a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/core/lib/logic/services/messenger.service.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import 'package:url_launcher/url_launcher_string.dart';
55

66
/// A class representing a fast messenger.
77
class FastMessenger {
8+
static String? encodeQueryParameters(Map<String, String> params) {
9+
return params.entries
10+
.map((MapEntry<String, String> e) =>
11+
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
12+
.join('&');
13+
}
14+
815
static Future<void> writeEmail(
916
String recipientEmail, {
1017
String? subject,
@@ -13,10 +20,10 @@ class FastMessenger {
1320
final Uri uri = Uri(
1421
scheme: 'mailto',
1522
path: recipientEmail,
16-
queryParameters: <String, String>{
23+
query: encodeQueryParameters(<String, String>{
1724
if (subject != null) 'subject': subject,
1825
if (body != null) 'body': body,
19-
},
26+
}),
2027
);
2128

2229
return launchUrl(uri.toString());

0 commit comments

Comments
 (0)