Skip to content

[url_launcher] README instructions for SMS are incorrect #156281

@onhyeon618

Description

@onhyeon618

What package does this bug report belong to?

url_launcher

What target platforms are you seeing this bug on?

Android

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
name: test_flutter_features
description: "A new Flutter project."
publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: '>=3.3.4 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  url_launcher: 6.3.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.0

flutter:
  uses-material-design: true

Steps to reproduce

  1. Create an Uri with "sms" scheme, set message to any string that contains character "&".
  2. run launchUrl(uri, mode: LaunchMode.externalApplication)

Expected results

The message given to Uri properly shows on sms body field.

Actual results

The message is not shown as it's given on the Uri.
If the original message was "Hello & World", depending on how I created Uri, it appears either "Hello%20%26%20World" or "Hello ".

final uri = Uri(
  scheme: 'sms',
  queryParameters: <String, String>{
    'body': Uri.encodeComponent('Hello & World'),
  },
);  // result: "Hello%20%26%20World"
final message = Uri.encodeComponent('Hello & World');
final uri = Uri.parse('sms:?body=$message');  // result: "Hello "

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () async {
                /// Code example provided on README
                final uri = Uri(
                  scheme: 'sms',
                  queryParameters: <String, String>{
                    'body': Uri.encodeComponent('Hello & World'),
                  },
                );
                launchUrl(uri, mode: LaunchMode.externalApplication); // result: "Hello%20%26%20World"
              },
              child: const Text('Test 1'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () async {
                /// Another way that I tried
                final message = Uri.encodeComponent('Hello & World');
                final uri = Uri.parse('sms:?body=$message');
                launchUrl(uri, mode: LaunchMode.externalApplication); // result: "Hello "
              },
              child: const Text('Test 2'),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Videos

No response

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.19045.4894], locale ko-KR)
    • Flutter version 3.16.9 on channel stable at D:\Programs\Android\Flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (8 months ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\user\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] Connected device (4 available)
    • SM S901N (mobile)            • R5CT22YWE0P   • android-arm64  • Android 14 (API 34)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.4894]
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 129.0.2792.65

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listp: url_launcherPlugin to launch external applicationspackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions