Improve navigation from dashboard
This commit is contained in:
@@ -230,6 +230,33 @@ class _DashboardState extends TbContextState<Dashboard> {
|
|||||||
await controller.postWebMessage(message: webMessage, targetOrigin: Uri.parse('*'));
|
await controller.postWebMessage(message: webMessage, targetOrigin: Uri.parse('*'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> tryLocalNavigation(String? path) async {
|
||||||
|
log.debug("path: $path");
|
||||||
|
if (path != null) {
|
||||||
|
var parts = path.split("/");
|
||||||
|
if ([
|
||||||
|
'profile',
|
||||||
|
'devices',
|
||||||
|
'assets',
|
||||||
|
'dashboards',
|
||||||
|
'dashboard',
|
||||||
|
'customers',
|
||||||
|
'auditLogs'
|
||||||
|
].contains(parts[0])) {
|
||||||
|
if ((parts[0] == 'dashboard' || parts[0] == 'dashboards') && parts.length > 1) {
|
||||||
|
var dashboardId = parts[1];
|
||||||
|
await navigateToDashboard(dashboardId);
|
||||||
|
} else if (parts[0] != 'dashboard') {
|
||||||
|
var targetPath = '/$path';
|
||||||
|
if (parts[0] == 'devices' && widget._home != true) {
|
||||||
|
targetPath = '/devicesPage';
|
||||||
|
}
|
||||||
|
await navigateTo(targetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
@@ -290,22 +317,7 @@ class _DashboardState extends TbContextState<Dashboard> {
|
|||||||
}
|
}
|
||||||
log.debug("path: $path");
|
log.debug("path: $path");
|
||||||
log.debug("params: $params");
|
log.debug("params: $params");
|
||||||
if (path != null) {
|
tryLocalNavigation(path);
|
||||||
if ([
|
|
||||||
'profile',
|
|
||||||
'devices',
|
|
||||||
'assets',
|
|
||||||
'dashboards',
|
|
||||||
'customers',
|
|
||||||
'auditLogs'
|
|
||||||
].contains(path)) {
|
|
||||||
var targetPath = '/$path';
|
|
||||||
if (path == 'devices' && widget._home != true) {
|
|
||||||
targetPath = '/devicesPage';
|
|
||||||
}
|
|
||||||
navigateTo(targetPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
webViewController.addJavaScriptHandler(handlerName: "tbMobileHandler", callback: (args) async {
|
webViewController.addJavaScriptHandler(handlerName: "tbMobileHandler", callback: (args) async {
|
||||||
@@ -317,25 +329,23 @@ class _DashboardState extends TbContextState<Dashboard> {
|
|||||||
var uri = navigationAction.request.url!;
|
var uri = navigationAction.request.url!;
|
||||||
var uriString = uri.toString();
|
var uriString = uri.toString();
|
||||||
log.debug('shouldOverrideUrlLoading $uriString');
|
log.debug('shouldOverrideUrlLoading $uriString');
|
||||||
if (![
|
if (Platform.isAndroid || Platform.isIOS && navigationAction.iosWKNavigationType == IOSWKNavigationType.LINK_ACTIVATED) {
|
||||||
"http",
|
if (uriString.startsWith(ThingsboardAppConstants.thingsBoardApiEndpoint)) {
|
||||||
"https",
|
var target = uriString.substring(ThingsboardAppConstants.thingsBoardApiEndpoint.length);
|
||||||
"file",
|
if (!target.startsWith("?accessToken")) {
|
||||||
"chrome",
|
if (target.startsWith("/")) {
|
||||||
"data",
|
target = target.substring(1);
|
||||||
"javascript",
|
}
|
||||||
"about"
|
await tryLocalNavigation(target);
|
||||||
].contains(uri.scheme)) {
|
return NavigationActionPolicy.CANCEL;
|
||||||
if (await canLaunch(uriString)) {
|
}
|
||||||
// Launch the App
|
} else if (await canLaunch(uriString)) {
|
||||||
await launch(
|
await launch(
|
||||||
uriString,
|
uriString,
|
||||||
);
|
);
|
||||||
// and cancel the request
|
|
||||||
return NavigationActionPolicy.CANCEL;
|
return NavigationActionPolicy.CANCEL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Platform.isIOS ? NavigationActionPolicy.ALLOW : NavigationActionPolicy.CANCEL;
|
return Platform.isIOS ? NavigationActionPolicy.ALLOW : NavigationActionPolicy.CANCEL;
|
||||||
},
|
},
|
||||||
onUpdateVisitedHistory: (controller, url, androidIsReload) async {
|
onUpdateVisitedHistory: (controller, url, androidIsReload) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user