From b6361feca9468a82049f6ed3226bb1a3fed406f5 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 18 Aug 2021 21:07:19 +0300 Subject: [PATCH] Partial web app support --- lib/core/auth/login/login_page.dart | 4 +- .../login/reset_password_request_page.dart | 4 +- lib/core/context/tb_context.dart | 30 ++++++++----- lib/core/context/tb_context_widget.dart | 12 ++--- lib/core/entity/entities_base.dart | 4 +- lib/core/entity/entities_list_widget.dart | 4 +- lib/core/entity/entity_details_page.dart | 4 +- lib/core/init/init_app.dart | 4 +- lib/main.dart | 4 +- lib/modules/alarm/alarms_base.dart | 4 +- lib/modules/alarm/alarms_page.dart | 4 +- lib/modules/asset/assets_page.dart | 4 +- .../audit_log/audit_log_details_page.dart | 4 +- lib/modules/audit_log/audit_logs_base.dart | 4 +- lib/modules/audit_log/audit_logs_page.dart | 4 +- lib/modules/customer/customers_page.dart | 4 +- lib/modules/dashboard/dashboard.dart | 45 ++++++++++++------- lib/modules/dashboard/dashboard_page.dart | 4 +- lib/modules/dashboard/dashboards_base.dart | 4 +- lib/modules/dashboard/dashboards_grid.dart | 4 +- lib/modules/dashboard/dashboards_page.dart | 4 +- .../dashboard/fullscreen_dashboard_page.dart | 4 +- .../dashboard/main_dashboard_page.dart | 4 +- lib/modules/device/device_profiles_base.dart | 8 ++-- lib/modules/device/devices_base.dart | 4 +- lib/modules/device/devices_list_page.dart | 4 +- lib/modules/device/devices_main_page.dart | 4 +- lib/modules/device/devices_page.dart | 4 +- lib/modules/home/home_page.dart | 8 ++-- lib/modules/main/main_page.dart | 4 +- lib/modules/more/more_page.dart | 4 +- lib/modules/profile/change_password_page.dart | 4 +- lib/modules/profile/profile_page.dart | 4 +- lib/modules/tenant/tenants_page.dart | 4 +- lib/modules/tenant/tenants_widget.dart | 4 +- lib/utils/services/_tb_app_storage.dart | 3 ++ lib/utils/services/tb_app_storage.dart | 3 ++ lib/utils/services/tb_secure_storage.dart | 2 + lib/utils/services/tb_web_local_storage.dart | 25 +++++++++++ lib/utils/ui/qr_code_scanner.dart | 4 +- lib/widgets/tb_app_bar.dart | 8 ++-- pubspec.lock | 7 +++ pubspec.yaml | 1 + 43 files changed, 169 insertions(+), 107 deletions(-) create mode 100644 lib/utils/services/_tb_app_storage.dart create mode 100644 lib/utils/services/tb_app_storage.dart create mode 100644 lib/utils/services/tb_web_local_storage.dart diff --git a/lib/core/auth/login/login_page.dart b/lib/core/auth/login/login_page.dart index 753f4a0..7fd413b 100644 --- a/lib/core/auth/login/login_page.dart +++ b/lib/core/auth/login/login_page.dart @@ -14,7 +14,7 @@ import 'package:thingsboard_client/thingsboard_client.dart'; import 'login_page_background.dart'; -class LoginPage extends TbPageWidget { +class LoginPage extends TbPageWidget { LoginPage(TbContext tbContext) : super(tbContext); @@ -23,7 +23,7 @@ class LoginPage extends TbPageWidget { } -class _LoginPageState extends TbPageState { +class _LoginPageState extends TbPageState { final ButtonStyle _oauth2ButtonWithTextStyle = OutlinedButton.styleFrom(padding: EdgeInsets.all(16), diff --git a/lib/core/auth/login/reset_password_request_page.dart b/lib/core/auth/login/reset_password_request_page.dart index a8c14bf..b9f830a 100644 --- a/lib/core/auth/login/reset_password_request_page.dart +++ b/lib/core/auth/login/reset_password_request_page.dart @@ -7,7 +7,7 @@ import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'package:thingsboard_app/widgets/tb_progress_indicator.dart'; -class ResetPasswordRequestPage extends TbPageWidget { +class ResetPasswordRequestPage extends TbPageWidget { ResetPasswordRequestPage(TbContext tbContext) : super(tbContext); @@ -16,7 +16,7 @@ class ResetPasswordRequestPage extends TbPageWidget { +class _ResetPasswordRequestPageState extends TbPageState { final _isLoadingNotifier = ValueNotifier(false); diff --git a/lib/core/context/tb_context.dart b/lib/core/context/tb_context.dart index 4d20215..b371e42 100644 --- a/lib/core/context/tb_context.dart +++ b/lib/core/context/tb_context.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'dart:io'; - +import 'package:universal_platform/universal_platform.dart'; import 'package:device_info/device_info.dart'; import 'package:fluro/fluro.dart'; import 'package:flutter/foundation.dart'; @@ -13,7 +12,7 @@ import 'package:thingsboard_app/core/auth/oauth2/tb_oauth2_client.dart'; import 'package:thingsboard_app/modules/main/main_page.dart'; import 'package:thingsboard_app/utils/services/widget_action_handler.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; -import 'package:thingsboard_app/utils/services/tb_secure_storage.dart'; +import 'package:thingsboard_app/utils/services/tb_app_storage.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; enum NotificationType { @@ -145,8 +144,9 @@ class TbContext { return true; }()); _initialized = true; + var storage = createAppStorage(); tbClient = ThingsboardClient(ThingsboardAppConstants.thingsBoardApiEndpoint, - storage: TbSecureStorage(), + storage: storage, onUserLoaded: onUserLoaded, onError: onError, onLoadStarted: onLoadStarted, @@ -156,15 +156,21 @@ class TbContext { oauth2Client = TbOAuth2Client(tbContext: this, appSecretProvider: AppSecretProvider.local()); try { - if (Platform.isAndroid) { + if (UniversalPlatform.isAndroid) { _androidInfo = await deviceInfoPlugin.androidInfo; _oauth2PlatformType = PlatformType.ANDROID; - } else if (Platform.isIOS) { + } else if (UniversalPlatform.isIOS) { _iosInfo = await deviceInfoPlugin.iosInfo; _oauth2PlatformType = PlatformType.IOS; + } else { + _oauth2PlatformType = PlatformType.WEB; + } + if (UniversalPlatform.isAndroid || UniversalPlatform.isIOS) { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + packageName = packageInfo.packageName; + } else { + packageName = 'web.app'; } - PackageInfo packageInfo = await PackageInfo.fromPlatform(); - packageName = packageInfo.packageName; await tbClient.init(); } catch (e, s) { log.error('Failed to init tbContext: $e', e, s); @@ -337,9 +343,9 @@ class TbContext { } bool isPhysicalDevice() { - if (Platform.isAndroid) { + if (UniversalPlatform.isAndroid) { return _androidInfo!.isPhysicalDevice; - } else if (Platform.isIOS) { + } else if (UniversalPlatform.isIOS) { return _iosInfo!.isPhysicalDevice; } else { return false; @@ -348,9 +354,9 @@ class TbContext { String userAgent() { String userAgent = 'Mozilla/5.0'; - if (Platform.isAndroid) { + if (UniversalPlatform.isAndroid) { userAgent += ' (Linux; Android ${_androidInfo!.version.release}; ${_androidInfo!.model})'; - } else if (Platform.isIOS) { + } else if (UniversalPlatform.isIOS) { userAgent += ' (${_iosInfo!.model})'; } userAgent += ' AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36'; diff --git a/lib/core/context/tb_context_widget.dart b/lib/core/context/tb_context_widget.dart index dd4072d..976d281 100644 --- a/lib/core/context/tb_context_widget.dart +++ b/lib/core/context/tb_context_widget.dart @@ -12,13 +12,13 @@ abstract class TbContextStatelessWidget extends StatelessWidget with HasTbContex } } -abstract class TbContextWidget, S extends TbContextState> extends StatefulWidget with HasTbContext { +abstract class TbContextWidget extends StatefulWidget with HasTbContext { TbContextWidget(TbContext tbContext, {Key? key}) : super(key: key) { setTbContext(tbContext); } } -abstract class TbContextState, S extends TbContextState> extends State with HasTbContext { +abstract class TbContextState extends State with HasTbContext { final bool handleLoading; @@ -47,11 +47,11 @@ mixin TbMainState { } -abstract class TbPageWidget, S extends TbPageState> extends TbContextWidget { +abstract class TbPageWidget extends TbContextWidget { TbPageWidget(TbContext tbContext, {Key? key}) : super(tbContext, key: key); } -abstract class TbPageState, S extends TbPageState> extends TbContextState with RouteAware { +abstract class TbPageState extends TbContextState with RouteAware { TbPageState({bool handleUserLoaded = false}): super(handleLoading: true); @override @@ -79,7 +79,7 @@ abstract class TbPageState, S extends TbPageState { +class TextContextWidget extends TbContextWidget { final String text; @@ -90,7 +90,7 @@ class TextContextWidget extends TbContextWidget { +class _TextContextWidgetState extends TbContextState { @override Widget build(BuildContext context) { diff --git a/lib/core/entity/entities_base.dart b/lib/core/entity/entities_base.dart index 44347e1..8c3e3ac 100644 --- a/lib/core/entity/entities_base.dart +++ b/lib/core/entity/entities_base.dart @@ -193,7 +193,7 @@ class TimePageLinkController extends PageKeyController { } -abstract class BaseEntitiesWidget extends TbContextWidget, BaseEntitiesState> with EntitiesBase { +abstract class BaseEntitiesWidget extends TbContextWidget with EntitiesBase { final bool searchMode; final PageKeyController

pageKeyController; @@ -211,7 +211,7 @@ abstract class BaseEntitiesWidget extends TbContextWidget extends TbContextState, BaseEntitiesState> { +abstract class BaseEntitiesState extends TbContextState> { late final PagingController pagingController; Completer? _refreshCompleter; diff --git a/lib/core/entity/entities_list_widget.dart b/lib/core/entity/entities_list_widget.dart index 56bfe38..2972269 100644 --- a/lib/core/entity/entities_list_widget.dart +++ b/lib/core/entity/entities_list_widget.dart @@ -41,7 +41,7 @@ abstract class EntitiesListPageLinkWidget extends EntitiesListWidget extends TbContextWidget, _EntitiesListWidgetState> with EntitiesBase { +abstract class EntitiesListWidget extends TbContextWidget with EntitiesBase { final EntitiesListWidgetController? _controller; @@ -58,7 +58,7 @@ abstract class EntitiesListWidget extends TbContextWidget extends TbContextState, _EntitiesListWidgetState> { +class _EntitiesListWidgetState extends TbContextState> { final EntitiesListWidgetController? _controller; diff --git a/lib/core/entity/entity_details_page.dart b/lib/core/entity/entity_details_page.dart index 8c71991..fb47b91 100644 --- a/lib/core/entity/entity_details_page.dart +++ b/lib/core/entity/entity_details_page.dart @@ -7,7 +7,7 @@ import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'package:thingsboard_app/widgets/tb_progress_indicator.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; -abstract class EntityDetailsPage extends TbPageWidget, _EntityDetailsPageState> { +abstract class EntityDetailsPage extends TbPageWidget { final labelTextStyle = TextStyle( color: Color(0xFF757575), @@ -56,7 +56,7 @@ abstract class EntityDetailsPage extends TbPageWidget extends TbPageState, _EntityDetailsPageState> { +class _EntityDetailsPageState extends TbPageState> { late Future entityFuture; late ValueNotifier titleValue; diff --git a/lib/core/init/init_app.dart b/lib/core/init/init_app.dart index 625a56a..a545d29 100644 --- a/lib/core/init/init_app.dart +++ b/lib/core/init/init_app.dart @@ -4,7 +4,7 @@ import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/widgets/tb_progress_indicator.dart'; -class ThingsboardInitApp extends TbPageWidget { +class ThingsboardInitApp extends TbPageWidget { ThingsboardInitApp(TbContext tbContext, {Key? key}) : super(tbContext, key: key); @@ -13,7 +13,7 @@ class ThingsboardInitApp extends TbPageWidget { +class _ThingsboardInitAppState extends TbPageState { @override void initState() { diff --git a/lib/main.dart b/lib/main.dart index 15e5ee5..7760760 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,4 @@ -import 'dart:io'; +import 'package:universal_platform/universal_platform.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -19,7 +19,7 @@ void main() async { // await FlutterDownloader.initialize(); // await Permission.storage.request(); - if (Platform.isAndroid) { + if (UniversalPlatform.isAndroid) { await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true); } diff --git a/lib/modules/alarm/alarms_base.dart b/lib/modules/alarm/alarms_base.dart index 27f8111..5471cad 100644 --- a/lib/modules/alarm/alarms_base.dart +++ b/lib/modules/alarm/alarms_base.dart @@ -86,7 +86,7 @@ class AlarmQueryController extends PageKeyController { } -class AlarmCard extends TbContextWidget { +class AlarmCard extends TbContextWidget { final AlarmInfo alarm; @@ -97,7 +97,7 @@ class AlarmCard extends TbContextWidget { } -class _AlarmCardState extends TbContextState { +class _AlarmCardState extends TbContextState { bool loading = false; AlarmInfo alarm; diff --git a/lib/modules/alarm/alarms_page.dart b/lib/modules/alarm/alarms_page.dart index 839c58a..f17f440 100644 --- a/lib/modules/alarm/alarms_page.dart +++ b/lib/modules/alarm/alarms_page.dart @@ -6,7 +6,7 @@ import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'alarms_list.dart'; -class AlarmsPage extends TbContextWidget { +class AlarmsPage extends TbContextWidget { final bool searchMode; @@ -17,7 +17,7 @@ class AlarmsPage extends TbContextWidget { } -class _AlarmsPageState extends TbContextState with AutomaticKeepAliveClientMixin { +class _AlarmsPageState extends TbContextState with AutomaticKeepAliveClientMixin { final AlarmQueryController _alarmQueryController = AlarmQueryController(); diff --git a/lib/modules/asset/assets_page.dart b/lib/modules/asset/assets_page.dart index d569d9b..1f301a6 100644 --- a/lib/modules/asset/assets_page.dart +++ b/lib/modules/asset/assets_page.dart @@ -6,7 +6,7 @@ import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'assets_list.dart'; -class AssetsPage extends TbPageWidget { +class AssetsPage extends TbPageWidget { final bool searchMode; @@ -17,7 +17,7 @@ class AssetsPage extends TbPageWidget { } -class _AssetsPageState extends TbPageState { +class _AssetsPageState extends TbPageState { final PageLinkController _pageLinkController = PageLinkController(); diff --git a/lib/modules/audit_log/audit_log_details_page.dart b/lib/modules/audit_log/audit_log_details_page.dart index 3bc43f7..e821f20 100644 --- a/lib/modules/audit_log/audit_log_details_page.dart +++ b/lib/modules/audit_log/audit_log_details_page.dart @@ -8,7 +8,7 @@ import 'package:thingsboard_app/modules/audit_log/audit_logs_base.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; -class AuditLogDetailsPage extends TbContextWidget { +class AuditLogDetailsPage extends TbContextWidget { final AuditLog auditLog; @@ -19,7 +19,7 @@ class AuditLogDetailsPage extends TbContextWidget { +class _AuditLogDetailsPageState extends TbContextState { final labelTextStyle = TextStyle( color: Color(0xFF757575), diff --git a/lib/modules/audit_log/audit_logs_base.dart b/lib/modules/audit_log/audit_logs_base.dart index 93b8928..847f78b 100644 --- a/lib/modules/audit_log/audit_logs_base.dart +++ b/lib/modules/audit_log/audit_logs_base.dart @@ -72,7 +72,7 @@ mixin AuditLogsBase on EntitiesBase { } } -class AuditLogCard extends TbContextWidget { +class AuditLogCard extends TbContextWidget { final AuditLog auditLog; @@ -83,7 +83,7 @@ class AuditLogCard extends TbContextWidget { } -class _AuditLogCardState extends TbContextState { +class _AuditLogCardState extends TbContextState { final entityDateFormat = DateFormat('yyyy-MM-dd'); diff --git a/lib/modules/audit_log/audit_logs_page.dart b/lib/modules/audit_log/audit_logs_page.dart index d0d6d1c..4ebf7c2 100644 --- a/lib/modules/audit_log/audit_logs_page.dart +++ b/lib/modules/audit_log/audit_logs_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'package:thingsboard_app/modules/audit_log/audit_logs_list.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; -class AuditLogsPage extends TbPageWidget { +class AuditLogsPage extends TbPageWidget { final bool searchMode; @@ -16,7 +16,7 @@ class AuditLogsPage extends TbPageWidget { } -class _AuditLogsPageState extends TbPageState { +class _AuditLogsPageState extends TbPageState { final TimePageLinkController _timePageLinkController = TimePageLinkController(); diff --git a/lib/modules/customer/customers_page.dart b/lib/modules/customer/customers_page.dart index 6b6402c..6deda21 100644 --- a/lib/modules/customer/customers_page.dart +++ b/lib/modules/customer/customers_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'package:thingsboard_app/modules/customer/customers_list.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; -class CustomersPage extends TbPageWidget { +class CustomersPage extends TbPageWidget { final bool searchMode; @@ -16,7 +16,7 @@ class CustomersPage extends TbPageWidget { } -class _CustomersPageState extends TbPageState { +class _CustomersPageState extends TbPageState { final PageLinkController _pageLinkController = PageLinkController(); diff --git a/lib/modules/dashboard/dashboard.dart b/lib/modules/dashboard/dashboard.dart index 629f012..88bcff2 100644 --- a/lib/modules/dashboard/dashboard.dart +++ b/lib/modules/dashboard/dashboard.dart @@ -10,6 +10,7 @@ import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/widgets/tb_progress_indicator.dart'; import 'package:thingsboard_app/widgets/two_value_listenable_builder.dart'; +import 'package:universal_platform/universal_platform.dart'; import 'package:url_launcher/url_launcher.dart'; class DashboardController { @@ -65,7 +66,7 @@ typedef DashboardTitleCallback = void Function(String title); typedef DashboardControllerCallback = void Function(DashboardController controller); -class Dashboard extends TbContextWidget { +class Dashboard extends TbContextWidget { final bool? _home; final bool _activeByDefault; @@ -84,7 +85,7 @@ class Dashboard extends TbContextWidget { } -class _DashboardState extends TbContextState { +class _DashboardState extends TbContextState { final Completer _controller = Completer(); @@ -145,21 +146,27 @@ class _DashboardState extends TbContextState { 'refreshToken': tbClient.getRefreshToken()! } }; - var controller = await _controller.future; - await controller.postWebMessage(message: WebMessage(data: jsonEncode(windowMessage)), targetOrigin: Uri.parse('*')); + if (!UniversalPlatform.isWeb) { + var controller = await _controller.future; + await controller.postWebMessage( + message: WebMessage(data: jsonEncode(windowMessage)), + targetOrigin: Uri.parse('*')); + } } } } Future _goBack() async { - if (_dashboardController.rightLayoutOpened.value) { - await _toggleRightLayout(); - return false; - } - var controller = await _controller.future; - if (await controller.canGoBack()) { - await controller.goBack(); - return false; + if (!UniversalPlatform.isWeb) { + if (_dashboardController.rightLayoutOpened.value) { + await _toggleRightLayout(); + return false; + } + var controller = await _controller.future; + if (await controller.canGoBack()) { + await controller.goBack(); + return false; + } } return true; } @@ -188,7 +195,10 @@ class _DashboardState extends TbContextState { Future _openDashboard(String dashboardId, {String? state, bool? hideToolbar, bool fullscreen = false}) async { _fullscreen = fullscreen; dashboardLoading.value = true; - var controller = await _controller.future; + InAppWebViewController? controller; + if (!UniversalPlatform.isWeb) { + controller = await _controller.future; + } var windowMessage = { 'type': 'openDashboardMessage', 'data': { @@ -205,7 +215,10 @@ class _DashboardState extends TbContextState { windowMessage['data']['hideToolbar'] = true; } var webMessage = WebMessage(data: jsonEncode(windowMessage)); - await controller.postWebMessage(message: webMessage, targetOrigin: Uri.parse('*')); + if (!UniversalPlatform.isWeb) { + await controller!.postWebMessage( + message: webMessage, targetOrigin: Uri.parse('*')); + } } Future _toggleRightLayout() async { @@ -239,6 +252,7 @@ class _DashboardState extends TbContextState { } else { return Stack( children: [ + UniversalPlatform.isWeb ? Center(child: Text('Not implemented!')) : InAppWebView( key: webViewKey, initialUrlRequest: URLRequest(url: _initialUrl), @@ -348,7 +362,8 @@ class _DashboardState extends TbContextState { action: PermissionRequestResponseAction.GRANT); }, ), - TwoValueListenableBuilder( + if (!UniversalPlatform.isWeb) + TwoValueListenableBuilder( firstValueListenable: dashboardLoading, secondValueListenable: dashboardActive, builder: (BuildContext context, bool loading, bool active, child) { diff --git a/lib/modules/dashboard/dashboard_page.dart b/lib/modules/dashboard/dashboard_page.dart index 0144974..13cc96d 100644 --- a/lib/modules/dashboard/dashboard_page.dart +++ b/lib/modules/dashboard/dashboard_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/modules/dashboard/dashboard.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; -class DashboardPage extends TbPageWidget { +class DashboardPage extends TbPageWidget { final String? _dashboardTitle; final String? _dashboardId; @@ -24,7 +24,7 @@ class DashboardPage extends TbPageWidget { } -class _DashboardPageState extends TbPageState { +class _DashboardPageState extends TbPageState { late ValueNotifier dashboardTitleValue; diff --git a/lib/modules/dashboard/dashboards_base.dart b/lib/modules/dashboard/dashboards_base.dart index c464f18..6ebb550 100644 --- a/lib/modules/dashboard/dashboards_base.dart +++ b/lib/modules/dashboard/dashboards_base.dart @@ -127,7 +127,7 @@ mixin DashboardsBase on EntitiesBase { } -class DashboardGridCard extends TbContextWidget { +class DashboardGridCard extends TbContextWidget { final DashboardInfo dashboard; @@ -138,7 +138,7 @@ class DashboardGridCard extends TbContextWidget { +class _DashboardGridCardState extends TbContextState { _DashboardGridCardState(): super(); diff --git a/lib/modules/dashboard/dashboards_grid.dart b/lib/modules/dashboard/dashboards_grid.dart index c7c8554..deb9235 100644 --- a/lib/modules/dashboard/dashboards_grid.dart +++ b/lib/modules/dashboard/dashboards_grid.dart @@ -7,7 +7,7 @@ import 'package:thingsboard_client/thingsboard_client.dart'; import 'dashboards_base.dart'; -class DashboardsGridWidget extends TbContextWidget { +class DashboardsGridWidget extends TbContextWidget { DashboardsGridWidget(TbContext tbContext) : super(tbContext); @@ -16,7 +16,7 @@ class DashboardsGridWidget extends TbContextWidget { +class _DashboardsGridWidgetState extends TbContextState { final PageLinkController _pageLinkController = PageLinkController(); diff --git a/lib/modules/dashboard/dashboards_page.dart b/lib/modules/dashboard/dashboards_page.dart index 7f8d441..0a7d6fc 100644 --- a/lib/modules/dashboard/dashboards_page.dart +++ b/lib/modules/dashboard/dashboards_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'dashboards_grid.dart'; -class DashboardsPage extends TbPageWidget { +class DashboardsPage extends TbPageWidget { DashboardsPage(TbContext tbContext) : super(tbContext); @@ -14,7 +14,7 @@ class DashboardsPage extends TbPageWidget } -class _DashboardsPageState extends TbPageState { +class _DashboardsPageState extends TbPageState { @override Widget build(BuildContext context) { diff --git a/lib/modules/dashboard/fullscreen_dashboard_page.dart b/lib/modules/dashboard/fullscreen_dashboard_page.dart index e81b988..94dc086 100644 --- a/lib/modules/dashboard/fullscreen_dashboard_page.dart +++ b/lib/modules/dashboard/fullscreen_dashboard_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/modules/dashboard/dashboard.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; -class FullscreenDashboardPage extends TbPageWidget { +class FullscreenDashboardPage extends TbPageWidget { final String fullscreenDashboardId; final String? _dashboardTitle; @@ -19,7 +19,7 @@ class FullscreenDashboardPage extends TbPageWidget { +class _FullscreenDashboardPageState extends TbPageState { late ValueNotifier dashboardTitleValue; final ValueNotifier showBackValue = ValueNotifier(false); diff --git a/lib/modules/dashboard/main_dashboard_page.dart b/lib/modules/dashboard/main_dashboard_page.dart index fdb56b7..17c3831 100644 --- a/lib/modules/dashboard/main_dashboard_page.dart +++ b/lib/modules/dashboard/main_dashboard_page.dart @@ -43,7 +43,7 @@ class MainDashboardPageController { } -class MainDashboardPage extends TbContextWidget { +class MainDashboardPage extends TbContextWidget { final String? _dashboardTitle; final MainDashboardPageController? _controller; @@ -60,7 +60,7 @@ class MainDashboardPage extends TbContextWidget with TickerProviderStateMixin { +class _MainDashboardPageState extends TbContextState with TickerProviderStateMixin { late ValueNotifier dashboardTitleValue; final ValueNotifier hasRightLayout = ValueNotifier(false); diff --git a/lib/modules/device/device_profiles_base.dart b/lib/modules/device/device_profiles_base.dart index ba25841..2f846aa 100644 --- a/lib/modules/device/device_profiles_base.dart +++ b/lib/modules/device/device_profiles_base.dart @@ -63,7 +63,7 @@ class RefreshDeviceCounts { Future Function()? onRefresh; } -class AllDevicesCard extends TbContextWidget { +class AllDevicesCard extends TbContextWidget { final RefreshDeviceCounts refreshDeviceCounts; @@ -74,7 +74,7 @@ class AllDevicesCard extends TbContextWidget { +class _AllDevicesCardState extends TbContextState { final StreamController _activeDevicesCount = StreamController.broadcast(); final StreamController _inactiveDevicesCount = StreamController.broadcast(); @@ -240,7 +240,7 @@ class _AllDevicesCardState extends TbContextState { +class DeviceProfileCard extends TbContextWidget { final DeviceProfileInfo deviceProfile; @@ -251,7 +251,7 @@ class DeviceProfileCard extends TbContextWidget { +class _DeviceProfileCardState extends TbContextState { late Future activeDevicesCount; late Future inactiveDevicesCount; diff --git a/lib/modules/device/devices_base.dart b/lib/modules/device/devices_base.dart index abe8f7b..07d192f 100644 --- a/lib/modules/device/devices_base.dart +++ b/lib/modules/device/devices_base.dart @@ -78,7 +78,7 @@ class DeviceQueryController extends PageKeyController { } -class DeviceCard extends TbContextWidget { +class DeviceCard extends TbContextWidget { final EntityData device; final bool listWidgetCard; @@ -91,7 +91,7 @@ class DeviceCard extends TbContextWidget { } -class _DeviceCardState extends TbContextState { +class _DeviceCardState extends TbContextState { final entityDateFormat = DateFormat('yyyy-MM-dd'); diff --git a/lib/modules/device/devices_list_page.dart b/lib/modules/device/devices_list_page.dart index 7cee485..a7005ae 100644 --- a/lib/modules/device/devices_list_page.dart +++ b/lib/modules/device/devices_list_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/modules/device/devices_base.dart'; import 'package:thingsboard_app/modules/device/devices_list.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; -class DevicesListPage extends TbPageWidget { +class DevicesListPage extends TbPageWidget { final String? deviceType; final bool? active; @@ -18,7 +18,7 @@ class DevicesListPage extends TbPageWidget { +class _DevicesListPageState extends TbPageState { late final DeviceQueryController _deviceQueryController; diff --git a/lib/modules/device/devices_main_page.dart b/lib/modules/device/devices_main_page.dart index 6015a1d..346fe2d 100644 --- a/lib/modules/device/devices_main_page.dart +++ b/lib/modules/device/devices_main_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'package:thingsboard_app/modules/device/device_profiles_grid.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; -class DevicesMainPage extends TbContextWidget { +class DevicesMainPage extends TbContextWidget { DevicesMainPage(TbContext tbContext) : super(tbContext); @@ -14,7 +14,7 @@ class DevicesMainPage extends TbContextWidget with AutomaticKeepAliveClientMixin { +class _DevicesMainPageState extends TbContextState with AutomaticKeepAliveClientMixin { final PageLinkController _pageLinkController = PageLinkController(); diff --git a/lib/modules/device/devices_page.dart b/lib/modules/device/devices_page.dart index 822d0e5..ad364c9 100644 --- a/lib/modules/device/devices_page.dart +++ b/lib/modules/device/devices_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'package:thingsboard_app/modules/device/device_profiles_grid.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; -class DevicesPage extends TbPageWidget { +class DevicesPage extends TbPageWidget { DevicesPage(TbContext tbContext) : super(tbContext); @@ -14,7 +14,7 @@ class DevicesPage extends TbPageWidget { } -class _DevicesPageState extends TbPageState { +class _DevicesPageState extends TbPageState { final PageLinkController _pageLinkController = PageLinkController(); diff --git a/lib/modules/home/home_page.dart b/lib/modules/home/home_page.dart index b508763..cd3dffc 100644 --- a/lib/modules/home/home_page.dart +++ b/lib/modules/home/home_page.dart @@ -10,7 +10,7 @@ import 'package:thingsboard_app/modules/tenant/tenants_widget.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; -class HomePage extends TbContextWidget { +class HomePage extends TbContextWidget { HomePage(TbContext tbContext) : super(tbContext); @@ -19,7 +19,7 @@ class HomePage extends TbContextWidget { } -class _HomePageState extends TbContextState with AutomaticKeepAliveClientMixin { +class _HomePageState extends TbContextState with AutomaticKeepAliveClientMixin { @override void initState() { @@ -94,7 +94,7 @@ class _HomePageState extends TbContextState with Autom } -class HomeDashboard extends TbContextWidget { +class HomeDashboard extends TbContextWidget { final HomeDashboardInfo dashboard; @@ -105,7 +105,7 @@ class HomeDashboard extends TbContextWidget } -class _HomeDashboardState extends TbContextState { +class _HomeDashboardState extends TbContextState { @override Widget build(BuildContext context) { diff --git a/lib/modules/main/main_page.dart b/lib/modules/main/main_page.dart index ae15f43..3991d44 100644 --- a/lib/modules/main/main_page.dart +++ b/lib/modules/main/main_page.dart @@ -85,7 +85,7 @@ class TbMainNavigationItem { } } -class MainPage extends TbPageWidget { +class MainPage extends TbPageWidget { final String _path; @@ -97,7 +97,7 @@ class MainPage extends TbPageWidget { } -class _MainPageState extends TbPageState with TbMainState, TickerProviderStateMixin { +class _MainPageState extends TbPageState with TbMainState, TickerProviderStateMixin { late ValueNotifier _currentIndexNotifier; late final List _tabItems; diff --git a/lib/modules/more/more_page.dart b/lib/modules/more/more_page.dart index 2c021f1..324ea6d 100644 --- a/lib/modules/more/more_page.dart +++ b/lib/modules/more/more_page.dart @@ -3,7 +3,7 @@ import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; -class MorePage extends TbContextWidget { +class MorePage extends TbContextWidget { MorePage(TbContext tbContext) : super(tbContext); @@ -12,7 +12,7 @@ class MorePage extends TbContextWidget { } -class _MorePageState extends TbContextState { +class _MorePageState extends TbContextState { @override Widget build(BuildContext context) { diff --git a/lib/modules/profile/change_password_page.dart b/lib/modules/profile/change_password_page.dart index 1c7c3cf..82bf396 100644 --- a/lib/modules/profile/change_password_page.dart +++ b/lib/modules/profile/change_password_page.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'package:thingsboard_app/widgets/tb_progress_indicator.dart'; -class ChangePasswordPage extends TbContextWidget { +class ChangePasswordPage extends TbContextWidget { ChangePasswordPage(TbContext tbContext) : super(tbContext); @@ -14,7 +14,7 @@ class ChangePasswordPage extends TbContextWidget { +class _ChangePasswordPageState extends TbContextState { final _isLoadingNotifier = ValueNotifier(false); diff --git a/lib/modules/profile/profile_page.dart b/lib/modules/profile/profile_page.dart index fc7dd72..7973dde 100644 --- a/lib/modules/profile/profile_page.dart +++ b/lib/modules/profile/profile_page.dart @@ -9,7 +9,7 @@ import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/widgets/tb_progress_indicator.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; -class ProfilePage extends TbPageWidget { +class ProfilePage extends TbPageWidget { final bool _fullscreen; @@ -20,7 +20,7 @@ class ProfilePage extends TbPageWidget { } -class _ProfilePageState extends TbPageState { +class _ProfilePageState extends TbPageState { final _isLoadingNotifier = ValueNotifier(true); diff --git a/lib/modules/tenant/tenants_page.dart b/lib/modules/tenant/tenants_page.dart index 4d84341..7fd3514 100644 --- a/lib/modules/tenant/tenants_page.dart +++ b/lib/modules/tenant/tenants_page.dart @@ -6,7 +6,7 @@ import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'tenants_list.dart'; -class TenantsPage extends TbPageWidget { +class TenantsPage extends TbPageWidget { final bool searchMode; @@ -17,7 +17,7 @@ class TenantsPage extends TbPageWidget { } -class _TenantsPageState extends TbPageState { +class _TenantsPageState extends TbPageState { final PageLinkController _pageLinkController = PageLinkController(); diff --git a/lib/modules/tenant/tenants_widget.dart b/lib/modules/tenant/tenants_widget.dart index bd936bf..b50e68e 100644 --- a/lib/modules/tenant/tenants_widget.dart +++ b/lib/modules/tenant/tenants_widget.dart @@ -5,7 +5,7 @@ import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'tenants_list.dart'; -class TenantsWidget extends TbContextWidget { +class TenantsWidget extends TbContextWidget { TenantsWidget(TbContext tbContext) : super(tbContext); @@ -14,7 +14,7 @@ class TenantsWidget extends TbContextWidget } -class _TenantsWidgetState extends TbContextState { +class _TenantsWidgetState extends TbContextState { final PageLinkController _pageLinkController = PageLinkController(); diff --git a/lib/utils/services/_tb_app_storage.dart b/lib/utils/services/_tb_app_storage.dart new file mode 100644 index 0000000..199bd02 --- /dev/null +++ b/lib/utils/services/_tb_app_storage.dart @@ -0,0 +1,3 @@ +import 'package:thingsboard_client/thingsboard_client.dart'; + +TbStorage createAppStorage() => throw UnsupportedError(''); diff --git a/lib/utils/services/tb_app_storage.dart b/lib/utils/services/tb_app_storage.dart new file mode 100644 index 0000000..d079962 --- /dev/null +++ b/lib/utils/services/tb_app_storage.dart @@ -0,0 +1,3 @@ +export '_tb_app_storage.dart' + if (dart.library.io) 'tb_secure_storage.dart' + if (dart.library.html) 'tb_web_local_storage.dart'; diff --git a/lib/utils/services/tb_secure_storage.dart b/lib/utils/services/tb_secure_storage.dart index a56b1f3..9fe091d 100644 --- a/lib/utils/services/tb_secure_storage.dart +++ b/lib/utils/services/tb_secure_storage.dart @@ -1,6 +1,8 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; +TbStorage createAppStorage() => TbSecureStorage(); + class TbSecureStorage implements TbStorage { final flutterStorage = FlutterSecureStorage(); diff --git a/lib/utils/services/tb_web_local_storage.dart b/lib/utils/services/tb_web_local_storage.dart new file mode 100644 index 0000000..5358776 --- /dev/null +++ b/lib/utils/services/tb_web_local_storage.dart @@ -0,0 +1,25 @@ +import 'package:thingsboard_client/thingsboard_client.dart'; +import 'dart:html'; + +TbStorage createAppStorage() => TbWebLocalStorage(); + +class TbWebLocalStorage implements TbStorage { + + final Storage _localStorage = window.localStorage; + + @override + Future deleteItem(String key) async { + _localStorage.remove(key); + } + + @override + Future getItem(String key) async { + return _localStorage[key]; + } + + @override + Future setItem(String key, String value) async { + _localStorage[key] = value; + } + +} diff --git a/lib/utils/ui/qr_code_scanner.dart b/lib/utils/ui/qr_code_scanner.dart index 38599c4..15270fe 100644 --- a/lib/utils/ui/qr_code_scanner.dart +++ b/lib/utils/ui/qr_code_scanner.dart @@ -7,7 +7,7 @@ import 'package:qr_code_scanner/qr_code_scanner.dart'; import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; -class QrCodeScannerPage extends TbPageWidget { +class QrCodeScannerPage extends TbPageWidget { QrCodeScannerPage(TbContext tbContext) : super(tbContext); @@ -16,7 +16,7 @@ class QrCodeScannerPage extends TbPageWidget { +class _QrCodeScannerPageState extends TbPageState { Timer? simulatedQrTimer; QRViewController? controller; diff --git a/lib/widgets/tb_app_bar.dart b/lib/widgets/tb_app_bar.dart index 9e88640..bbd7ea6 100644 --- a/lib/widgets/tb_app_bar.dart +++ b/lib/widgets/tb_app_bar.dart @@ -6,7 +6,7 @@ import 'package:flutter/widgets.dart'; import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; -class TbAppBar extends TbContextWidget implements PreferredSizeWidget { +class TbAppBar extends TbContextWidget implements PreferredSizeWidget { final Widget? leading; final Widget? title; @@ -28,7 +28,7 @@ class TbAppBar extends TbContextWidget implements Pref } -class _TbAppBarState extends TbContextState { +class _TbAppBarState extends TbContextState { @override void initState() { @@ -74,7 +74,7 @@ class _TbAppBarState extends TbContextState { } } -class TbAppSearchBar extends TbContextWidget implements PreferredSizeWidget { +class TbAppSearchBar extends TbContextWidget implements PreferredSizeWidget { final double? elevation; final Color? shadowColor; @@ -94,7 +94,7 @@ class TbAppSearchBar extends TbContextWidget _TbAppSearchBarState(); } -class _TbAppSearchBarState extends TbContextState { +class _TbAppSearchBarState extends TbContextState { final TextEditingController _filter = new TextEditingController(); final _textUpdates = StreamController(); diff --git a/pubspec.lock b/pubspec.lock index ee46414..da09f3f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -488,6 +488,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + universal_platform: + dependency: "direct main" + description: + name: universal_platform + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0+1" url_launcher: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index d56a774..9eee717 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -38,6 +38,7 @@ dependencies: dart_jsonwebtoken: ^2.2.0 crypto: ^3.0.1 flutter_form_builder: ^6.0.1 + universal_platform: ^1.0.0+1 dev_dependencies: flutter_test: