【问题标题】:Flutter how to use deep links to launch apps on the webFlutter 如何使用深度链接在网络上启动应用
【发布时间】: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


    【解决方案1】:

    问题解决!!!

    AndroidMainfest.xml 修改如下。谢谢!

    <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
                <intent-filter android:autoVerify="true">
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <data android:scheme="http" android:host="deeplink.exampe.test" />
                    <data android:scheme="https" />
                </intent-filter>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      相关资源
      最近更新 更多