opt: _routePush 逻辑分支

This commit is contained in:
guozhigq
2024-06-20 00:06:45 +08:00
parent 4dba8dfc2f
commit 6978c76fcd

View File

@ -1,5 +1,6 @@
import 'package:appscheme/appscheme.dart'; import 'package:appscheme/appscheme.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:pilipala/utils/route_push.dart'; import 'package:pilipala/utils/route_push.dart';
@ -19,7 +20,6 @@ class PiliSchame {
/// 完整链接进入 b23.无效 /// 完整链接进入 b23.无效
appScheme.getLatestScheme().then((SchemeEntity? value) { appScheme.getLatestScheme().then((SchemeEntity? value) {
print('getLatestScheme value: $value');
if (value != null) { if (value != null) {
_routePush(value); _routePush(value);
} }
@ -27,8 +27,6 @@ class PiliSchame {
/// 注册从外部打开的Scheme监听信息 # /// 注册从外部打开的Scheme监听信息 #
appScheme.registerSchemeListener().listen((SchemeEntity? event) { appScheme.registerSchemeListener().listen((SchemeEntity? event) {
print('registerSchemeListener event: $event');
if (event != null) { if (event != null) {
_routePush(event); _routePush(event);
} }
@ -41,16 +39,19 @@ class PiliSchame {
final String host = value.host; final String host = value.host;
final String path = value.path; final String path = value.path;
if (scheme == 'bilibili') { if (scheme == 'bilibili') {
if (host == 'root') { switch (host) {
case 'root':
Navigator.popUntil( Navigator.popUntil(
Get.context!, (Route<dynamic> route) => route.isFirst); Get.context!, (Route<dynamic> route) => route.isFirst);
} else if (host == 'space') { break;
case 'space':
final String mid = path.split('/').last; final String mid = path.split('/').last;
Get.toNamed<dynamic>( Get.toNamed<dynamic>(
'/member?mid=$mid', '/member?mid=$mid',
arguments: <String, dynamic>{'face': null}, arguments: <String, dynamic>{'face': null},
); );
} else if (host == 'video') { break;
case 'video':
String pathQuery = path.split('/').last; String pathQuery = path.split('/').last;
final numericRegex = RegExp(r'^[0-9]+$'); final numericRegex = RegExp(r'^[0-9]+$');
if (numericRegex.hasMatch(pathQuery)) { if (numericRegex.hasMatch(pathQuery)) {
@ -64,16 +65,21 @@ class PiliSchame {
} else { } else {
SmartDialog.showToast('投稿匹配失败'); SmartDialog.showToast('投稿匹配失败');
} }
} else if (host == 'live') { break;
case 'live':
final String roomId = path.split('/').last; final String roomId = path.split('/').last;
Get.toNamed<dynamic>('/liveRoom?roomid=$roomId', Get.toNamed<dynamic>(
arguments: <String, String?>{'liveItem': null, 'heroTag': roomId}); '/liveRoom?roomid=$roomId',
} else if (host == 'bangumi') { arguments: <String, String?>{'liveItem': null, 'heroTag': roomId},
);
break;
case 'bangumi':
if (path.startsWith('/season')) { if (path.startsWith('/season')) {
final String seasonId = path.split('/').last; final String seasonId = path.split('/').last;
RoutePush.bangumiPush(int.parse(seasonId), null); RoutePush.bangumiPush(int.parse(seasonId), null);
} }
} else if (host == 'opus') { break;
case 'opus':
if (path.startsWith('/detail')) { if (path.startsWith('/detail')) {
var opusId = path.split('/').last; var opusId = path.split('/').last;
Get.toNamed( Get.toNamed(
@ -85,9 +91,11 @@ class PiliSchame {
}, },
); );
} }
} else if (host == 'search') { break;
case 'search':
Get.toNamed('/searchResult', parameters: {'keyword': ''}); Get.toNamed('/searchResult', parameters: {'keyword': ''});
} else if (host == 'article') { break;
case 'article':
final String id = path.split('/').last.split('?').first; final String id = path.split('/').last.split('?').first;
Get.toNamed('/htmlRender', parameters: { Get.toNamed('/htmlRender', parameters: {
'url': 'https://www.bilibili.com/read/cv$id', 'url': 'https://www.bilibili.com/read/cv$id',
@ -95,12 +103,18 @@ class PiliSchame {
'id': 'cv$id', 'id': 'cv$id',
'dynamicType': 'read' 'dynamicType': 'read'
}); });
} else if (host == 'pgc') { break;
case 'pgc':
if (path.contains('ep')) { if (path.contains('ep')) {
final String lastPathSegment = path.split('/').last; final String lastPathSegment = path.split('/').last;
RoutePush.bangumiPush( RoutePush.bangumiPush(
null, int.parse(lastPathSegment.split('?').first)); null, int.parse(lastPathSegment.split('?').first));
} }
break;
default:
SmartDialog.showToast('未匹配地址,请联系开发者');
Clipboard.setData(ClipboardData(text: value.toJson().toString()));
break;
} }
} }
if (scheme == 'https') { if (scheme == 'https') {