Skip to content

Commit c5ae090

Browse files
committed
fix app links
1 parent 2ef887c commit c5ae090

File tree

8 files changed

+146
-109
lines changed

8 files changed

+146
-109
lines changed

lib/core/auth/noauth/di/noauth_di.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:thingsboard_app/core/auth/noauth/data/datasource/remote/i_noauth_remote_datasource.dart';
22
import 'package:thingsboard_app/core/auth/noauth/data/datasource/remote/noauth_remote_datasource.dart';
3-
import 'package:thingsboard_app/core/auth/noauth/data/repository/noauth_repository.dart';
3+
import 'package:thingsboard_app/core/auth/noauth/domain/repository/noauth_repository.dart';
44
import 'package:thingsboard_app/core/auth/noauth/domain/repository/i_noauth_repository.dart';
55
import 'package:thingsboard_app/core/auth/noauth/domain/usecases/switch_endpoint_usecase.dart';
66
import 'package:thingsboard_app/core/auth/noauth/presentation/bloc/bloc.dart';
@@ -9,6 +9,9 @@ import 'package:thingsboard_app/locator.dart';
99

1010
abstract final class NoAuthDi {
1111
static void init({required TbContext tbContext}) {
12+
if (getIt.hasScope("NoAuthDi")) {
13+
return;
14+
}
1215
getIt.pushNewScope(
1316
scopeName: 'NoAuthDi',
1417
init: (locator) {
@@ -47,6 +50,8 @@ abstract final class NoAuthDi {
4750
}
4851

4952
static void dispose() {
50-
getIt.dropScope('NoAuthDi');
53+
if(getIt.hasScope('NoAuthDi')) {
54+
getIt.dropScope('NoAuthDi');
55+
}
5156
}
5257
}

lib/core/auth/noauth/presentation/view/switch_endpoint_noauth_view.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class _SwitchEndpointNoAuthViewState
5252
});
5353
} else if (state is NoAuthDoneState) {
5454
GetIt.instance<NoAuthBloc>().close();
55-
if (tbClient.isPreVerificationToken()) {
56-
getIt<ThingsboardAppRouter>().navigateTo('/login/mfa',
57-
replace: true, clearStack: true,);
58-
} else {
59-
tbContext.updateRouteState();
60-
}
55+
// if (tbClient.isPreVerificationToken()) {
56+
// getIt<ThingsboardAppRouter>().navigateTo('/login/mfa',
57+
// replace: true, clearStack: true,);
58+
// } else {
59+
// tbContext.updateRouteState();
60+
// }
6161
}
6262
},
6363
buildWhen: (_, state) => state is! NoAuthDoneState,

