【发布时间】:2022-01-18 04:48:20
【问题描述】:
我想通过网络上的链接启动我的应用程序。
我想使用一个名为 uni_link 的包。
按照示例,我将以下内容添加到AndroidMainfest.xml。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="exampletest"
android:host="deeplink.exampe.test" />
</intent-filter>
我希望应用在点击网络上的链接时启动。
这是我的主要来源。
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:uni_links/uni_links.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
Future<String?> initialLink() async {
try {
final initialLink = await getInitialLink();
return initialLink!;
} on PlatformException catch (exception){
print('${exception.message}');
}
}
String deepLinkURL = "";
@override
void initState() {
initialLink().then((value) => setState(() {
deepLinkURL = value!;
}));
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Deep Linking Sample"),
),
body: Center(
child: Center(
child: Container(
child: Text(deepLinkURL == null ? "null" : "$deepLinkURL" ),
),
),
),
);
}
}
我不太明白这个例子,所以我问了一个问题。如果你能用一个简单的例子解释一下,我将不胜感激!
【问题讨论】:
标签: flutter dart deep-linking