Handle device default dashboard
This commit is contained in:
@@ -7,5 +7,11 @@
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.VIDEO_CAPTURE" />
|
||||
<uses-permission android:name="android.permission.AUDIO_CAPTURE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<application android:usesCleartextTraffic="true"/>
|
||||
</manifest>
|
||||
|
||||
@@ -4,7 +4,13 @@
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<application
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.VIDEO_CAPTURE" />
|
||||
<uses-permission android:name="android.permission.AUDIO_CAPTURE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<application
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:label="ThingsBoard App"
|
||||
android:icon="@mipmap/launcher_icon">
|
||||
|
||||
@@ -7,4 +7,11 @@
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.VIDEO_CAPTURE" />
|
||||
<uses-permission android:name="android.permission.AUDIO_CAPTURE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -44,6 +44,7 @@ class _LoginPageState extends TbPageState<LoginPage, _LoginPageState> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text('Login to ThingsBoard'),
|
||||
),
|
||||
|
||||
@@ -30,6 +30,8 @@ mixin EntitiesBase<T, P> on HasTbContext {
|
||||
|
||||
Widget? buildHeading(BuildContext context) => null;
|
||||
|
||||
Key? getKey(T entity) => null;
|
||||
|
||||
Widget buildEntityListCard(BuildContext context, T entity) {
|
||||
return Text('Not implemented!');
|
||||
}
|
||||
@@ -68,7 +70,7 @@ class PageKeyValue<P> {
|
||||
|
||||
class PageLinkController extends PageKeyController<PageLink> {
|
||||
|
||||
PageLinkController({int pageSize = 10, 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();
|
||||
@@ -83,7 +85,7 @@ class PageLinkController extends PageKeyController<PageLink> {
|
||||
|
||||
class TimePageLinkController extends PageKeyController<TimePageLink> {
|
||||
|
||||
TimePageLinkController({int pageSize = 10, 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();
|
||||
|
||||
@@ -44,6 +44,7 @@ class _EntitiesGridState<T, P> extends BaseEntitiesState<T, P> {
|
||||
builderDelegate: PagedChildBuilderDelegate<T>(
|
||||
itemBuilder: (context, item, index) => EntityGridCard<T>(
|
||||
item,
|
||||
key: widget.getKey(item),
|
||||
entityCardWidgetBuilder: widget.buildEntityGridCard,
|
||||
onEntityTap: widget.onEntityTap,
|
||||
settings: widget.entityGridCardSettings(item),
|
||||
|
||||
@@ -35,6 +35,7 @@ class _EntitiesListState<T,P> extends BaseEntitiesState<T, P> {
|
||||
builderDelegate: PagedChildBuilderDelegate<T>(
|
||||
itemBuilder: (context, item, index) => EntityListCard<T>(
|
||||
item,
|
||||
key: widget.getKey(item),
|
||||
entityCardWidgetBuilder: widget.buildEntityListCard,
|
||||
onEntityTap: widget.onEntityTap,
|
||||
settings: widget.entityListCardSettings(item),
|
||||
|
||||
@@ -11,13 +11,14 @@ class EntityGridCard<T> extends StatelessWidget {
|
||||
final EntityCardWidgetBuilder<T> _entityCardWidgetBuilder;
|
||||
final EntityCardSettings _settings;
|
||||
|
||||
EntityGridCard(T entity, {EntityTapFunction<T>? onEntityTap,
|
||||
EntityGridCard(T entity, {Key? key, EntityTapFunction<T>? onEntityTap,
|
||||
required EntityCardWidgetBuilder<T> entityCardWidgetBuilder,
|
||||
required EntityCardSettings settings}):
|
||||
this._entity = entity,
|
||||
this._onEntityTap = onEntityTap,
|
||||
this._entityCardWidgetBuilder = entityCardWidgetBuilder,
|
||||
this._settings = settings;
|
||||
this._settings = settings,
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -11,7 +11,7 @@ class EntityListCard<T> extends StatelessWidget {
|
||||
final EntityCardWidgetBuilder<T> _entityCardWidgetBuilder;
|
||||
final EntityCardSettings _settings;
|
||||
|
||||
EntityListCard(T entity, {EntityTapFunction<T>? onEntityTap,
|
||||
EntityListCard(T entity, {Key? key, EntityTapFunction<T>? onEntityTap,
|
||||
required EntityCardWidgetBuilder<T> entityCardWidgetBuilder,
|
||||
required EntityCardSettings settings,
|
||||
bool listWidgetCard = false}):
|
||||
@@ -19,7 +19,8 @@ class EntityListCard<T> extends StatelessWidget {
|
||||
this._onEntityTap = onEntityTap,
|
||||
this._entityCardWidgetBuilder = entityCardWidgetBuilder,
|
||||
this._settings = settings,
|
||||
this._listWidgetCard = listWidgetCard;
|
||||
this._listWidgetCard = listWidgetCard,
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -11,6 +11,8 @@ final appRouter = ThingsboardAppRouter();
|
||||
void main() async {
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
// await FlutterDownloader.initialize();
|
||||
// await Permission.storage.request();
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
@@ -49,6 +50,7 @@ class _DashboardState extends TbContextState<Dashboard, _DashboardState> {
|
||||
useShouldOverrideUrlLoading: true,
|
||||
mediaPlaybackRequiresUserGesture: false,
|
||||
javaScriptEnabled: true,
|
||||
// useOnDownloadStart: true
|
||||
),
|
||||
android: AndroidInAppWebViewOptions(
|
||||
useHybridComposition: false,
|
||||
@@ -96,127 +98,144 @@ class _DashboardState extends TbContextState<Dashboard, _DashboardState> {
|
||||
}
|
||||
return true;
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
InAppWebView(
|
||||
key: webViewKey,
|
||||
initialUrlRequest: URLRequest(url: Uri.parse(_dashboardUrl)),
|
||||
initialOptions: options,
|
||||
onWebViewCreated: (webViewController) {
|
||||
webViewController.addJavaScriptHandler(handlerName: "tbMobileDashboardStateNameHandler", callback: (args) async {
|
||||
log.debug("Invoked tbMobileDashboardStateNameHandler: $args");
|
||||
webViewLoading.value = false;
|
||||
if (args.isNotEmpty && args[0] is String) {
|
||||
if (widget._titleCallback != null) {
|
||||
widget._titleCallback!(args[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
webViewController.addJavaScriptHandler(handlerName: "tbMobileHandler", callback: (args) async {
|
||||
log.debug("Invoked tbMobileHandler: $args");
|
||||
return await widgetActionHandler.handleWidgetMobileAction(args, webViewController);
|
||||
});
|
||||
_controller.complete(webViewController);
|
||||
},
|
||||
shouldOverrideUrlLoading: (controller, navigationAction) async {
|
||||
var uri = navigationAction.request.url!;
|
||||
var uriString = uri.toString();
|
||||
log.debug('shouldOverrideUrlLoading $uriString');
|
||||
if (![
|
||||
"http",
|
||||
"https",
|
||||
"file",
|
||||
"chrome",
|
||||
"data",
|
||||
"javascript",
|
||||
"about"
|
||||
].contains(uri.scheme)) {
|
||||
if (await canLaunch(uriString)) {
|
||||
// Launch the App
|
||||
await launch(
|
||||
uriString,
|
||||
);
|
||||
// and cancel the request
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
}
|
||||
return NavigationActionPolicy.ALLOW;
|
||||
},
|
||||
onUpdateVisitedHistory: (controller, url, androidIsReload) async {
|
||||
if (url != null) {
|
||||
String newStateId = url.pathSegments.last;
|
||||
log.debug('onUpdateVisitedHistory: $newStateId');
|
||||
if (newStateId == 'profile') {
|
||||
webViewLoading.value = true;
|
||||
await controller.goBack();
|
||||
await navigateTo('/profile');
|
||||
webViewLoading.value = false;
|
||||
return;
|
||||
} else if (newStateId == 'login') {
|
||||
webViewLoading.value = true;
|
||||
await controller.pauseTimers();
|
||||
await controller.stopLoading();
|
||||
await tbClient.logout();
|
||||
return;
|
||||
} else if (['devices', 'assets', 'dashboards'].contains(newStateId)) {
|
||||
var controller = await _controller.future;
|
||||
await controller.goBack();
|
||||
navigateTo('/$newStateId');
|
||||
return;
|
||||
} else {
|
||||
if (url.pathSegments.length > 1) {
|
||||
var segmentName = url.pathSegments[url.pathSegments.length-2];
|
||||
if (segmentName == 'dashboards' && widget._home != true) {
|
||||
webViewLoading.value = true;
|
||||
var targetPath = _createDashboardNavigationPath(newStateId, fullscreen: widget._fullscreen);
|
||||
await navigateTo(targetPath, replace: true);
|
||||
return;
|
||||
} else if (segmentName == 'dashboard') {
|
||||
_currentDashboardId = newStateId;
|
||||
_currentDashboardState = url.queryParameters['state'];
|
||||
return;
|
||||
child: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
InAppWebView(
|
||||
key: webViewKey,
|
||||
initialUrlRequest: URLRequest(url: Uri.parse(_dashboardUrl)),
|
||||
initialOptions: options,
|
||||
onWebViewCreated: (webViewController) {
|
||||
webViewController.addJavaScriptHandler(handlerName: "tbMobileDashboardStateNameHandler", callback: (args) async {
|
||||
log.debug("Invoked tbMobileDashboardStateNameHandler: $args");
|
||||
webViewLoading.value = false;
|
||||
if (args.isNotEmpty && args[0] is String) {
|
||||
if (widget._titleCallback != null) {
|
||||
widget._titleCallback!(args[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
webViewController.addJavaScriptHandler(handlerName: "tbMobileHandler", callback: (args) async {
|
||||
log.debug("Invoked tbMobileHandler: $args");
|
||||
return await widgetActionHandler.handleWidgetMobileAction(args, webViewController);
|
||||
});
|
||||
_controller.complete(webViewController);
|
||||
},
|
||||
shouldOverrideUrlLoading: (controller, navigationAction) async {
|
||||
var uri = navigationAction.request.url!;
|
||||
var uriString = uri.toString();
|
||||
log.debug('shouldOverrideUrlLoading $uriString');
|
||||
if (![
|
||||
"http",
|
||||
"https",
|
||||
"file",
|
||||
"chrome",
|
||||
"data",
|
||||
"javascript",
|
||||
"about"
|
||||
].contains(uri.scheme)) {
|
||||
if (await canLaunch(uriString)) {
|
||||
// Launch the App
|
||||
await launch(
|
||||
uriString,
|
||||
);
|
||||
// and cancel the request
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
}
|
||||
webViewLoading.value = true;
|
||||
if (widget._home == true) {
|
||||
await navigateTo('/home', replace: true);
|
||||
|
||||
return Platform.isIOS ? NavigationActionPolicy.ALLOW : NavigationActionPolicy.CANCEL;
|
||||
},
|
||||
onUpdateVisitedHistory: (controller, url, androidIsReload) async {
|
||||
if (url != null) {
|
||||
String newStateId = url.pathSegments.last;
|
||||
log.debug('onUpdateVisitedHistory: $newStateId');
|
||||
if (newStateId == 'profile') {
|
||||
webViewLoading.value = true;
|
||||
await controller.goBack();
|
||||
await navigateTo('/profile');
|
||||
webViewLoading.value = false;
|
||||
return;
|
||||
} else if (newStateId == 'login') {
|
||||
webViewLoading.value = true;
|
||||
await controller.pauseTimers();
|
||||
await controller.stopLoading();
|
||||
await tbClient.logout();
|
||||
return;
|
||||
} else if (['devices', 'assets', 'dashboards'].contains(newStateId)) {
|
||||
var controller = await _controller.future;
|
||||
await controller.goBack();
|
||||
navigateTo('/$newStateId');
|
||||
return;
|
||||
} else {
|
||||
if (url.pathSegments.length > 1) {
|
||||
var segmentName = url.pathSegments[url.pathSegments.length-2];
|
||||
if (segmentName == 'dashboards' && widget._home != true) {
|
||||
webViewLoading.value = true;
|
||||
var targetPath = _createDashboardNavigationPath(newStateId, fullscreen: widget._fullscreen);
|
||||
await navigateTo(targetPath, replace: true);
|
||||
return;
|
||||
} else if (segmentName == 'dashboard') {
|
||||
_currentDashboardId = newStateId;
|
||||
_currentDashboardState = url.queryParameters['state'];
|
||||
return;
|
||||
}
|
||||
}
|
||||
webViewLoading.value = true;
|
||||
if (widget._home == true) {
|
||||
await navigateTo('/home', replace: true);
|
||||
} else {
|
||||
var targetPath = _createDashboardNavigationPath(_currentDashboardId, state: _currentDashboardState, fullscreen: widget._fullscreen);
|
||||
await navigateTo(targetPath, replace: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onConsoleMessage: (controller, consoleMessage) {
|
||||
log.debug('[JavaScript console] ${consoleMessage.messageLevel}: ${consoleMessage.message}');
|
||||
},
|
||||
onLoadStart: (controller, url) async {
|
||||
log.debug('onLoadStart: $url');
|
||||
// await _setTokens(controller.webStorage.localStorage);
|
||||
},
|
||||
onLoadStop: (controller, url) async {
|
||||
log.debug('onLoadStop: $url');
|
||||
// await _setTokens(controller.webStorage.localStorage);
|
||||
},
|
||||
androidOnPermissionRequest: (controller, origin, resources) async {
|
||||
log.debug('androidOnPermissionRequest origin: $origin, resources: $resources');
|
||||
return PermissionRequestResponse(
|
||||
resources: resources,
|
||||
action: PermissionRequestResponseAction.GRANT);
|
||||
},
|
||||
/* onDownloadStart: (controller, url) async {
|
||||
log.debug("onDownloadStart $url");
|
||||
final taskId = await FlutterDownloader.enqueue(
|
||||
url: url.toString(),
|
||||
savedDir: (await getExternalStorageDirectory())!.path,
|
||||
showNotification: true,
|
||||
openFileFromNotification: true,
|
||||
);
|
||||
} */
|
||||
),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: webViewLoading,
|
||||
builder: (BuildContext context, bool loading, child) {
|
||||
if (!loading) {
|
||||
return SizedBox.shrink();
|
||||
} else {
|
||||
var targetPath = _createDashboardNavigationPath(_currentDashboardId, state: _currentDashboardState, fullscreen: widget._fullscreen);
|
||||
await navigateTo(targetPath, replace: true);
|
||||
return Container(
|
||||
decoration: BoxDecoration(color: Colors.white),
|
||||
child: Center(
|
||||
child: RefreshProgressIndicator()
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onConsoleMessage: (controller, consoleMessage) {
|
||||
log.debug('[JavaScript console] ${consoleMessage.messageLevel}: ${consoleMessage.message}');
|
||||
},
|
||||
onLoadStart: (controller, url) async {
|
||||
log.debug('onLoadStart: $url');
|
||||
// await _setTokens(controller.webStorage.localStorage);
|
||||
},
|
||||
onLoadStop: (controller, url) async {
|
||||
log.debug('onLoadStop: $url');
|
||||
// await _setTokens(controller.webStorage.localStorage);
|
||||
},
|
||||
|
||||
),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: webViewLoading,
|
||||
builder: (BuildContext context, bool loading, child) {
|
||||
if (!loading) {
|
||||
return SizedBox.shrink();
|
||||
} else {
|
||||
return Container(
|
||||
decoration: BoxDecoration(color: Colors.white),
|
||||
child: Center(
|
||||
child: RefreshProgressIndicator()
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:thingsboard_app/constants/assets_path.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';
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
|
||||
@@ -41,61 +43,8 @@ mixin DashboardsBase on EntitiesBase<DashboardInfo, PageLink> {
|
||||
EntityCardSettings entityGridCardSettings(DashboardInfo dashboard) => EntityCardSettings(dropShadow: true); //dashboard.image != null);
|
||||
|
||||
@override
|
||||
Widget buildEntityGridCard(BuildContext context, DashboardInfo entity) {
|
||||
var hasImage = entity.image != null;
|
||||
Widget image;
|
||||
if (hasImage) {
|
||||
var uriData = UriData.parse(entity.image!);
|
||||
image = Image.memory(uriData.contentAsBytes());
|
||||
} else {
|
||||
image = Image.asset(ThingsboardImage.dashboardPlaceholder);
|
||||
}
|
||||
return
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: image,
|
||||
)
|
||||
),
|
||||
hasImage ? Positioned.fill(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0x00000000),
|
||||
Color(0xb7000000)
|
||||
],
|
||||
stops: [0.4219, 1]
|
||||
)
|
||||
)
|
||||
),
|
||||
) : Container(),
|
||||
Positioned(
|
||||
bottom: 16,
|
||||
left: 16,
|
||||
right: 16,
|
||||
child: AutoSizeText(entity.title,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
minFontSize: 8,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: hasImage ? Colors.white : Color(0xFF282828),
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
height: 20 / 14
|
||||
),
|
||||
)
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
Widget buildEntityGridCard(BuildContext context, DashboardInfo dashboard) {
|
||||
return DashboardGridCard(tbContext, dashboard: dashboard);
|
||||
}
|
||||
|
||||
Widget _buildEntityListCard(BuildContext context, DashboardInfo dashboard, bool listWidgetCard) {
|
||||
@@ -173,3 +122,91 @@ mixin DashboardsBase on EntitiesBase<DashboardInfo, PageLink> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DashboardGridCard extends TbContextWidget<DashboardGridCard, _DashboardGridCardState> {
|
||||
|
||||
final DashboardInfo dashboard;
|
||||
|
||||
DashboardGridCard(TbContext tbContext, {required this.dashboard}) : super(tbContext);
|
||||
|
||||
@override
|
||||
_DashboardGridCardState createState() => _DashboardGridCardState();
|
||||
|
||||
}
|
||||
|
||||
class _DashboardGridCardState extends TbContextState<DashboardGridCard, _DashboardGridCardState> {
|
||||
|
||||
_DashboardGridCardState(): super();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(DashboardGridCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var hasImage = widget.dashboard.image != null;
|
||||
Widget image;
|
||||
BoxFit imageFit;
|
||||
if (hasImage) {
|
||||
var uriData = UriData.parse(widget.dashboard.image!);
|
||||
image = Image.memory(uriData.contentAsBytes());
|
||||
imageFit = BoxFit.contain;
|
||||
} else {
|
||||
image = Image.asset(ThingsboardImage.dashboardPlaceholder);
|
||||
imageFit = BoxFit.cover;
|
||||
}
|
||||
return
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: FittedBox(
|
||||
fit: imageFit,
|
||||
child: image,
|
||||
)
|
||||
),
|
||||
hasImage ? Positioned.fill(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0x00000000),
|
||||
Color(0xb7000000)
|
||||
],
|
||||
stops: [0.4219, 1]
|
||||
)
|
||||
)
|
||||
),
|
||||
) : Container(),
|
||||
Positioned(
|
||||
bottom: 16,
|
||||
left: 16,
|
||||
right: 16,
|
||||
child: AutoSizeText(widget.dashboard.title,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
minFontSize: 8,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: hasImage ? Colors.white : Color(0xFF282828),
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
height: 20 / 14
|
||||
),
|
||||
)
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -264,11 +264,14 @@ class _DeviceProfileCardState extends TbContextState<DeviceProfileCard, _DeviceP
|
||||
var entity = widget.deviceProfile;
|
||||
var hasImage = entity.image != null;
|
||||
Widget image;
|
||||
BoxFit imageFit;
|
||||
if (hasImage) {
|
||||
var uriData = UriData.parse(entity.image!);
|
||||
image = Image.memory(uriData.contentAsBytes());
|
||||
imageFit = BoxFit.contain;
|
||||
} else {
|
||||
image = Image.asset(ThingsboardImage.deviceProfilePlaceholder);
|
||||
imageFit = BoxFit.cover;
|
||||
}
|
||||
return
|
||||
ClipRRect(
|
||||
@@ -277,7 +280,7 @@ class _DeviceProfileCardState extends TbContextState<DeviceProfileCard, _DeviceP
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
fit: imageFit,
|
||||
child: image,
|
||||
)
|
||||
),
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -6,6 +8,7 @@ import 'package:thingsboard_app/core/context/tb_context_widget.dart';
|
||||
import 'package:thingsboard_app/core/entity/entities_base.dart';
|
||||
import 'package:thingsboard_app/utils/services/device_profile_cache.dart';
|
||||
import 'package:thingsboard_app/utils/services/entity_query_api.dart';
|
||||
import 'package:thingsboard_app/utils/utils.dart';
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
|
||||
mixin DevicesBase on EntitiesBase<EntityData, EntityDataQuery> {
|
||||
@@ -22,8 +25,18 @@ mixin DevicesBase on EntitiesBase<EntityData, EntityDataQuery> {
|
||||
}
|
||||
|
||||
@override
|
||||
void onEntityTap(EntityData device) {
|
||||
navigateTo('/device/${device.entityId.id}');
|
||||
void onEntityTap(EntityData device) async {
|
||||
var profile = await DeviceProfileCache.getDeviceProfileInfo(tbClient, device.field('type')!, device.entityId.id!);
|
||||
if (profile.defaultDashboardId != null) {
|
||||
var dashboardId = profile.defaultDashboardId!.id!;
|
||||
var state = Utils.createDashboardEntityState(device.entityId, entityName: device.field('name')!, entityLabel: device.field('label')!);
|
||||
navigateTo('/dashboard/$dashboardId?title=${device.field('name')!}&state=$state');
|
||||
} else {
|
||||
// navigateTo('/device/${device.entityId.id}');
|
||||
if (tbClient.isTenantAdmin()) {
|
||||
showWarnNotification('BALALAI');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -126,7 +139,7 @@ class _DeviceCardState extends TbContextState<DeviceCard, _DeviceCardState> {
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
fit: BoxFit.contain,
|
||||
child: Image.memory(uriData.contentAsBytes()),
|
||||
)
|
||||
),
|
||||
@@ -154,7 +167,9 @@ class _DeviceCardState extends TbContextState<DeviceCard, _DeviceCardState> {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Center(child: RefreshProgressIndicator());
|
||||
return Center(child: RefreshProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation(Theme.of(tbContext.currentState!.context).colorScheme.primary)
|
||||
));
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
@@ -19,6 +19,7 @@ abstract class EntityQueryApi {
|
||||
static final defaultDeviceFields = <EntityKey>[
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'name'),
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'type'),
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'label'),
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'createdTime')
|
||||
];
|
||||
|
||||
@@ -29,7 +30,7 @@ abstract class EntityQueryApi {
|
||||
static Future<int> countDevices(ThingsboardClient tbClient, {String? deviceType, bool? active}) {
|
||||
EntityFilter deviceFilter;
|
||||
if (deviceType != null) {
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType);
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType, deviceNameFilter: '');
|
||||
} else {
|
||||
deviceFilter = EntityTypeFilter(entityType: EntityType.DEVICE);
|
||||
}
|
||||
@@ -40,11 +41,11 @@ abstract class EntityQueryApi {
|
||||
return tbClient.getEntityQueryService().countEntitiesByQuery(deviceCountQuery);
|
||||
}
|
||||
|
||||
static EntityDataQuery createDefaultDeviceQuery({int pageSize = 10, String? searchText, String? deviceType, bool? active}) {
|
||||
static EntityDataQuery createDefaultDeviceQuery({int pageSize = 20, String? searchText, String? deviceType, bool? active}) {
|
||||
EntityFilter deviceFilter;
|
||||
List<KeyFilter>? keyFilters;
|
||||
if (deviceType != null) {
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType);
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType, deviceNameFilter: '');
|
||||
} else {
|
||||
deviceFilter = EntityTypeFilter(entityType: EntityType.DEVICE);
|
||||
}
|
||||
|
||||
30
lib/utils/utils.dart
Normal file
30
lib/utils/utils.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
|
||||
abstract class Utils {
|
||||
|
||||
static String createDashboardEntityState(EntityId entityId, {String? entityName, String? entityLabel}) {
|
||||
var stateObj = [<String, dynamic>{
|
||||
'params': <String, dynamic>{
|
||||
'entityId': entityId.toJson()
|
||||
}
|
||||
}];
|
||||
if (entityName != null) {
|
||||
stateObj[0]['params']['entityName'] = entityName;
|
||||
}
|
||||
if (entityLabel != null) {
|
||||
stateObj[0]['params']['entityLabel'] = entityLabel;
|
||||
}
|
||||
var stateJson = json.encode(stateObj);
|
||||
var encodedUri = Uri.encodeComponent(stateJson);
|
||||
encodedUri = encodedUri.replaceAllMapped(RegExp(r'%([0-9A-F]{2})'), (match) {
|
||||
var p1 = match.group(1)!;
|
||||
return String.fromCharCode(int.parse(p1, radix: 16));
|
||||
});
|
||||
return Uri.encodeComponent(
|
||||
base64.encode(utf8.encode(encodedUri))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -84,7 +84,7 @@ packages:
|
||||
name: device_info
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "2.0.2"
|
||||
device_info_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -145,7 +145,7 @@ packages:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "2.0.2"
|
||||
flutter_secure_storage:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -225,7 +225,7 @@ packages:
|
||||
name: image_picker
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.5+2"
|
||||
version: "0.7.5+3"
|
||||
image_picker_for_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -411,7 +411,7 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "39f0c98fc6543436d0fc388aad71688505f48d65"
|
||||
resolved-ref: "0fbaccafa7c0b3b3a6c9ac689c5949164101c5b5"
|
||||
url: "git@github.com:thingsboard/dart_thingsboard_client.git"
|
||||
source: git
|
||||
version: "1.0.0"
|
||||
|
||||
@@ -24,6 +24,9 @@ dependencies:
|
||||
fading_edge_scrollview: ^2.0.0
|
||||
stream_transform: ^2.0.0
|
||||
flutter_inappwebview: ^5.3.2
|
||||
# flutter_downloader: ^1.6.0
|
||||
# permission_handler: ^8.0.0+2
|
||||
# path_provider: ^2.0.2
|
||||
url_launcher: ^6.0.3
|
||||
image_picker: ^0.7.4
|
||||
mime: ^1.0.0
|
||||
|
||||
Reference in New Issue
Block a user