본문 바로가기

카테고리 없음

flutter url_launcher 사용하기

반응형

https://pub.dev/packages/url_launcher

 

url_launcher | Flutter package

Flutter plugin for launching a URL. Supports web, phone, SMS, and email schemes.

pub.dev

 

 

 

설치 

 

pubspec.yaml 파일안에 dependencies아래와 같이 넣어준다.

dependencies:
  url_launcher: ^6.1.10

pub get 실행

 

Example 

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

final Uri _url = Uri.parse('https://flutter.dev');

void main() => runApp(
      const MaterialApp(
        home: Material(
          child: Center(
            child: ElevatedButton(
              onPressed: _launchUrl,
              child: Text('Show Flutter homepage'),
            ),
          ),
        ),
      ),
    );

Future<void> _launchUrl() async {
  if (!await launchUrl(_url)) {
    throw Exception('Could not launch $_url');
  }
}

See the example app for more complex examples.

 

 

 

 

IOS

Add any URL schemes passed to canLaunchUrl as LSApplicationQueriesSchemes entries in your Info.plist file, otherwise it will return false.

Example:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>sms</string>
  <string>tel</string>
</array>

 

안드로이드 

Add any URL schemes passed to canLaunchUrl as <queries> entries in your AndroidManifest.xml, otherwise it will return false in most cases starting on Android 11 (API 30) or higher. Checking for supportsLaunchMode(LaunchMode.inAppBrowserView) also requires a <queries> entry to return anything but false. A <queries> element must be added to your manifest as a child of the root element.

Example:

<!-- Provide required visibility configuration for API level 30 and above -->
<queries>
  <!-- If your app checks for SMS support -->
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="sms" />
  </intent>
  <!-- If your app checks for call support -->
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="tel" />
  </intent>
  <!-- If your application checks for inAppBrowserView launch mode support -->
  <intent>
    <action android:name="android.support.customtabs.action.CustomTabsService" />
  </intent>
</queries>

See the Android documentation for examples of other queries.

 

 

SchemeExampleAction

https:<URL> https://flutter.dev Open <URL> in the default browser
mailto:<email address>?subject=<subject>&body=<body> mailto:smith@example.org?subject=News&body=New%20plugin Create email to <email address> in the default email app
tel:<phone number> tel:+1-555-010-999 Make a phone call to <phone number> using the default phone app
sms:<phone number> sms:5550101234 Send an SMS message to <phone number> using the default messaging app
file:<path> file:/home Open file or folder using default app association, supported on desktop platforms
반응형