在flutter中打開第三方應用可以使用url_launcher插件
打開https://pub.dartlang.org/,然後搜尋url_launcher,然後點選進入該插件界面
大家在installing中可以看到使用方法
首先在pubspec.yaml中添加url_launcher插件包,然後點選packages get進行安裝
安裝成功後在需要調用的頁面引用該插件
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
在頁面中添加一個觸發按鈕
RaisedButton(
onPressed: () => _openYoutube(),
child: Text('點選啟動Youtube'),
),
在後面寫上對應的方法,本例子以打開youtube為例
_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不同~是以分開來判斷
點選按鈕之後即可打開youtube的APP
轉載于:https://www.cnblogs.com/gxsyj/p/10748897.html