Flutter打開第三方應用

在flutter中打開第三方應用能夠使用url_launcher插件javascript

打開https://pub.dartlang.org/,而後搜索url_launcher,而後點擊進入該插件界面java

你們在installing中能夠看到使用方法app

首先在pubspec.yaml中添加url_launcher插件包,而後點擊packages get進行安裝async

安裝成功後在須要調用的頁面引用該插件url

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

  

在頁面中添加一個觸發按鈕插件

RaisedButton(
   onPressed: () => _openYoutube(),
   child: Text('點擊啓動Youtube'),
),

  

在後面寫上對應的方法,本例子以打開youtube爲例3d

  _openYoutube() async {
    // Android
    const url = 'vnd.youtube://';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      //  Ios
      const url = 'youtube://';
      if(await canLaunch(url)){
        await launch(url);
      }else{
        throw 'Could not launch $url';
      }
    }
  }

  

方法中定義的url爲app-scheme-url,安卓跟IOS的url不一樣~因此分開來判斷blog

點擊按鈕以後便可打開youtube的APPip

相關文章
相關標籤/搜索