lib/core/auth/noauth/routes/noauth_routes.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ class NoAuthRoutes extends TbRoutes {
1111
late final noAuthQrHandler = Handler(
1212
handlerFunc: (context, params) {
1313
final rawArgs = context?.settings?.arguments as Map<String, dynamic>?;
14-
final args = rawArgs == null ? null: SwitchEndpointArgs.fromJson(rawArgs);
15-
14+
if((rawArgs != null && rawArgs['secret'] == null) || rawArgs == null) {
15+
return SwitchEndpointNoAuthView(
16+
tbContext,
17+
arguments: null,
18+
);
19+
}
1620
return SwitchEndpointNoAuthView(
1721
tbContext,
18-
arguments: args,
22+
arguments: SwitchEndpointArgs.fromJson(rawArgs),
1923
);
2024
},
2125
);

lib/core/context/tb_context.dart

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class TbContext implements PopEntry {
101101
}) async {
102102
log.debug('TbContext:reinit()');
103103

104-
_handleRootState = false;
104+
_handleRootState = true;
105105

106106
tbClient = ThingsboardClient(
107107
endpoint,
@@ -142,7 +142,7 @@ class TbContext implements PopEntry {
142142

143143
void onError(ThingsboardError tbError) {
144144
log.error('onError', tbError, tbError.getStackTrace());
145-
_overlayService.showErrorNotification((_) => tbError.message!);
145+
_overlayService.showErrorNotification((_) => tbError.message!);
146146
}
147147

148148
void onLoadStarted() {
@@ -245,7 +245,13 @@ class TbContext implements PopEntry {
245245

246246
if (Utils.isConnectionError(e)) {
247247
final res = await _overlayService.showAlertDialog(
248-
content: (context) => DialogContent(title: S.of(context).connectionError, message: S.of(context).failedToConnectToServer, ok: S.of(context).retry,),);
248+
content:
249+
(context) => DialogContent(
250+
title: S.of(context).connectionError,
251+
message: S.of(context).failedToConnectToServer,
252+
ok: S.of(context).retry,
253+
),
254+
);
249255
if (res == true) {
250256
_overlayService.hideNotification();
251257
onUserLoaded();
@@ -276,7 +282,10 @@ class TbContext implements PopEntry {
276282
}
277283

278284
_appLinkStreamSubscription ??= appLinks.uriLinkStream.listen(
279-
(link) {
285+
(Uri? link) {
286+
if (link == null) {
287+
return;
288+
}
280289
thingsboardAppRouter.navigateByAppLink(link.toString());
281290
},
282291
onError: (err) {
@@ -303,54 +312,54 @@ class TbContext implements PopEntry {
303312
_appLinkStreamSubscription = null;
304313
}
305314

306-
Future<void> updateRouteState() async {
315+
Future<void> updateRouteState() async {
307316
log.debug(
308317
'TbContext:updateRouteState() ${currentState != null && currentState!.mounted}',
309318
);
310-
if (currentState != null && currentState!.mounted) {
311-
if (tbClient.isAuthenticated() && !tbClient.isPreVerificationToken()) {
312-
final defaultDashboardId = _defaultDashboardId();
313-
if (defaultDashboardId != null) {
314-
final bool fullscreen = _userForceFullscreen();
315-
if (!fullscreen) {
316-
await thingsboardAppRouter.navigateToDashboard(
317-
defaultDashboardId,
318-
animate: false,
319-
);
320-
thingsboardAppRouter.navigateTo(
321-
'/main',
322-
replace: true,
323-
closeDashboard: false,
324-
clearStack: true,
325-
transition: TransitionType.none,
326-
);
327-
} else {
328-
thingsboardAppRouter.navigateTo(
329-
'/fullscreenDashboard/$defaultDashboardId',
330-
replace: true,
331-
clearStack: true,
332-
transition: TransitionType.fadeIn,
333-
);
334-
}
335-
} else {
336-
thingsboardAppRouter.navigateTo(
337-
'/main',
338-
replace: true,
339-
clearStack: true,
340-
transition: TransitionType.fadeIn,
341-
transitionDuration: const Duration(milliseconds: 750),
342-
);
343-
}
344-
} else {
345-
thingsboardAppRouter.navigateTo(
346-
'/login',
347-
replace: true,
348-
clearStack: true,
349-
transition: TransitionType.fadeIn,
350-
transitionDuration: const Duration(milliseconds: 750),
351-
);
352-
}
319+
320+
if (!tbClient.isAuthenticated() || tbClient.isPreVerificationToken()) {
321+
thingsboardAppRouter.navigateTo(
322+
'/login',
323+
replace: true,
324+
clearStack: true,
325+
transition: TransitionType.fadeIn,
326+
transitionDuration: const Duration(milliseconds: 750),
327+
);
328+
return;
353329
}
330+
331+
final defaultDashboardId = _defaultDashboardId();
332+
if (defaultDashboardId == null) {
333+
thingsboardAppRouter.navigateTo(
334+
'/main',
335+
replace: true,
336+
clearStack: true,
337+
transition: TransitionType.fadeIn,
338+
transitionDuration: const Duration(milliseconds: 750),
339+
);
340+
return;
341+
}
342+
final bool fullscreen = _userForceFullscreen();
343+
if (fullscreen) {
344+
thingsboardAppRouter.navigateTo(
345+
'/fullscreenDashboard/$defaultDashboardId',
346+
replace: true,
347+
clearStack: true,
348+
transition: TransitionType.fadeIn,
349+
);
350+
return;
351+
}
352+
await thingsboardAppRouter.navigateToDashboard(
353+
defaultDashboardId,
354+
animate: false,
355+
);
356+
thingsboardAppRouter.navigateTo(
357+
'/main',
358+
replace: true,
359+
closeDashboard: false,
360+
clearStack: true,
361+
transition: TransitionType.none,
362+
);
354363
}
355364

356365
String? _defaultDashboardId() {

lib/core/init/inti_region_app.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_native_splash/flutter_native_splash.dart';
23
import 'package:thingsboard_app/constants/app_constants.dart';
34
import 'package:thingsboard_app/core/auth/login/select_region/model/region.dart';
45
import 'package:thingsboard_app/core/auth/login/select_region/select_region_screen.dart';
@@ -33,6 +34,7 @@ class _ThingsboardInitAppState extends TbPageState<ThingsboardInitRegionApp> {
3334

3435
if ((snapshot.hasError || snapshot.data == null) &&
3536
!ThingsboardAppConstants.ignoreRegionSelection) {
37+
FlutterNativeSplash.remove();
3638
return SelectRegionScreen(tbContext);
3739
}
3840
if (ThingsboardAppConstants.ignoreRegionSelection) {
@@ -44,13 +46,17 @@ class _ThingsboardInitAppState extends TbPageState<ThingsboardInitRegionApp> {
4446

4547
initTbContext();
4648

47-
return Scaffold(
48-
body: Container(
49-
alignment: Alignment.center,
50-
color: Colors.white,
51-
child: const TbProgressIndicator(size: 50.0),
52-
),
53-
);
49+
return FutureBuilder(
50+
future: initTbContext(),
51+
builder: (context, snapshot) {
52+
return Scaffold(
53+
body: Container(
54+
alignment: Alignment.center,
55+
color: Colors.white,
56+
child: !snapshot.hasData ? const SizedBox() : TbProgressIndicator(size: 50.0),
57+
),
58+
);
59+
});
5460
},
5561
);
5662
}

lib/modules/layout_pages/bloc/layout_pages_bloc.dart

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ import 'package:thingsboard_app/utils/services/layouts/i_layout_service.dart';
2727
import 'package:thingsboard_app/utils/ui/tb_text_styles.dart';
2828

2929
class LayoutPagesBloc extends Bloc<LayoutPagesEvent, LayoutPagesState> {
30-
LayoutPagesBloc({
31-
required this.layoutService,
32-
required this.tbContext,
33-
}) : super(const BottomBarLoadingState()) {
30+
LayoutPagesBloc({required this.layoutService, required this.tbContext})
31+
: super(const BottomBarLoadingState()) {
3432
on(_onEvent);
3533
}
3634

@@ -43,44 +41,7 @@ class LayoutPagesBloc extends Bloc<LayoutPagesEvent, LayoutPagesState> {
4341
) async {
4442
switch (event) {
4543
case BottomBarFetchEvent():
46-
final items = layoutService.getCachedPageLayouts();
47-
48-
layoutService.setBottomBarItems(
49-
items
50-
.map(
51-
(e) => TbMainNavigationItem(
52-
page: MainItemWidget(
53-
tbContext,
54-
path: e.path ?? '',
55-
child: getWidget(e),
56-
),
57-
title: getLabel(e, event.context),
58-
icon: getIcon(e),
59-
path: getPath(e),
60-
showAdditionalIcon: e.id == Pages.notifications,
61-
additionalIconSmall: e.id == Pages.notifications
62-
? notificationSmallNumberWidget()
63-
: null,
64-
additionalIconLarge: e.id == Pages.notifications
65-
? notificationLargeNumberWidget()
66-
: null,
67-
),
68-
)
69-
.toList(),
70-
more: TbMainNavigationItem(
71-
page: MainItemWidget(
72-
tbContext,
73-
path: '/more',
74-
child: MorePage(tbContext),
75-
),
76-
title: S.of(event.context).more,
77-
icon: Icons.menu_outlined,
78-
path: '/more',
79-
),
80-
);
81-
82-
emit(BottomBarDataState(items: layoutService.getBottomBarItems()));
83-
44+
await onBottomBarFetchEvent(event, emit);
8445
case BottomBarOrientationChangedEvent():
8546
layoutService.setDeviceScreenSize(
8647
event.screenSize,
@@ -90,6 +51,50 @@ class LayoutPagesBloc extends Bloc<LayoutPagesEvent, LayoutPagesState> {
9051
}
9152
}
9253

54+
Future<void> onBottomBarFetchEvent(
55+
BottomBarFetchEvent event,
56+
Emitter emit,
57+
) async {
58+
final items = layoutService.getCachedPageLayouts();
59+
layoutService.setBottomBarItems(
60+
items
61+
.map(
62+
(e) => TbMainNavigationItem(
63+
page: MainItemWidget(
64+
tbContext,
65+
path: e.path ?? '',
66+
child: getWidget(e),
67+
),
68+
title: getLabel(e, event.context),
69+
icon: getIcon(e),
70+
path: getPath(e),
71+
showAdditionalIcon: e.id == Pages.notifications,
72+
additionalIconSmall:
73+
e.id == Pages.notifications
74+
? notificationSmallNumberWidget()
75+
: null,
76+
additionalIconLarge:
77+
e.id == Pages.notifications
78+
? notificationLargeNumberWidget()
79+
: null,
80+
),
81+
)
82+
.toList(),
83+
more: TbMainNavigationItem(
84+
page: MainItemWidget(
85+
tbContext,
86+
path: '/more',
87+
child: MorePage(tbContext),
88+
),
89+
title: S.of(event.context).more,
90+
icon: Icons.menu_outlined,
91+
path: '/more',
92+
),
93+
);
94+
95+
emit(BottomBarDataState(items: layoutService.getBottomBarItems()));
96+
}
97+
9398
Widget getWidget(PageLayout pageLayout) {
9499
switch (pageLayout.id) {
95100
case Pages.home:

lib/thingsboard_app.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ class _ThingsBoardAppState extends State<ThingsboardApp> {
4242
theme: tbTheme,
4343
darkTheme: tbDarkTheme,
4444
navigatorKey: getIt<ThingsboardAppRouter>().navigatorKey,
45-
onGenerateRoute: getIt<ThingsboardAppRouter>().router.generator,
45+
onGenerateRoute: (settings) {
46+
final uri = Uri.tryParse(settings.name ?? '');
47+
if (uri != null && uri.host != '') {
48+
return getIt<ThingsboardAppRouter>().router
49+
.matchRoute(context, '/')
50+
.route;
51+
}
52+
return getIt<ThingsboardAppRouter>().router.generator(settings);
53+
},
4654
navigatorObservers: [
4755
getIt<ThingsboardAppRouter>().tbContext.routeObserver,
4856
],

0 commit comments

Comments
 (0)