完成DeepLink

This commit is contained in:
胡天 2023-07-24 11:47:02 +08:00
parent 443f3edcc0
commit d018147931
5 changed files with 80 additions and 3 deletions

View File

@ -24,6 +24,13 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<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="newsgetx" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

View File

@ -1,5 +1,5 @@
/// Api地址
// const String ServerApiUrl = "http://172.31.163.87:4523/m1/2998542-0-default";
const String ServerApiUrl = "http://192.168.1.5:4523/m1/2998542-0-default";
const String ServerApiUrl = "http://172.31.163.87:4523/m1/2998542-0-default";
// const String ServerApiUrl = "http://192.168.1.5:4523/m1/2998542-0-default";
const CryptoSalt = "E1pWsyfiy@R@X#qn17!StJNdZK1fFF8iV6ffN!goZkqt#JxO";

View File

@ -1,9 +1,12 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:news_getx/theme/app_colors.dart';
import 'package:news_getx/utils/iconfont.dart';
import 'package:uni_links/uni_links.dart';
class ApplicationController extends GetxController {
///
@ -44,12 +47,55 @@ class ApplicationController extends GetxController {
bool isInitialUriIsHandled = false;
StreamSubscription? uriSub;
//
Future<void> handleInitialUri() async {
if (!isInitialUriIsHandled) {
isInitialUriIsHandled = true;
try {
final uri = await getInitialUri();
if (uri == null) {
print('no initial uri');
} else {
// scheme
print('got initial uri: $uri');
}
} on PlatformException {
print('falied to get initial uri');
} on FormatException catch (err) {
print('malformed initial uri, $err');
}
}
}
//
handleIncomingLinks() {
if (!kIsWeb) {
uriSub = uriLinkStream.listen((Uri? uri) {
// scheme
print('got uri: $uri');
// if (uri!.pathSegments[1].toLowerCase() == 'category') {
if (uri != null && uri.path == '/notify/category') {
print('跳转到Category页');
handleNavBarTap(1);
}
}, onError: (err) {
print('got err: $err');
});
}
}
///
@override
void onInit() {
super.onInit();
// deek link处理
// handleInitialUri();
// handleIncomingLinks();
// tab
tabTitles = ['Welcome', 'Category', 'Bookmarks', 'Account'];
bottomTabs = <BottomNavigationBarItem>[

View File

@ -602,6 +602,30 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.2"
uni_links:
dependency: "direct main"
description:
name: uni_links
sha256: "051098acfc9e26a9fde03b487bef5d3d228ca8f67693480c6f33fd4fbb8e2b6e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.5.1"
uni_links_platform_interface:
dependency: transitive
description:
name: uni_links_platform_interface
sha256: "929cf1a71b59e3b7c2d8a2605a9cf7e0b125b13bc858e55083d88c62722d4507"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
uni_links_web:
dependency: transitive
description:
name: uni_links_web
sha256: "7539db908e25f67de2438e33cc1020b30ab94e66720b5677ba6763b25f6394df"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.0"
universal_io:
dependency: transitive
description:

View File

@ -95,7 +95,7 @@ dependencies:
webview_flutter: ^4.2.2
# 通过 scheme 打开APP 获取 参数
# uni_links: ^0.5.1
uni_links: ^0.5.1
dev_dependencies:
flutter_test: