Flutter意图跳转插件flutter_intent_forzzh的使用
Flutter意图跳转插件flutter_intent_forzzh的使用
用于启动原生系统(Android/iOS)界面,或者跳转三方App的插件。如果是跳转三方应用,请先确保你的移动设备上已安装该第三方App。
Android 使用说明:
1. 在 AndroidManifest.xml
中添加需要启动的包名配置
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zzh.intent.native_intent_example">
...
<queries>
<!-- 配置需要启动的应用包名 -->
<package android:name="com.taobao.taobao" />
</queries>
</manifest>
2. 通过 Scheme 启动
NativeIntent intent = NativeIntent(
action: AndroidIntent.ACTION_VIEW,
data: "taobao://s.click.taobao.com/NMJ5nJu",
);
intent.launch();
3. 通过 AppId 启动
NativeIntent intent = NativeIntent(
action: AndroidIntent.ACTION_VIEW,
package: 'com.taobao.taobao',
);
intent.launch();
4. 跳转系统界面
NativeIntent intent = const NativeIntent(
action: Settings.ACTION_NFC_SETTINGS, // 跳转系统 NFC 设置
);
intent.launch();
iOS 使用说明(iOS 需要 10.0 及以上版本):
1. 在 [Info.plist]
中添加 Scheme 白名单
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- URL Scheme 白名单 -->
<string>taobao</string>
<string>vipshop</string>
<!-- 其他需要的白名单 -->
<!-- URL Scheme 白名单 -->
</array>
2. 启动方式同上,传入参数 data
必须是有效值
var intent = NativeIntent(
data: "taobao://s.click.taobao.com/NMJ5nJu",
);
intent.launch();
3. 或者启动系统界面
NativeIntent intent = const NativeIntent(
action: IOSIntent.APPSTORE, // 跳转 App Store
);
intent.launch();
完整示例代码
以下是一个完整的示例代码,展示了如何在 Flutter 中使用 flutter_intent_forzzh
插件来实现意图跳转。
示例代码
import 'package:flutter/material.dart';
import 'package:flutter_intent_forzzh/native_intent_lib.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter Intent Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
buildButton("启动淘宝", () {
NativeIntent intent = NativeIntent(
action: AndroidIntent.ACTION_VIEW,
data: "taobao://s.click.taobao.com/NMJ5nJu",
);
intent.launch();
}),
buildButton("跳转设置 (NFC)", () {
NativeIntent intent = const NativeIntent(
action: Settings.ACTION_NFC_SETTINGS,
);
intent.launch();
}),
buildButton("跳转 App Store", () {
NativeIntent intent = const NativeIntent(
action: IOSIntent.APPSTORE,
);
intent.launch();
}),
],
),
),
),
);
}
Widget buildButton(String title, Function function) {
return GestureDetector(
onTap: () {
function.call();
},
child: Container(
width: 200,
height: 35,
margin: const EdgeInsets.only(top: 20),
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Colors.lightBlueAccent,
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Text(title),
),
);
}
}
更多关于Flutter意图跳转插件flutter_intent_forzzh的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复