iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐙

How to open browser apps from a Flutter app

に公開
2025/06/12

Introduction

This article explains how to open URLs by specifying browser apps such as Chrome or Firefox in a Flutter app.

  • Note: Only Android and iOS are supported.

Package Installation

Add android_intent_plus and url_launcher to the pubspec.yaml file and run flutter pub get.

dependencies:
  android_intent_plus: <any version>
  url_launcher: <any version>
```text

# Code for Android

Use the `android_intent_plus` package.

```dart
Future<void> _launchBrowserAndroid(
  BrowserType browserType,
  String url,
) async {
  switch (browserType) {
    case BrowserType.chrome:
      final intent = AndroidIntent(
        action: 'action_view',
        data: url,
        package: 'com.android.chrome',
      );
      return await intent.launch();
    case BrowserType.firefox:
      final intent = AndroidIntent(
        action: 'action_view',
        data: url,
        package: 'org.mozilla.firefox',
      );
      return await intent.launch();
    case BrowserType.opera:
      final intent = AndroidIntent(
        action: 'action_view',
        data: url,
        package: 'com.opera.browser',
      );
      return await intent.launch();
  }
}
```text

# Code for iOS

Use the `url_launcher` package.

```dart
Future<void> _launchBrowserIOS(
  BrowserType browserType,
  String url,
) async {
  final String formattedUrl;
  switch (browserType) {
    case BrowserType.chrome:
      formattedUrl = url
          .replaceFirst('https://', 'googlechrome://')
          .replaceFirst('http://', 'googlechrome://');
      break;
    case BrowserType.firefox:
      formattedUrl = 'firefox://open-url?url=$url';
      break;
    case BrowserType.opera:
      formattedUrl = url
          .replaceFirst('https://', 'touch-https://')
          .replaceFirst('http://', 'touch-http://');
      break;
  }
  launchUrl(
    Uri.parse(formattedUrl),
    mode: LaunchMode.externalApplication,
  );
}

Summary

This is the complete implementation. You can find usage examples in the example directory.
https://github.com/K9i-0/multi_browser_launcher

GitHubで編集を提案

Discussion