0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Flutterでメール送信時にインデントや空白が+(プラス)に置き換わってしまう

Posted at

この記事の想定読者

Flutterのwebのurl_launcherパッケージを使用してメーラーソフトを起動する
空白文字が「+」として扱われてしまっていて困っている

イメージ画像

スクリーンショット 2025-01-06 17.59.27.png

パッケージのインポート

$ flutter pub add url_launcher
  • yaml
dependencies:
  url_launcher: 

コード

良い例

    final bodyStr = '''
    メール本文です。
    スペース があっても+に置き換えられません。
    ''';
    final email = 'John.Doe@example.com';
    final title = Uri.encodeComponent('title');
    final body = Uri.encodeComponent(bodyStr);
    final mailtoUri =  Uri.parse('mailto:$email?subject=$title&body=$body');
    if (await canLaunchUrl(mailtoUri)) {
      launchUrl(mailtoUri);
    } else {
      throw "Cloud not launch $mailtoUri.";
    }

悪い例

  final title = 'title';
  final bodyStr = '''
    メール本文です。
    スペースがある場合+に置き換えられてしまいます。
    ''';
  final uri = Uri(
    scheme: 'mailto',
    path: 'John.Doe@example.com',
    queryParameters: {'subject': $title,'body':$bodyStr}
  );

  if (await canLaunch(scheme)) {
    await launch(scheme);
  } else {
    print('problem on launcher');
  }

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?