diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index f3009cd..ef69853 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -24,6 +24,13 @@ + + + + + + + diff --git a/lib/config/server.dart b/lib/config/server.dart index d626f1a..4ce406b 100644 --- a/lib/config/server.dart +++ b/lib/config/server.dart @@ -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"; \ No newline at end of file diff --git a/lib/modules/application/application_controller.dart b/lib/modules/application/application_controller.dart index 317b9d5..83f4303 100644 --- a/lib/modules/application/application_controller.dart +++ b/lib/modules/application/application_controller.dart @@ -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 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 = [ diff --git a/pubspec.lock b/pubspec.lock index acf7fdf..d2073b7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 742dbae..1ad26bf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: