6-15
加入連結
- 安裝 https://pub.dev/packages/url_launcher
- 修改 \xxx\android\app\src\main\AndroidManifest.xml,加入:
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
如:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.tad0616.kidney_disease_diet">
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
<application
android:label="xxx"
android:icon="@mipmap/ic_launcher">
..略...
</application>
</manifest>
- 修改 \xxx\ios\Runner\Info.plist,加入:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
</array>
- 引入套件
import 'package:url_launcher/url_launcher.dart';
- 製作方法:
void _launchURL(url) async =>
await canLaunch(url) ? await launch(url) : throw '無法連至 $url';
- 套用方法:
GestureDetector(
onTap: () => _launchURL(
'https://網址'),
child: Text(
'顯示文字或網址',
style: TextStyle(fontSize: 14.0),
),
),