(callback, message) => compute(callback, message)); + storage: storage, + onUserLoaded: onUserLoaded, + onError: onError, + onLoadStarted: onLoadStarted, + onLoadFinished: onLoadFinished, + computeFunc:(callback, message) => compute(callback, message)); - oauth2Client = TbOAuth2Client(tbContext: this, appSecretProvider: AppSecretProvider.local()); + oauth2Client = TbOAuth2Client( + tbContext: this, appSecretProvider: AppSecretProvider.local()); try { if (UniversalPlatform.isAndroid) { @@ -203,11 +199,12 @@ class TbContext { showNotification(message, NotificationType.success, duration: duration); } - void showNotification(String message, NotificationType type, {Duration? duration}) { + void showNotification(String message, NotificationType type, + {Duration? duration}) { duration ??= const Duration(days: 1); Color backgroundColor; var textColor = Color(0xFFFFFFFF); - switch(type) { + switch (type) { case NotificationType.info: backgroundColor = Color(0xFF323232); break; @@ -224,16 +221,16 @@ class TbContext { final snackBar = SnackBar( duration: duration, backgroundColor: backgroundColor, - content: Text(message, - style: TextStyle( - color: textColor - ), + content: Text( + message, + style: TextStyle(color: textColor), ), action: SnackBarAction( label: 'Close', textColor: textColor, onPressed: () { - messengerKey.currentState!.hideCurrentSnackBar(reason: SnackBarClosedReason.dismiss); + messengerKey.currentState! + .hideCurrentSnackBar(reason: SnackBarClosedReason.dismiss); }, ), ); @@ -264,7 +261,8 @@ class TbContext { if (tbClient.getAuthUser()!.userId != null) { try { userDetails = await tbClient.getUserService().getUser(); - homeDashboard = await tbClient.getDashboardService().getHomeDashboardInfo(); + homeDashboard = + await tbClient.getDashboardService().getHomeDashboardInfo(); } catch (e) { if (!_isConnectionError(e)) { tbClient.logout(); @@ -276,33 +274,44 @@ class TbContext { } else { userDetails = null; homeDashboard = null; - oauth2ClientInfos = await tbClient.getOAuth2Service().getOAuth2Clients(pkgName: packageName, platform: _oauth2PlatformType); + oauth2ClientInfos = await tbClient.getOAuth2Service().getOAuth2Clients( + pkgName: packageName, platform: _oauth2PlatformType); } _isAuthenticated.value = tbClient.isAuthenticated(); await updateRouteState(); - } catch (e, s) { log.error('Error: $e', e, s); if (_isConnectionError(e)) { - var res = await confirm(title: 'Connection error', message: 'Failed to connect to server', cancel: 'Cancel', ok: 'Retry'); + var res = await confirm( + title: 'Connection error', + message: 'Failed to connect to server', + cancel: 'Cancel', + ok: 'Retry'); if (res == true) { onUserLoaded(); } else { - navigateTo('/login', replace: true, clearStack: true, transition: TransitionType.fadeIn, transitionDuration: Duration(milliseconds: 750)); + navigateTo('/login', + replace: true, + clearStack: true, + transition: TransitionType.fadeIn, + transitionDuration: Duration(milliseconds: 750)); } } } } bool _isConnectionError(e) { - return e is ThingsboardError && e.errorCode == ThingsBoardErrorCode.general && e.message == 'Unable to connect'; + return e is ThingsboardError && + e.errorCode == ThingsBoardErrorCode.general && + e.message == 'Unable to connect'; } Listenable get isAuthenticatedListenable => _isAuthenticated; bool get isAuthenticated => _isAuthenticated.value; - bool get hasOAuthClients => oauth2ClientInfos != null && oauth2ClientInfos!.isNotEmpty; + bool get hasOAuthClients => + oauth2ClientInfos != null && oauth2ClientInfos!.isNotEmpty; FutureupdateRouteState() async { if (currentState != null) { @@ -318,14 +327,20 @@ class TbContext { transition: TransitionType.none); } else { navigateTo('/fullscreenDashboard/$defaultDashboardId', - replace: true, - transition: TransitionType.fadeIn); + replace: true, transition: TransitionType.fadeIn); } } else { - navigateTo('/home', replace: true, transition: TransitionType.fadeIn, transitionDuration: Duration(milliseconds: 750)); + navigateTo('/home', + replace: true, + transition: TransitionType.fadeIn, + transitionDuration: Duration(milliseconds: 750)); } } else { - navigateTo('/login', replace: true, clearStack: true, transition: TransitionType.fadeIn, transitionDuration: Duration(milliseconds: 750)); + navigateTo('/login', + replace: true, + clearStack: true, + transition: TransitionType.fadeIn, + transitionDuration: Duration(milliseconds: 750)); } } } @@ -338,9 +353,10 @@ class TbContext { } bool _userForceFullscreen() { - return tbClient.getAuthUser()!.isPublic || - (userDetails != null && userDetails!.additionalInfo != null && - userDetails!.additionalInfo!['defaultDashboardFullscreen'] == true); + return tbClient.getAuthUser()!.isPublic! || + (userDetails != null && + userDetails!.additionalInfo != null && + userDetails!.additionalInfo!['defaultDashboardFullscreen'] == true); } bool isPhysicalDevice() { @@ -356,11 +372,13 @@ class TbContext { String userAgent() { String userAgent = 'Mozilla/5.0'; if (UniversalPlatform.isAndroid) { - userAgent += ' (Linux; Android ${_androidInfo!.version.release}; ${_androidInfo!.model})'; + userAgent += + ' (Linux; Android ${_androidInfo!.version.release}; ${_androidInfo!.model})'; } 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'; + userAgent += + ' AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36'; return userAgent; } @@ -374,11 +392,17 @@ class TbContext { return false; } - Future navigateTo(String path, {bool replace = false, bool clearStack = false, closeDashboard = true, - TransitionType? transition, Duration? transitionDuration, bool restoreDashboard = true}) async { + Future navigateTo(String path, + {bool replace = false, + bool clearStack = false, + closeDashboard = true, + TransitionType? transition, + Duration? transitionDuration, + bool restoreDashboard = true}) async { if (currentState != null) { hideNotification(); - bool isOpenedDashboard = _mainDashboardHolder?.isDashboardOpen() == true && closeDashboard; + bool isOpenedDashboard = + _mainDashboardHolder?.isDashboardOpen() == true && closeDashboard; if (isOpenedDashboard) { _mainDashboardHolder?.openMain(); } @@ -403,12 +427,24 @@ class TbContext { } } _closeMainFirst = isOpenedDashboard; - return await router.navigateTo(currentState!.context, path, transition: transition, transitionDuration: transitionDuration, replace: replace, clearStack: clearStack); + return await router.navigateTo(currentState!.context, path, + transition: transition, + transitionDuration: transitionDuration, + replace: replace, + clearStack: clearStack); } } - Future navigateToDashboard(String dashboardId, {String? dashboardTitle, String? state, bool? hideToolbar, bool animate = true}) async { - await _mainDashboardHolder?.navigateToDashboard(dashboardId, dashboardTitle: dashboardTitle, state: state, hideToolbar: hideToolbar, animate: animate); + Future navigateToDashboard(String dashboardId, + {String? dashboardTitle, + String? state, + bool? hideToolbar, + bool animate = true}) async { + await _mainDashboardHolder?.navigateToDashboard(dashboardId, + dashboardTitle: dashboardTitle, + state: state, + hideToolbar: hideToolbar, + animate: animate); } Future showFullScreenDialog (Widget dialog) { @@ -416,8 +452,7 @@ class TbContext { builder: (BuildContext context) { return dialog; }, - fullscreenDialog: true - )); + fullscreenDialog: true)); } void pop ([T? result, BuildContext? context]) async { @@ -428,7 +463,7 @@ class TbContext { } } - Future maybePop ([ T? result ]) async { + Future maybePop ([T? result]) async { if (currentState != null) { return Navigator.of(currentState!.context).maybePop(result); } else { @@ -441,7 +476,7 @@ class TbContext { return true; } if (_mainDashboardHolder != null) { - return await _mainDashboardHolder!.dashboardGoBack(); + return await _mainDashboardHolder!.dashboardGoBack(); } return true; } @@ -456,18 +491,22 @@ class TbContext { return false; } - Future confirm({required String title, required String message, String cancel = 'Cancel', String ok = 'Ok'}) { - return showDialog (context: currentState!.context, + Future confirm( + {required String title, + required String message, + String cancel = 'Cancel', + String ok = 'Ok'}) { + return showDialog ( + context: currentState!.context, builder: (context) => AlertDialog( - title: Text(title), - content: Text(message), - actions: [ - TextButton(onPressed: () => pop(false, context), - child: Text(cancel)), - TextButton(onPressed: () => pop(true, context), - child: Text(ok)) - ], - )); + title: Text(title), + content: Text(message), + actions: [ + TextButton( + onPressed: () => pop(false, context), child: Text(cancel)), + TextButton(onPressed: () => pop(true, context), child: Text(ok)) + ], + )); } } @@ -480,11 +519,13 @@ mixin HasTbContext { void setupCurrentState(TbContextState currentState) { if (_tbContext.currentState != null) { - ModalRoute.of(_tbContext.currentState!.context)?.removeScopedWillPopCallback(_tbContext.willPop); + ModalRoute.of(_tbContext.currentState!.context) + ?.removeScopedWillPopCallback(_tbContext.willPop); } _tbContext.currentState = currentState; if (_tbContext.currentState != null) { - ModalRoute.of(_tbContext.currentState!.context)?.addScopedWillPopCallback(_tbContext.willPop); + ModalRoute.of(_tbContext.currentState!.context) + ?.addScopedWillPopCallback(_tbContext.willPop); } if (_tbContext._closeMainFirst) { _tbContext._closeMainFirst = false; @@ -514,33 +555,55 @@ mixin HasTbContext { await _tbContext.init(); } - Future navigateTo(String path, {bool replace = false, bool clearStack = false}) => _tbContext.navigateTo(path, replace: replace, clearStack: clearStack); + Future navigateTo(String path, + {bool replace = false, bool clearStack = false}) => + _tbContext.navigateTo(path, replace: replace, clearStack: clearStack); - void pop ([T? result, BuildContext? context]) => _tbContext.pop (result, context); + void pop ([T? result, BuildContext? context]) => + _tbContext.pop (result, context); - Future maybePop ([ T? result ]) => _tbContext.maybePop (result); + Future maybePop ([T? result]) => + _tbContext.maybePop (result); - Future navigateToDashboard(String dashboardId, {String? dashboardTitle, String? state, bool? hideToolbar, bool animate = true}) => - _tbContext.navigateToDashboard(dashboardId, dashboardTitle: dashboardTitle, state: state, hideToolbar: hideToolbar, animate: animate); + Future navigateToDashboard(String dashboardId, + {String? dashboardTitle, + String? state, + bool? hideToolbar, + bool animate = true}) => + _tbContext.navigateToDashboard(dashboardId, + dashboardTitle: dashboardTitle, + state: state, + hideToolbar: hideToolbar, + animate: animate); - Future confirm({required String title, required String message, String cancel = 'Cancel', String ok = 'Ok'}) => _tbContext.confirm(title: title, message: message, cancel: cancel, ok: ok); + Future confirm( + {required String title, + required String message, + String cancel = 'Cancel', + String ok = 'Ok'}) => + _tbContext.confirm( + title: title, message: message, cancel: cancel, ok: ok); void hideNotification() => _tbContext.hideNotification(); - void showErrorNotification(String message, {Duration? duration}) => _tbContext.showErrorNotification(message, duration: duration); + void showErrorNotification(String message, {Duration? duration}) => + _tbContext.showErrorNotification(message, duration: duration); - void showInfoNotification(String message, {Duration? duration}) => _tbContext.showInfoNotification(message, duration: duration); + void showInfoNotification(String message, {Duration? duration}) => + _tbContext.showInfoNotification(message, duration: duration); - void showWarnNotification(String message, {Duration? duration}) => _tbContext.showWarnNotification(message, duration: duration); + void showWarnNotification(String message, {Duration? duration}) => + _tbContext.showWarnNotification(message, duration: duration); - void showSuccessNotification(String message, {Duration? duration}) => _tbContext.showSuccessNotification(message, duration: duration); + void showSuccessNotification(String message, {Duration? duration}) => + _tbContext.showSuccessNotification(message, duration: duration); void subscribeRouteObserver(TbPageState pageState) { - _tbContext.routeObserver.subscribe(pageState, ModalRoute.of(pageState.context) as PageRoute); + _tbContext.routeObserver + .subscribe(pageState, ModalRoute.of(pageState.context) as PageRoute); } void unsubscribeRouteObserver(TbPageState pageState) { _tbContext.routeObserver.unsubscribe(pageState); } - } diff --git a/lib/core/context/tb_context_widget.dart b/lib/core/context/tb_context_widget.dart index 6294cf6..4174dab 100644 --- a/lib/core/context/tb_context_widget.dart +++ b/lib/core/context/tb_context_widget.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:thingsboard_app/core/context/tb_context.dart'; abstract class RefreshableWidget extends Widget { refresh(); } -abstract class TbContextStatelessWidget extends StatelessWidget with HasTbContext { +abstract class TbContextStatelessWidget extends StatelessWidget + with HasTbContext { TbContextStatelessWidget(TbContext tbContext, {Key? key}) : super(key: key) { setTbContext(tbContext); } @@ -18,8 +18,8 @@ abstract class TbContextWidget extends StatefulWidget with HasTbContext { } } -abstract class TbContextState extends State with HasTbContext { - +abstract class TbContextState extends State + with HasTbContext { final bool handleLoading; bool closeMainFirst = false; @@ -35,25 +35,23 @@ abstract class TbContextState extends State with H void dispose() { super.dispose(); } - } mixin TbMainState { - bool canNavigate(String path); navigateToPath(String path); bool isHomePage(); - } abstract class TbPageWidget extends TbContextWidget { TbPageWidget(TbContext tbContext, {Key? key}) : super(tbContext, key: key); } -abstract class TbPageState extends TbContextState with RouteAware { - TbPageState({bool handleUserLoaded = false}): super(handleLoading: true); +abstract class TbPageState extends TbContextState + with RouteAware { + TbPageState({bool handleUserLoaded = false}) : super(handleLoading: true); @override void didChangeDependencies() { @@ -77,25 +75,20 @@ abstract class TbPageState extends TbContextState wit hideNotification(); setupCurrentState(this); } - } class TextContextWidget extends TbContextWidget { - final String text; TextContextWidget(TbContext tbContext, this.text) : super(tbContext); @override _TextContextWidgetState createState() => _TextContextWidgetState(); - } class _TextContextWidgetState extends TbContextState { - @override Widget build(BuildContext context) { return Scaffold(body: Center(child: Text(widget.text))); } - } diff --git a/lib/core/entity/entities_base.dart b/lib/core/entity/entities_base.dart index 8c3e3ac..07b82b0 100644 --- a/lib/core/entity/entities_base.dart +++ b/lib/core/entity/entities_base.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:intl/intl.dart'; import 'package:thingsboard_app/core/context/tb_context.dart'; @@ -31,7 +30,8 @@ const Map entityTypeTranslations = { }; typedef EntityTapFunction = Function(T entity); -typedef EntityCardWidgetBuilder = Widget Function(BuildContext context, T entity); +typedef EntityCardWidgetBuilder = Widget Function( + BuildContext context, T entity); class EntityCardSettings { bool dropShadow; @@ -39,7 +39,6 @@ class EntityCardSettings { } mixin EntitiesBase on HasTbContext { - final entityDateFormat = DateFormat('yyyy-MM-dd'); String get title; @@ -73,11 +72,9 @@ mixin EntitiesBase on HasTbContext { EntityCardSettings entityGridCardSettings(T entity) => EntityCardSettings(); void onEntityTap(T entity); - } -mixin ContactBasedBase on EntitiesBase { - +mixin ContactBasedBase on EntitiesBase { @override Widget buildEntityListCard(BuildContext context, T contact) { var address = Utils.contactToShortAddress(contact); @@ -89,8 +86,7 @@ mixin ContactBasedBase on EntitiesBase { children: [ Flexible( fit: FlexFit.tight, - child: - Column( + child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( @@ -105,39 +101,36 @@ mixin ContactBasedBase on EntitiesBase { color: Color(0xFF282828), fontSize: 14, fontWeight: FontWeight.w500, - height: 20 / 14 - )) - ), - Text(entityDateFormat.format(DateTime.fromMillisecondsSinceEpoch(contact.createdTime!)), + height: 20 / 14))), + Text( + entityDateFormat.format( + DateTime.fromMillisecondsSinceEpoch( + contact.createdTime!)), style: TextStyle( color: Color(0xFFAFAFAF), fontSize: 12, fontWeight: FontWeight.normal, - height: 16 / 12 - )) - ] - ), + height: 16 / 12)) + ]), SizedBox(height: 4), - if (contact.email != null) Text(contact.email!, - style: TextStyle( - color: Color(0xFFAFAFAF), - fontSize: 12, - fontWeight: FontWeight.normal, - height: 16 / 12 - )), - if (contact.email == null) - SizedBox(height: 16), + if (contact.email != null) + Text(contact.email!, + style: TextStyle( + color: Color(0xFFAFAFAF), + fontSize: 12, + fontWeight: FontWeight.normal, + height: 16 / 12)), + if (contact.email == null) SizedBox(height: 16), if (address != null) SizedBox(height: 4), - if (address != null) Text(address, - style: TextStyle( - color: Color(0xFFAFAFAF), - fontSize: 12, - fontWeight: FontWeight.normal, - height: 16 / 12 - )), + if (address != null) + Text(address, + style: TextStyle( + color: Color(0xFFAFAFAF), + fontSize: 12, + fontWeight: FontWeight.normal, + height: 16 / 12)), ], - ) - ), + )), SizedBox(width: 16), Icon(Icons.chevron_right, color: Color(0xFFACACAC)), SizedBox(width: 8) @@ -148,24 +141,21 @@ mixin ContactBasedBase on EntitiesBase { } abstract class PageKeyController extends ValueNotifier
> { - PageKeyController(P initialPageKey) : super(PageKeyValue(initialPageKey)); P nextPageKey(P pageKey); - } class PageKeyValue { - final P pageKey; PageKeyValue(this.pageKey); - } class PageLinkController extends PageKeyController
{ - - PageLinkController({int pageSize = 20, String? searchText}) : super(PageLink(pageSize, 0, searchText, SortOrder('createdTime', Direction.DESC))); + PageLinkController({int pageSize = 20, String? searchText}) + : super(PageLink( + pageSize, 0, searchText, SortOrder('createdTime', Direction.DESC))); @override PageLink nextPageKey(PageLink pageKey) => pageKey.nextPageLink(); @@ -175,12 +165,12 @@ class PageLinkController extends PageKeyController { value.pageKey.textSearch = searchText; notifyListeners(); } - } class TimePageLinkController extends PageKeyController { - - TimePageLinkController({int pageSize = 20, String? searchText}) : super(TimePageLink(pageSize, 0, searchText, SortOrder('createdTime', Direction.DESC))); + TimePageLinkController({int pageSize = 20, String? searchText}) + : super(TimePageLink( + pageSize, 0, searchText, SortOrder('createdTime', Direction.DESC))); @override TimePageLink nextPageKey(TimePageLink pageKey) => pageKey.nextPageLink(); @@ -190,29 +180,27 @@ class TimePageLinkController extends PageKeyController { value.pageKey.textSearch = searchText; notifyListeners(); } - } -abstract class BaseEntitiesWidget extends TbContextWidget with EntitiesBase { - +abstract class BaseEntitiesWidget extends TbContextWidget + with EntitiesBase { final bool searchMode; final PageKeyController pageKeyController; - BaseEntitiesWidget(TbContext tbContext, this.pageKeyController, {this.searchMode = false}): - super(tbContext); + BaseEntitiesWidget(TbContext tbContext, this.pageKeyController, + {this.searchMode = false}) + : super(tbContext); @override - Widget? buildHeading(BuildContext context) => searchMode ? Text('Search results', style: TextStyle( - color: Color(0xFFAFAFAF), - fontSize: 16, - height: 24 / 16 - )) : null; - - + Widget? buildHeading(BuildContext context) => searchMode + ? Text('Search results', + style: TextStyle( + color: Color(0xFFAFAFAF), fontSize: 16, height: 24 / 16)) + : null; } -abstract class BaseEntitiesState
extends TbContextState > { - +abstract class BaseEntitiesState + extends TbContextState > { late final PagingController pagingController; Completer
? _refreshCompleter; bool _dataLoading = false; @@ -224,7 +212,8 @@ abstract class BaseEntitiesState extends TbContextState extends TbContextState Future.wait([ - widget.onRefresh(), - _refresh() - ]), - child: pagedViewBuilder(context) - ); + onRefresh: () => Future.wait([widget.onRefresh(), _refresh()]), + child: pagedViewBuilder(context)); } - + Widget pagedViewBuilder(BuildContext context); Widget firstPageProgressIndicatorBuilder(BuildContext context) { - return Stack( children: [ + return Stack(children: [ Positioned( top: 20, left: 0, @@ -338,7 +323,7 @@ abstract class BaseEntitiesState extends TbContextState extends TbContextState extends TbContextState pagingController.refresh(), ); } - } class FirstPageExceptionIndicator extends StatelessWidget { diff --git a/lib/core/entity/entities_grid.dart b/lib/core/entity/entities_grid.dart index bcfae9e..f60ed9c 100644 --- a/lib/core/entity/entities_grid.dart +++ b/lib/core/entity/entities_grid.dart @@ -6,14 +6,11 @@ import 'entities_base.dart'; import 'entity_grid_card.dart'; mixin EntitiesGridStateBase on StatefulWidget { - @override _EntitiesGridState createState() => _EntitiesGridState(); - } class _EntitiesGridState extends BaseEntitiesState { - _EntitiesGridState() : super(); @override @@ -24,9 +21,7 @@ class _EntitiesGridState extends BaseEntitiesState { if (heading != null) { slivers.add(SliverPadding( padding: EdgeInsets.fromLTRB(16, 16, 16, 0), - sliver: SliverToBoxAdapter( - child: heading - ))); + sliver: SliverToBoxAdapter(child: heading))); } slivers.add(SliverPadding( padding: EdgeInsets.all(16), @@ -44,19 +39,17 @@ class _EntitiesGridState extends BaseEntitiesState { ), builderDelegate: PagedChildBuilderDelegate ( itemBuilder: (context, item, index) => EntityGridCard ( - item, - key: widget.getKey(item), - entityCardWidgetBuilder: widget.buildEntityGridCard, - onEntityTap: widget.onEntityTap, - settings: widget.entityGridCardSettings(item), - ), - firstPageProgressIndicatorBuilder: firstPageProgressIndicatorBuilder, - newPageProgressIndicatorBuilder: newPageProgressIndicatorBuilder, - noItemsFoundIndicatorBuilder: noItemsFoundIndicatorBuilder - ) - ))); - return CustomScrollView( - slivers: slivers - ); + item, + key: widget.getKey(item), + entityCardWidgetBuilder: widget.buildEntityGridCard, + onEntityTap: widget.onEntityTap, + settings: widget.entityGridCardSettings(item), + ), + firstPageProgressIndicatorBuilder: + firstPageProgressIndicatorBuilder, + newPageProgressIndicatorBuilder: + newPageProgressIndicatorBuilder, + noItemsFoundIndicatorBuilder: noItemsFoundIndicatorBuilder)))); + return CustomScrollView(slivers: slivers); } } diff --git a/lib/core/entity/entities_list.dart b/lib/core/entity/entities_list.dart index 898f124..0590716 100644 --- a/lib/core/entity/entities_list.dart +++ b/lib/core/entity/entities_list.dart @@ -6,14 +6,11 @@ import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'entity_list_card.dart'; mixin EntitiesListStateBase on StatefulWidget { - @override _EntitiesListState createState() => _EntitiesListState(); - } -class _EntitiesListState extends BaseEntitiesState { - +class _EntitiesListState extends BaseEntitiesState { _EntitiesListState() : super(); @override @@ -23,9 +20,7 @@ class _EntitiesListState extends BaseEntitiesState { if (heading != null) { slivers.add(SliverPadding( padding: EdgeInsets.fromLTRB(16, 16, 16, 0), - sliver: SliverToBoxAdapter( - child: heading - ))); + sliver: SliverToBoxAdapter(child: heading))); } slivers.add(SliverPadding( padding: EdgeInsets.all(16), @@ -34,19 +29,16 @@ class _EntitiesListState extends BaseEntitiesState { separatorBuilder: (context, index) => SizedBox(height: 8), builderDelegate: PagedChildBuilderDelegate ( itemBuilder: (context, item, index) => EntityListCard ( - item, - key: widget.getKey(item), - entityCardWidgetBuilder: widget.buildEntityListCard, - onEntityTap: widget.onEntityTap, - settings: widget.entityListCardSettings(item), - ), - firstPageProgressIndicatorBuilder: firstPageProgressIndicatorBuilder, - newPageProgressIndicatorBuilder: newPageProgressIndicatorBuilder, - noItemsFoundIndicatorBuilder: noItemsFoundIndicatorBuilder - ) - ))); - return CustomScrollView( - slivers: slivers - ); + item, + key: widget.getKey(item), + entityCardWidgetBuilder: widget.buildEntityListCard, + onEntityTap: widget.onEntityTap, + ), + firstPageProgressIndicatorBuilder: + firstPageProgressIndicatorBuilder, + newPageProgressIndicatorBuilder: + newPageProgressIndicatorBuilder, + noItemsFoundIndicatorBuilder: noItemsFoundIndicatorBuilder)))); + return CustomScrollView(slivers: slivers); } } diff --git a/lib/core/entity/entities_list_widget.dart b/lib/core/entity/entities_list_widget.dart index 2972269..2bf94bf 100644 --- a/lib/core/entity/entities_list_widget.dart +++ b/lib/core/entity/entities_list_widget.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:fading_edge_scrollview/fading_edge_scrollview.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; import 'package:thingsboard_app/core/entity/entities_base.dart'; @@ -11,14 +10,15 @@ import 'package:thingsboard_client/thingsboard_client.dart'; import 'entity_list_card.dart'; class EntitiesListWidgetController { - final List<_EntitiesListWidgetState> states = []; - void _registerEntitiesWidgetState(_EntitiesListWidgetState entitiesListWidgetState) { + void _registerEntitiesWidgetState( + _EntitiesListWidgetState entitiesListWidgetState) { states.add(entitiesListWidgetState); } - void _unregisterEntitiesWidgetState(_EntitiesListWidgetState entitiesListWidgetState) { + void _unregisterEntitiesWidgetState( + _EntitiesListWidgetState entitiesListWidgetState) { states.remove(entitiesListWidgetState); } @@ -29,45 +29,48 @@ class EntitiesListWidgetController { void dispose() { states.clear(); } - } -abstract class EntitiesListPageLinkWidget extends EntitiesListWidget { - - EntitiesListPageLinkWidget(TbContext tbContext, {EntitiesListWidgetController? controller}) : super(tbContext, controller: controller); +abstract class EntitiesListPageLinkWidget + extends EntitiesListWidget { + EntitiesListPageLinkWidget(TbContext tbContext, + {EntitiesListWidgetController? controller}) + : super(tbContext, controller: controller); @override - PageKeyController createPageKeyController() => PageLinkController(pageSize: 5); - + PageKeyController createPageKeyController() => + PageLinkController(pageSize: 5); } -abstract class EntitiesListWidget extends TbContextWidget with EntitiesBase { - +abstract class EntitiesListWidget extends TbContextWidget + with EntitiesBase { final EntitiesListWidgetController? _controller; - EntitiesListWidget(TbContext tbContext, {EntitiesListWidgetController? controller}): - _controller = controller, - super(tbContext); + EntitiesListWidget(TbContext tbContext, + {EntitiesListWidgetController? controller}) + : _controller = controller, + super(tbContext); @override - _EntitiesListWidgetState createState() => _EntitiesListWidgetState(_controller); + _EntitiesListWidgetState createState() => + _EntitiesListWidgetState(_controller); PageKeyController createPageKeyController(); void onViewAll(); - } -class _EntitiesListWidgetState
extends TbContextState > { - +class _EntitiesListWidgetState + extends TbContextState > { final EntitiesListWidgetController? _controller; late final PageKeyController _pageKeyController; - final StreamController
?> _entitiesStreamController = StreamController.broadcast(); + final StreamController ?> _entitiesStreamController = + StreamController.broadcast(); - _EntitiesListWidgetState(EntitiesListWidgetController? controller): - _controller = controller; + _EntitiesListWidgetState(EntitiesListWidgetController? controller) + : _controller = controller; @override void initState() { @@ -76,7 +79,7 @@ class _EntitiesListWidgetState extends TbContextState extends TbContextState extends TbContextState ?>( - stream: _entitiesStreamController.stream, - builder: (context, snapshot) { - if (snapshot.hasData) { - var data = snapshot.data!; - if (data.data.isEmpty) { - return _buildNoEntitiesFound(); //return Text('Loaded'); + stream: _entitiesStreamController.stream, + builder: (context, snapshot) { + if (snapshot.hasData) { + var data = snapshot.data!; + if (data.data.isEmpty) { + return _buildNoEntitiesFound(); //return Text('Loaded'); + } else { + return _buildEntitiesView(context, data.data); + } } else { - return _buildEntitiesView(context, data.data); + return Center( + child: RefreshProgressIndicator( + valueColor: AlwaysStoppedAnimation( + Theme.of(tbContext.currentState!.context) + .colorScheme + .primary), + )); } - } else { - return Center( - child: RefreshProgressIndicator( - valueColor: AlwaysStoppedAnimation(Theme.of(tbContext.currentState!.context).colorScheme.primary), - ) - ); - } - } - ), + }), ) ], - ) - ) - ), + ))), decoration: BoxDecoration( boxShadow: [ BoxShadow( color: Colors.black.withAlpha(25), blurRadius: 10.0, - offset: Offset(0, 4) - ), + offset: Offset(0, 4)), BoxShadow( color: Colors.black.withAlpha(18), blurRadius: 30.0, - offset: Offset(0, 10) - ), + offset: Offset(0, 10)), ], - ) - ); + )); } Widget _buildNoEntitiesFound() { return Container( - decoration: BoxDecoration( + decoration: BoxDecoration( border: Border.all( - color: Color(0xFFDEDEDE), - style: BorderStyle.solid, - width: 1 - ), - borderRadius: BorderRadius.circular(4) - ), - child: Center( - child: - Text(widget.noItemsFoundText, + color: Color(0xFFDEDEDE), style: BorderStyle.solid, width: 1), + borderRadius: BorderRadius.circular(4)), + child: Center( + child: Text(widget.noItemsFoundText, style: TextStyle( color: Color(0xFFAFAFAF), fontSize: 14, - ) - ), - ), + )), + ), ); } @@ -219,13 +209,11 @@ class _EntitiesListWidgetState extends TbContextState EntityListCard ( - entity, - entityCardWidgetBuilder: widget.buildEntityListWidgetCard, - onEntityTap: widget.onEntityTap, - settings: widget.entityListCardSettings(entity), - listWidgetCard: true - )).toList() - )); + children: entities + .map((entity) => EntityListCard (entity, + entityCardWidgetBuilder: widget.buildEntityListWidgetCard, + onEntityTap: widget.onEntityTap, + listWidgetCard: true)) + .toList())); } } diff --git a/lib/core/entity/entity_details_page.dart b/lib/core/entity/entity_details_page.dart index fb47b91..b4c96ad 100644 --- a/lib/core/entity/entity_details_page.dart +++ b/lib/core/entity/entity_details_page.dart @@ -1,6 +1,4 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; 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_app_bar.dart'; @@ -8,18 +6,11 @@ import 'package:thingsboard_app/widgets/tb_progress_indicator.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; abstract class EntityDetailsPage extends TbPageWidget { + final labelTextStyle = + TextStyle(color: Color(0xFF757575), fontSize: 14, height: 20 / 14); - final labelTextStyle = TextStyle( - color: Color(0xFF757575), - fontSize: 14, - height: 20 / 14 - ); - - final valueTextStyle = TextStyle( - color: Color(0xFF282828), - fontSize: 14, - height: 20 / 14 - ); + final valueTextStyle = + TextStyle(color: Color(0xFF282828), fontSize: 14, height: 20 / 14); final String _defaultTitle; final String _entityId; @@ -29,19 +20,19 @@ abstract class EntityDetailsPage extends TbPageWidget { final double? _appBarElevation; EntityDetailsPage(TbContext tbContext, - {required String defaultTitle, - required String entityId, - String? subTitle, - bool showLoadingIndicator = true, - bool hideAppBar = false, - double? appBarElevation}): - this._defaultTitle = defaultTitle, - this._entityId = entityId, - this._subTitle = subTitle, - this._showLoadingIndicator = showLoadingIndicator, - this._hideAppBar = hideAppBar, - this._appBarElevation = appBarElevation, - super(tbContext); + {required String defaultTitle, + required String entityId, + String? subTitle, + bool showLoadingIndicator = true, + bool hideAppBar = false, + double? appBarElevation}) + : this._defaultTitle = defaultTitle, + this._entityId = entityId, + this._subTitle = subTitle, + this._showLoadingIndicator = showLoadingIndicator, + this._hideAppBar = hideAppBar, + this._appBarElevation = appBarElevation, + super(tbContext); @override _EntityDetailsPageState createState() => _EntityDetailsPageState(); @@ -53,11 +44,10 @@ abstract class EntityDetailsPage extends TbPageWidget { } Widget buildEntityDetails(BuildContext context, T entity); - } -class _EntityDetailsPageState extends TbPageState > { - +class _EntityDetailsPageState + extends TbPageState > { late Future entityFuture; late ValueNotifier titleValue; @@ -70,7 +60,7 @@ class _EntityDetailsPageState extends TbPageState extends TbPageState ( - valueListenable: titleValue, - builder: (context, title, _widget) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - FittedBox( - fit: BoxFit.fitWidth, - alignment: Alignment.centerLeft, - child: Text(title, - style: widget._subTitle != null ? Theme.of(context).primaryTextTheme.headline6!.copyWith( - fontSize: 16 - ) : null - ) - ), - if (widget._subTitle != null) Text(widget._subTitle!, style: TextStyle( - color: Theme.of(context).primaryTextTheme.headline6!.color!.withAlpha((0.38 * 255).ceil()), - fontSize: 12, - fontWeight: FontWeight.normal, - height: 16 / 12 - )) - ] - ); - }, - ), - ), + appBar: widget._hideAppBar + ? null + : TbAppBar( + tbContext, + showLoadingIndicator: widget._showLoadingIndicator, + elevation: widget._appBarElevation, + title: ValueListenableBuilder ( + valueListenable: titleValue, + builder: (context, title, _widget) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + FittedBox( + fit: BoxFit.fitWidth, + alignment: Alignment.centerLeft, + child: Text(title, + style: widget._subTitle != null + ? Theme.of(context) + .primaryTextTheme + .headline6! + .copyWith(fontSize: 16) + : null)), + if (widget._subTitle != null) + Text(widget._subTitle!, + style: TextStyle( + color: Theme.of(context) + .primaryTextTheme + .headline6! + .color! + .withAlpha((0.38 * 255).ceil()), + fontSize: 12, + fontWeight: FontWeight.normal, + height: 16 / 12)) + ]); + }, + ), + ), body: FutureBuilder ( future: entityFuture, builder: (context, snapshot) { @@ -123,7 +120,8 @@ class _EntityDetailsPageState extends TbPageState extends TbPageState extends EntityDetailsPage { - +abstract class ContactBasedDetailsPage + extends EntityDetailsPage { ContactBasedDetailsPage(TbContext tbContext, - { required String defaultTitle, - required String entityId, - String? subTitle, - bool showLoadingIndicator = true, - bool hideAppBar = false, - double? appBarElevation}): - super(tbContext, defaultTitle: defaultTitle, entityId: entityId, - subTitle: subTitle, showLoadingIndicator: showLoadingIndicator, - hideAppBar: hideAppBar, appBarElevation: appBarElevation); + {required String defaultTitle, + required String entityId, + String? subTitle, + bool showLoadingIndicator = true, + bool hideAppBar = false, + double? appBarElevation}) + : super(tbContext, + defaultTitle: defaultTitle, + entityId: entityId, + subTitle: subTitle, + showLoadingIndicator: showLoadingIndicator, + hideAppBar: hideAppBar, + appBarElevation: appBarElevation); @override Widget buildEntityDetails(BuildContext context, T contact) { @@ -201,9 +202,6 @@ abstract class ContactBasedDetailsPage extends EntityDet SizedBox(height: 16), Text('Email', style: labelTextStyle), Text(contact.email ?? '', style: valueTextStyle), - ] - ) - ); + ])); } } - diff --git a/lib/core/entity/entity_grid_card.dart b/lib/core/entity/entity_grid_card.dart index 1435987..e3a6273 100644 --- a/lib/core/entity/entity_grid_card.dart +++ b/lib/core/entity/entity_grid_card.dart @@ -1,7 +1,4 @@ - import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; -import 'package:thingsboard_client/thingsboard_client.dart'; import 'entities_base.dart'; @@ -11,10 +8,12 @@ class EntityGridCard extends StatelessWidget { final EntityCardWidgetBuilder _entityCardWidgetBuilder; final EntityCardSettings _settings; - EntityGridCard(T entity, {Key? key, EntityTapFunction ? onEntityTap, - required EntityCardWidgetBuilder entityCardWidgetBuilder, - required EntityCardSettings settings}): - this._entity = entity, + EntityGridCard(T entity, + {Key? key, + EntityTapFunction ? onEntityTap, + required EntityCardWidgetBuilder entityCardWidgetBuilder, + required EntityCardSettings settings}) + : this._entity = entity, this._onEntityTap = onEntityTap, this._entityCardWidgetBuilder = entityCardWidgetBuilder, this._settings = settings, @@ -22,35 +21,31 @@ class EntityGridCard extends StatelessWidget { @override Widget build(BuildContext context) { - return - GestureDetector( - behavior: HitTestBehavior.opaque, - child: - Container( - child: Card( - margin: EdgeInsets.zero, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(4), - ), - elevation: 0, - child: _entityCardWidgetBuilder(context, _entity) - ), - decoration: _settings.dropShadow ? BoxDecoration( - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha((255 * 0.05).ceil()), - blurRadius: 6.0, - offset: Offset(0, 4) + return GestureDetector( + behavior: HitTestBehavior.opaque, + child: Container( + child: Card( + margin: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(4), + ), + elevation: 0, + child: _entityCardWidgetBuilder(context, _entity)), + decoration: _settings.dropShadow + ? BoxDecoration( + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha((255 * 0.05).ceil()), + blurRadius: 6.0, + offset: Offset(0, 4)) + ], ) - ], - ) : null, - ), - onTap: () { - if (_onEntityTap != null) { - _onEntityTap!(_entity); - } + : null, + ), + onTap: () { + if (_onEntityTap != null) { + _onEntityTap!(_entity); } - ); + }); } } - diff --git a/lib/core/entity/entity_list_card.dart b/lib/core/entity/entity_list_card.dart index bfda649..59415bf 100644 --- a/lib/core/entity/entity_list_card.dart +++ b/lib/core/entity/entity_list_card.dart @@ -1,6 +1,4 @@ - import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'entities_base.dart'; @@ -9,58 +7,51 @@ class EntityListCard extends StatelessWidget { final T _entity; final EntityTapFunction ? _onEntityTap; final EntityCardWidgetBuilder _entityCardWidgetBuilder; - final EntityCardSettings _settings; - EntityListCard(T entity, {Key? key, EntityTapFunction ? onEntityTap, - required EntityCardWidgetBuilder entityCardWidgetBuilder, - required EntityCardSettings settings, - bool listWidgetCard = false}): - this._entity = entity, + EntityListCard(T entity, + {Key? key, + EntityTapFunction ? onEntityTap, + required EntityCardWidgetBuilder entityCardWidgetBuilder, + bool listWidgetCard = false}) + : this._entity = entity, this._onEntityTap = onEntityTap, this._entityCardWidgetBuilder = entityCardWidgetBuilder, - this._settings = settings, this._listWidgetCard = listWidgetCard, super(key: key); @override Widget build(BuildContext context) { - return - GestureDetector( - behavior: HitTestBehavior.opaque, - child: - Container( - margin: _listWidgetCard ? EdgeInsets.only(right: 8) : EdgeInsets.zero, - child: Card( - margin: EdgeInsets.zero, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(4), + return GestureDetector( + behavior: HitTestBehavior.opaque, + child: Container( + margin: _listWidgetCard ? EdgeInsets.only(right: 8) : EdgeInsets.zero, + child: Card( + margin: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(4), + ), + elevation: 0, + child: _entityCardWidgetBuilder(context, _entity)), + decoration: _listWidgetCard + ? BoxDecoration( + border: Border.all( + color: Color(0xFFDEDEDE), + style: BorderStyle.solid, + width: 1), + borderRadius: BorderRadius.circular(4)) + : BoxDecoration( + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha((255 * 0.05).ceil()), + blurRadius: 6.0, + offset: Offset(0, 4)), + ], ), - elevation: 0, - child: _entityCardWidgetBuilder(context, _entity) - ), - decoration: _listWidgetCard ? BoxDecoration( - border: Border.all( - color: Color(0xFFDEDEDE), - style: BorderStyle.solid, - width: 1 - ), - borderRadius: BorderRadius.circular(4) - ) : BoxDecoration( - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha((255 * 0.05).ceil()), - blurRadius: 6.0, - offset: Offset(0, 4) - ), - ], - ), - ), - onTap: () { - if (_onEntityTap != null) { - _onEntityTap!(_entity); - } + ), + onTap: () { + if (_onEntityTap != null) { + _onEntityTap!(_entity); } - ); + }); } } - diff --git a/lib/core/init/init_app.dart b/lib/core/init/init_app.dart index a545d29..890f19d 100644 --- a/lib/core/init/init_app.dart +++ b/lib/core/init/init_app.dart @@ -1,20 +1,17 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; 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 { - - ThingsboardInitApp(TbContext tbContext, {Key? key}) : super(tbContext, key: key); + ThingsboardInitApp(TbContext tbContext, {Key? key}) + : super(tbContext, key: key); @override _ThingsboardInitAppState createState() => _ThingsboardInitAppState(); - } class _ThingsboardInitAppState extends TbPageState { - @override void initState() { super.initState(); @@ -26,10 +23,7 @@ class _ThingsboardInitAppState extends TbPageState { return Container( alignment: Alignment.center, color: Colors.white, - child: TbProgressIndicator( - size: 50.0 - ), + child: TbProgressIndicator(size: 50.0), ); } - } diff --git a/lib/core/init/init_routes.dart b/lib/core/init/init_routes.dart index 7c0a474..698e53c 100644 --- a/lib/core/init/init_routes.dart +++ b/lib/core/init/init_routes.dart @@ -7,8 +7,8 @@ import 'package:thingsboard_app/core/context/tb_context.dart'; import 'init_app.dart'; class InitRoutes extends TbRoutes { - - late var initHandler = Handler(handlerFunc: (BuildContext? context, Map params) { + late var initHandler = Handler( + handlerFunc: (BuildContext? context, Map params) { return ThingsboardInitApp(tbContext); }); @@ -18,5 +18,4 @@ class InitRoutes extends TbRoutes { void doRegisterRoutes(router) { router.define("/", handler: initHandler); } - } diff --git a/lib/main.dart b/lib/main.dart index 3cce13c..f5710e3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,5 @@ import 'package:universal_platform/universal_platform.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; @@ -14,7 +13,6 @@ import 'config/themes/tb_theme.dart'; final appRouter = ThingsboardAppRouter(); void main() async { - WidgetsFlutterBinding.ensureInitialized(); // await FlutterDownloader.initialize(); // await Permission.storage.request(); @@ -27,18 +25,18 @@ void main() async { } class ThingsboardApp extends StatefulWidget { - ThingsboardApp({Key? key}) : super(key: key); @override ThingsboardAppState createState() => ThingsboardAppState(); - } -class ThingsboardAppState extends State with TickerProviderStateMixin implements TbMainDashboardHolder { - +class ThingsboardAppState extends State + with TickerProviderStateMixin + implements TbMainDashboardHolder { final TwoPageViewController _mainPageViewController = TwoPageViewController(); - final MainDashboardPageController _mainDashboardPageController = MainDashboardPageController(); + final MainDashboardPageController _mainDashboardPageController = + MainDashboardPageController(); final GlobalKey mainAppKey = GlobalKey(); final GlobalKey dashboardKey = GlobalKey(); @@ -50,8 +48,13 @@ class ThingsboardAppState extends State with TickerProviderState } @override - Future navigateToDashboard(String dashboardId, {String? dashboardTitle, String? state, bool? hideToolbar, bool animate = true}) async { - await _mainDashboardPageController.openDashboard(dashboardId, dashboardTitle: dashboardTitle, state: state, hideToolbar: hideToolbar); + Future navigateToDashboard(String dashboardId, + {String? dashboardTitle, + String? state, + bool? hideToolbar, + bool animate = true}) async { + await _mainDashboardPageController.openDashboard(dashboardId, + dashboardTitle: dashboardTitle, state: state, hideToolbar: hideToolbar); _openDashboard(animate: animate); } @@ -121,40 +124,36 @@ class ThingsboardAppState extends State with TickerProviderState return res; } - @override Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( systemNavigationBarColor: Colors.white, statusBarColor: Colors.white, - systemNavigationBarIconBrightness: Brightness.light - )); + systemNavigationBarIconBrightness: Brightness.light)); return MaterialApp( - title: 'ThingsBoard', + title: 'ThingsBoard', themeMode: ThemeMode.light, home: TwoPageView( - controller: _mainPageViewController, - first: MaterialApp( - key: mainAppKey, - scaffoldMessengerKey: appRouter.tbContext.messengerKey, - title: 'ThingsBoard', - theme: tbTheme, - themeMode: ThemeMode.light, - darkTheme: tbDarkTheme, - onGenerateRoute: appRouter.router.generator, - navigatorObservers: [appRouter.tbContext.routeObserver], - ), - second: MaterialApp( - key: dashboardKey, - // scaffoldMessengerKey: appRouter.tbContext.messengerKey, - title: 'ThingsBoard', - theme: tbTheme, - themeMode: ThemeMode.light, - darkTheme: tbDarkTheme, - home: MainDashboardPage(appRouter.tbContext, controller: _mainDashboardPageController), - ) - ) - ); + controller: _mainPageViewController, + first: MaterialApp( + key: mainAppKey, + scaffoldMessengerKey: appRouter.tbContext.messengerKey, + title: 'ThingsBoard', + theme: tbTheme, + themeMode: ThemeMode.light, + darkTheme: tbDarkTheme, + onGenerateRoute: appRouter.router.generator, + navigatorObservers: [appRouter.tbContext.routeObserver], + ), + second: MaterialApp( + key: dashboardKey, + // scaffoldMessengerKey: appRouter.tbContext.messengerKey, + title: 'ThingsBoard', + theme: tbTheme, + themeMode: ThemeMode.light, + darkTheme: tbDarkTheme, + home: MainDashboardPage(appRouter.tbContext, + controller: _mainDashboardPageController), + ))); } - } diff --git a/lib/modules/alarm/alarm_routes.dart b/lib/modules/alarm/alarm_routes.dart index 36b479d..f2851b2 100644 --- a/lib/modules/alarm/alarm_routes.dart +++ b/lib/modules/alarm/alarm_routes.dart @@ -6,8 +6,8 @@ import 'package:thingsboard_app/modules/alarm/alarms_page.dart'; import 'package:thingsboard_app/modules/main/main_page.dart'; class AlarmRoutes extends TbRoutes { - - late var alarmsHandler = Handler(handlerFunc: (BuildContext? context, Map params) { + late var alarmsHandler = Handler( + handlerFunc: (BuildContext? context, Map params) { var searchMode = params['search']?.first == 'true'; if (searchMode) { return AlarmsPage(tbContext, searchMode: true); @@ -22,5 +22,4 @@ class AlarmRoutes extends TbRoutes { void doRegisterRoutes(router) { router.define("/alarms", handler: alarmsHandler); } - } diff --git a/lib/modules/alarm/alarms_base.dart b/lib/modules/alarm/alarms_base.dart index 5471cad..3192696 100644 --- a/lib/modules/alarm/alarms_base.dart +++ b/lib/modules/alarm/alarms_base.dart @@ -1,6 +1,5 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/context/tb_context_widget.dart'; @@ -8,7 +7,6 @@ import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'package:thingsboard_app/utils/utils.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; - const Map alarmSeverityColors = { AlarmSeverity.CRITICAL: Color(0xFFFF0000), AlarmSeverity.MAJOR: Color(0xFFFFA500), @@ -33,7 +31,6 @@ const Map alarmStatusTranslations = { }; mixin AlarmsBase on EntitiesBase { - @override String get title => 'Alarms'; @@ -49,11 +46,14 @@ mixin AlarmsBase on EntitiesBase { void onEntityTap(AlarmInfo alarm) { String? dashboardId = alarm.details?['dashboardId']; if (dashboardId != null) { - var state = Utils.createDashboardEntityState(alarm.originator, entityName: alarm.originatorName); - navigateToDashboard(dashboardId, dashboardTitle: alarm.originatorName, state: state); + var state = Utils.createDashboardEntityState(alarm.originator, + entityName: alarm.originatorName); + navigateToDashboard(dashboardId, + dashboardTitle: alarm.originatorName, state: state); } else { if (tbClient.isTenantAdmin()) { - showWarnNotification('Mobile dashboard should be configured in device profile alarm rules!'); + showWarnNotification( + 'Mobile dashboard should be configured in device profile alarm rules!'); } } } @@ -69,8 +69,11 @@ mixin AlarmsBase on EntitiesBase { } class AlarmQueryController extends PageKeyController { - - AlarmQueryController({int pageSize = 20, String? searchText}) : super(AlarmQuery(TimePageLink(pageSize, 0, searchText, SortOrder('createdTime', Direction.DESC)), fetchOriginator: true)); + AlarmQueryController({int pageSize = 20, String? searchText}) + : super(AlarmQuery( + TimePageLink(pageSize, 0, searchText, + SortOrder('createdTime', Direction.DESC)), + fetchOriginator: true)); @override AlarmQuery nextPageKey(AlarmQuery pageKey) { @@ -83,28 +86,24 @@ class AlarmQueryController extends PageKeyController { query.pageLink.textSearch = searchText; notifyListeners(); } - } class AlarmCard extends TbContextWidget { - final AlarmInfo alarm; AlarmCard(TbContext tbContext, {required this.alarm}) : super(tbContext); @override _AlarmCardState createState() => _AlarmCardState(alarm); - } class _AlarmCardState extends TbContextState { - bool loading = false; AlarmInfo alarm; final entityDateFormat = DateFormat('yyyy-MM-dd'); - _AlarmCardState(this.alarm): super(); + _AlarmCardState(this.alarm) : super(); @override void initState() { @@ -121,161 +120,176 @@ class _AlarmCardState extends TbContextState { @override Widget build(BuildContext context) { if (this.loading) { - return Container( height: 134, alignment: Alignment.center, child: RefreshProgressIndicator()); + return Container( + height: 134, + alignment: Alignment.center, + child: RefreshProgressIndicator()); } else { bool hasDashboard = alarm.details?['dashboardId'] != null; return Stack( children: [ Positioned.fill( - child: Container( - alignment: Alignment.centerLeft, - child: Container( - width: 4, - decoration: BoxDecoration( - color: alarmSeverityColors[alarm.severity]!, - borderRadius: BorderRadius.only(topLeft: Radius.circular(4), bottomLeft: Radius.circular(4)) - ), - ) - ) - ), - Row( - mainAxisSize: MainAxisSize.max, - children: [ - SizedBox(width: 4), - Flexible( - fit: FlexFit.tight, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox(width: 16), - Flexible( - fit: FlexFit.tight, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox(height: 12), - Row( - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Flexible( - fit: FlexFit.tight, - child: AutoSizeText(alarm.type, - maxLines: 2, - minFontSize: 8, - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Color(0xFF282828), - fontWeight: FontWeight.w500, - fontSize: 14, - height: 20 / 14) - ) - ), - Text(entityDateFormat.format(DateTime.fromMillisecondsSinceEpoch(alarm.createdTime!)), + child: Container( + alignment: Alignment.centerLeft, + child: Container( + width: 4, + decoration: BoxDecoration( + color: alarmSeverityColors[alarm.severity]!, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(4), + bottomLeft: Radius.circular(4))), + ))), + Row(mainAxisSize: MainAxisSize.max, children: [ + SizedBox(width: 4), + Flexible( + fit: FlexFit.tight, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox(width: 16), + Flexible( + fit: FlexFit.tight, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox(height: 12), + Row( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Flexible( + fit: FlexFit.tight, + child: AutoSizeText(alarm.type, + maxLines: 2, + minFontSize: 8, + overflow: + TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFF282828), + fontWeight: + FontWeight.w500, + fontSize: 14, + height: 20 / 14))), + Text( + entityDateFormat.format(DateTime + .fromMillisecondsSinceEpoch( + alarm.createdTime!)), + style: TextStyle( + color: Color(0xFFAFAFAF), + fontWeight: FontWeight.normal, + fontSize: 12, + height: 16 / 12)) + ]), + SizedBox(height: 4), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Flexible( + fit: FlexFit.tight, + child: Text( + alarm.originatorName != null + ? alarm.originatorName! + : '', style: TextStyle( color: Color(0xFFAFAFAF), - fontWeight: FontWeight.normal, + fontWeight: + FontWeight.normal, fontSize: 12, - height: 16 / 12) - ) - ] - ), - SizedBox(height: 4), - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Flexible( - fit: FlexFit.tight, - child: Text(alarm.originatorName != null ? alarm.originatorName! : '', - style: TextStyle( - color: Color(0xFFAFAFAF), - fontWeight: FontWeight.normal, - fontSize: 12, - height: 16 / 12) - ) - ), - Text(alarmSeverityTranslations[alarm.severity]!, - style: TextStyle( - color: alarmSeverityColors[alarm.severity]!, - fontWeight: FontWeight.w500, - fontSize: 12, - height: 16 / 12) - ) - ] - ), - SizedBox(height: 12)], - ) - ), - SizedBox(width: 16), - if (hasDashboard) Icon(Icons.chevron_right, color: Color(0xFFACACAC)), - if (hasDashboard) SizedBox(width: 16), - ] - ), - Divider(height: 1), - SizedBox(height: 8), + height: 16 / 12))), + Text( + alarmSeverityTranslations[ + alarm.severity]!, + style: TextStyle( + color: alarmSeverityColors[ + alarm.severity]!, + fontWeight: FontWeight.w500, + fontSize: 12, + height: 16 / 12)) + ]), + SizedBox(height: 12) + ], + )), + SizedBox(width: 16), + if (hasDashboard) + Icon(Icons.chevron_right, + color: Color(0xFFACACAC)), + if (hasDashboard) SizedBox(width: 16), + ]), + Divider(height: 1), + SizedBox(height: 8), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox(width: 16), + Flexible( + fit: FlexFit.tight, + child: Text( + alarmStatusTranslations[alarm.status]!, + style: TextStyle( + color: Color(0xFF282828), + fontWeight: FontWeight.normal, + fontSize: 14, + height: 20 / 14))), + SizedBox(height: 32), Row( - crossAxisAlignment: CrossAxisAlignment.center, children: [ - SizedBox(width: 16), - Flexible( - fit: FlexFit.tight, - child: Text(alarmStatusTranslations[alarm.status]!, - style: TextStyle( - color: Color(0xFF282828), - fontWeight: FontWeight.normal, - fontSize: 14, - height: 20 / 14) - ) - ), - SizedBox(height: 32), - Row( - children: [ - if ([AlarmStatus.CLEARED_UNACK, AlarmStatus.ACTIVE_UNACK].contains(alarm.status)) - CircleAvatar( - radius: 16, - backgroundColor: Color(0xffF0F4F9), - child: IconButton(icon: Icon(Icons.done, size: 18), padding: EdgeInsets.all(7.0), onPressed: () => _ackAlarm(alarm)) - ), - if ([AlarmStatus.ACTIVE_UNACK, AlarmStatus.ACTIVE_ACK].contains(alarm.status)) - Row( - children: [ - SizedBox(width: 4), - CircleAvatar( - radius: 16, - backgroundColor: Color(0xffF0F4F9), - child: IconButton(icon: Icon(Icons.clear, size: 18), padding: EdgeInsets.all(7.0), onPressed: () => _clearAlarm(alarm)) - ) - ] - ) - ], - ), - SizedBox(width: 8) + if ([ + AlarmStatus.CLEARED_UNACK, + AlarmStatus.ACTIVE_UNACK + ].contains(alarm.status)) + CircleAvatar( + radius: 16, + backgroundColor: Color(0xffF0F4F9), + child: IconButton( + icon: Icon(Icons.done, size: 18), + padding: EdgeInsets.all(7.0), + onPressed: () => _ackAlarm(alarm))), + if ([ + AlarmStatus.ACTIVE_UNACK, + AlarmStatus.ACTIVE_ACK + ].contains(alarm.status)) + Row(children: [ + SizedBox(width: 4), + CircleAvatar( + radius: 16, + backgroundColor: Color(0xffF0F4F9), + child: IconButton( + icon: Icon(Icons.clear, size: 18), + padding: EdgeInsets.all(7.0), + onPressed: () => _clearAlarm(alarm))) + ]) ], ), - SizedBox(height: 8) - ] - ) - ) - ] - ) + SizedBox(width: 8) + ], + ), + SizedBox(height: 8) + ])) + ]) ], ); } } _clearAlarm(AlarmInfo alarm) async { - var res = await confirm(title: 'Clear Alarm', message: 'Are you sure you want to clear Alarm?', cancel: 'No', ok: 'Yes'); + var res = await confirm( + title: 'Clear Alarm', + message: 'Are you sure you want to clear Alarm?', + cancel: 'No', + ok: 'Yes'); if (res != null && res) { setState(() { loading = true; }); await tbClient.getAlarmService().clearAlarm(alarm.id!.id!); - var newAlarm = await tbClient.getAlarmService().getAlarmInfo( - alarm.id!.id!); + var newAlarm = + await tbClient.getAlarmService().getAlarmInfo(alarm.id!.id!); setState(() { loading = false; this.alarm = newAlarm!; @@ -284,19 +298,22 @@ class _AlarmCardState extends TbContextState { } _ackAlarm(AlarmInfo alarm) async { - var res = await confirm(title: 'Acknowledge Alarm', message: 'Are you sure you want to acknowledge Alarm?', cancel: 'No', ok: 'Yes'); + var res = await confirm( + title: 'Acknowledge Alarm', + message: 'Are you sure you want to acknowledge Alarm?', + cancel: 'No', + ok: 'Yes'); if (res != null && res) { setState(() { loading = true; }); await tbClient.getAlarmService().ackAlarm(alarm.id!.id!); - var newAlarm = await tbClient.getAlarmService().getAlarmInfo( - alarm.id!.id!); + var newAlarm = + await tbClient.getAlarmService().getAlarmInfo(alarm.id!.id!); setState(() { loading = false; this.alarm = newAlarm!; }); } } - } diff --git a/lib/modules/alarm/alarms_list.dart b/lib/modules/alarm/alarms_list.dart index 7f56af2..a28947d 100644 --- a/lib/modules/alarm/alarms_list.dart +++ b/lib/modules/alarm/alarms_list.dart @@ -1,4 +1,3 @@ -import 'package:flutter/widgets.dart'; import 'package:thingsboard_app/core/context/tb_context.dart'; import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'package:thingsboard_app/core/entity/entities_list.dart'; @@ -6,9 +5,10 @@ import 'package:thingsboard_client/thingsboard_client.dart'; import 'alarms_base.dart'; -class AlarmsList extends BaseEntitiesWidget with AlarmsBase, EntitiesListStateBase { - - AlarmsList(TbContext tbContext, PageKeyController pageKeyController, {searchMode = false}) : super(tbContext, pageKeyController, searchMode: searchMode); - +class AlarmsList extends BaseEntitiesWidget + with AlarmsBase, EntitiesListStateBase { + AlarmsList( + TbContext tbContext, PageKeyController pageKeyController, + {searchMode = false}) + : super(tbContext, pageKeyController, searchMode: searchMode); } - diff --git a/lib/modules/alarm/alarms_page.dart b/lib/modules/alarm/alarms_page.dart index f17f440..ca0193c 100644 --- a/lib/modules/alarm/alarms_page.dart +++ b/lib/modules/alarm/alarms_page.dart @@ -7,18 +7,16 @@ import 'package:thingsboard_app/widgets/tb_app_bar.dart'; import 'alarms_list.dart'; class AlarmsPage extends TbContextWidget { - final bool searchMode; AlarmsPage(TbContext tbContext, {this.searchMode = false}) : super(tbContext); @override _AlarmsPageState createState() => _AlarmsPageState(); - } -class _AlarmsPageState extends TbContextState with AutomaticKeepAliveClientMixin { - +class _AlarmsPageState extends TbContextState + with AutomaticKeepAliveClientMixin { final AlarmQueryController _alarmQueryController = AlarmQueryController(); @override @@ -29,32 +27,26 @@ class _AlarmsPageState extends TbContextState with AutomaticKeepAliv @override Widget build(BuildContext context) { super.build(context); - var alarmsList = AlarmsList(tbContext, _alarmQueryController, searchMode: widget.searchMode); + var alarmsList = AlarmsList(tbContext, _alarmQueryController, + searchMode: widget.searchMode); PreferredSizeWidget appBar; if (widget.searchMode) { appBar = TbAppSearchBar( tbContext, - onSearch: (searchText) => _alarmQueryController.onSearchText(searchText), + onSearch: (searchText) => + _alarmQueryController.onSearchText(searchText), ); } else { - appBar = TbAppBar( - tbContext, - title: Text(alarmsList.title), - actions: [ - IconButton( - icon: Icon( - Icons.search - ), - onPressed: () { - navigateTo('/alarms?search=true'); - }, - ) - ]); + appBar = TbAppBar(tbContext, title: Text(alarmsList.title), actions: [ + IconButton( + icon: Icon(Icons.search), + onPressed: () { + navigateTo('/alarms?search=true'); + }, + ) + ]); } - return Scaffold( - appBar: appBar, - body: alarmsList - ); + return Scaffold(appBar: appBar, body: alarmsList); } @override @@ -62,5 +54,4 @@ class _AlarmsPageState extends TbContextState with AutomaticKeepAliv _alarmQueryController.dispose(); super.dispose(); } - } diff --git a/lib/modules/asset/asset_details_page.dart b/lib/modules/asset/asset_details_page.dart index 718875d..29055f1 100644 --- a/lib/modules/asset/asset_details_page.dart +++ b/lib/modules/asset/asset_details_page.dart @@ -5,11 +5,11 @@ import 'package:thingsboard_app/core/entity/entity_details_page.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; class AssetDetailsPage extends EntityDetailsPage { - - AssetDetailsPage(TbContext tbContext, String assetId): - super(tbContext, - entityId: assetId, - defaultTitle: 'Asset', subTitle: 'Asset details'); + AssetDetailsPage(TbContext tbContext, String assetId) + : super(tbContext, + entityId: assetId, + defaultTitle: 'Asset', + subTitle: 'Asset details'); @override Future fetchEntity(String assetId) { @@ -35,9 +35,6 @@ class AssetDetailsPage extends EntityDetailsPage { SizedBox(height: 16), Text('Assigned to customer', style: labelTextStyle), Text(asset.customerTitle ?? '', style: valueTextStyle), - ] - ) - ); + ])); } - } diff --git a/lib/modules/asset/asset_routes.dart b/lib/modules/asset/asset_routes.dart index a2ca78f..6a52743 100644 --- a/lib/modules/asset/asset_routes.dart +++ b/lib/modules/asset/asset_routes.dart @@ -7,13 +7,14 @@ import 'package:thingsboard_app/modules/asset/assets_page.dart'; import 'asset_details_page.dart'; class AssetRoutes extends TbRoutes { - - late var assetsHandler = Handler(handlerFunc: (BuildContext? context, Map params) { + late var assetsHandler = Handler( + handlerFunc: (BuildContext? context, Map params) { var searchMode = params['search']?.first == 'true'; return AssetsPage(tbContext, searchMode: searchMode); }); - late var assetDetailsHandler = Handler(handlerFunc: (BuildContext? context, Map params) { + late var assetDetailsHandler = Handler( + handlerFunc: (BuildContext? context, Map params) { return AssetDetailsPage(tbContext, params["id"][0]); }); @@ -24,5 +25,4 @@ class AssetRoutes extends TbRoutes { router.define("/assets", handler: assetsHandler); router.define("/asset/:id", handler: assetDetailsHandler); } - } diff --git a/lib/modules/asset/assets_base.dart b/lib/modules/asset/assets_base.dart index 0bdcb69..83ab9d4 100644 --- a/lib/modules/asset/assets_base.dart +++ b/lib/modules/asset/assets_base.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:thingsboard_app/core/entity/entities_base.dart'; import 'package:thingsboard_client/thingsboard_client.dart'; mixin AssetsBase on EntitiesBase { - @override String get title => 'Assets'; @@ -16,7 +14,9 @@ mixin AssetsBase on EntitiesBase { if (tbClient.isTenantAdmin()) { return tbClient.getAssetService().getTenantAssetInfos(pageLink); } else { - return tbClient.getAssetService().getCustomerAssetInfos(tbClient.getAuthUser()!.customerId, pageLink); + return tbClient + .getAssetService() + .getCustomerAssetInfos(tbClient.getAuthUser()!.customerId!, pageLink); } } @@ -41,115 +41,91 @@ mixin AssetsBase on EntitiesBase { } Widget _buildCard(context, AssetInfo asset) { - return Row( - mainAxisSize: MainAxisSize.max, - children: [ - Flexible( - fit: FlexFit.tight, - child: - Container( - padding: EdgeInsets.symmetric(vertical: 10, horizontal: 0), - child: Row( - mainAxisSize: MainAxisSize.max, - children: [ - SizedBox(width: 16), - Flexible( - fit: FlexFit.tight, - child: - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - FittedBox( - fit: BoxFit.fitWidth, - alignment: Alignment.centerLeft, - child: Text('${asset.name}', - style: TextStyle( - color: Color(0xFF282828), - fontSize: 14, - fontWeight: FontWeight.w500, - height: 20 / 14 - )) - ), - Text(entityDateFormat.format(DateTime.fromMillisecondsSinceEpoch(asset.createdTime!)), + return Row(mainAxisSize: MainAxisSize.max, children: [ + Flexible( + fit: FlexFit.tight, + child: Container( + padding: EdgeInsets.symmetric(vertical: 10, horizontal: 0), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + SizedBox(width: 16), + Flexible( + fit: FlexFit.tight, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FittedBox( + fit: BoxFit.fitWidth, + alignment: Alignment.centerLeft, + child: Text('${asset.name}', style: TextStyle( - color: Color(0xFFAFAFAF), - fontSize: 12, - fontWeight: FontWeight.normal, - height: 16 / 12 - )) - ] - ), - SizedBox(height: 4), - Text('${asset.type}', - style: TextStyle( - color: Color(0xFFAFAFAF), - fontSize: 12, - fontWeight: FontWeight.normal, - height: 1.33 - )) - ], - ) - ), - SizedBox(width: 16), - Icon(Icons.chevron_right, color: Color(0xFFACACAC)), - SizedBox(width: 16) - ], - ), - ) - - ) - ] - ); + color: Color(0xFF282828), + fontSize: 14, + fontWeight: FontWeight.w500, + height: 20 / 14))), + Text( + entityDateFormat.format( + DateTime.fromMillisecondsSinceEpoch( + asset.createdTime!)), + style: TextStyle( + color: Color(0xFFAFAFAF), + fontSize: 12, + fontWeight: FontWeight.normal, + height: 16 / 12)) + ]), + SizedBox(height: 4), + Text('${asset.type}', + style: TextStyle( + color: Color(0xFFAFAFAF), + fontSize: 12, + fontWeight: FontWeight.normal, + height: 1.33)) + ], + )), + SizedBox(width: 16), + Icon(Icons.chevron_right, color: Color(0xFFACACAC)), + SizedBox(width: 16) + ], + ), + )) + ]); } Widget _buildListWidgetCard(BuildContext context, AssetInfo asset) { - return Row( - mainAxisSize: MainAxisSize.min, - children: [ - Flexible( - fit: FlexFit.loose, - child: - Container( - padding: EdgeInsets.symmetric(vertical: 9, horizontal: 16), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Flexible( - fit: FlexFit.loose, - child: - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - FittedBox( - fit: BoxFit.fitWidth, - alignment: Alignment.centerLeft, - child: Text('${asset.name}', - style: TextStyle( - color: Color(0xFF282828), - fontSize: 14, - fontWeight: FontWeight.w500, - height: 1.7 - )) - ), - Text('${asset.type}', + return Row(mainAxisSize: MainAxisSize.min, children: [ + Flexible( + fit: FlexFit.loose, + child: Container( + padding: EdgeInsets.symmetric(vertical: 9, horizontal: 16), + child: Row(mainAxisSize: MainAxisSize.min, children: [ + Flexible( + fit: FlexFit.loose, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + FittedBox( + fit: BoxFit.fitWidth, + alignment: Alignment.centerLeft, + child: Text('${asset.name}', style: TextStyle( - color: Color(0xFFAFAFAF), - fontSize: 12, - fontWeight: FontWeight.normal, - height: 1.33 - )) - ], - ) - ) - ] - ) - ) - ) - ] - ); + color: Color(0xFF282828), + fontSize: 14, + fontWeight: FontWeight.w500, + height: 1.7))), + Text('${asset.type}', + style: TextStyle( + color: Color(0xFFAFAFAF), + fontSize: 12, + fontWeight: FontWeight.normal, + height: 1.33)) + ], + )) + ]))) + ]); } } diff --git a/lib/modules/asset/assets_list.dart b/lib/modules/asset/assets_list.dart index aa3da35..9f08002 100644 --- a/lib/modules/asset/assets_list.dart +++ b/lib/modules/asset/assets_list.dart @@ -5,9 +5,9 @@ import 'package:thingsboard_client/thingsboard_client.dart'; import 'assets_base.dart'; -class AssetsList extends BaseEntitiesWidget with AssetsBase, EntitiesListStateBase { - - AssetsList(TbContext tbContext, PageKeyController pageKeyController, {searchMode = false}) : super(tbContext, pageKeyController, searchMode: searchMode); - +class AssetsList extends BaseEntitiesWidget + with AssetsBase, EntitiesListStateBase { + AssetsList(TbContext tbContext, PageKeyController