SVG images support
This commit is contained in:
@@ -5,6 +5,7 @@ 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_app/utils/utils.dart';
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
|
||||
mixin DashboardsBase on EntitiesBase<DashboardInfo, PageLink> {
|
||||
@@ -155,8 +156,7 @@ class _DashboardGridCardState extends TbContextState<DashboardGridCard, _Dashboa
|
||||
var hasImage = widget.dashboard.image != null;
|
||||
Widget image;
|
||||
if (hasImage) {
|
||||
var uriData = UriData.parse(widget.dashboard.image!);
|
||||
image = Image.memory(uriData.contentAsBytes());
|
||||
image = Utils.imageFromBase64(widget.dashboard.image!);
|
||||
} else {
|
||||
image = Image.asset(ThingsboardImage.dashboardPlaceholder);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,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/widgets/tb_progress_indicator.dart';
|
||||
import 'package:thingsboard_app/utils/utils.dart';
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
|
||||
mixin DeviceProfilesBase on EntitiesBase<DeviceProfileInfo, PageLink> {
|
||||
@@ -278,13 +278,15 @@ class _DeviceProfileCardState extends TbContextState<DeviceProfileCard, _DeviceP
|
||||
var hasImage = entity.image != null;
|
||||
Widget image;
|
||||
BoxFit imageFit;
|
||||
double padding;
|
||||
if (hasImage) {
|
||||
var uriData = UriData.parse(entity.image!);
|
||||
image = Image.memory(uriData.contentAsBytes());
|
||||
image = Utils.imageFromBase64(entity.image!);
|
||||
imageFit = BoxFit.contain;
|
||||
padding = 8;
|
||||
} else {
|
||||
image = Image.asset(ThingsboardImage.deviceProfilePlaceholder);
|
||||
imageFit = BoxFit.cover;
|
||||
padding = 0;
|
||||
}
|
||||
return
|
||||
ClipRRect(
|
||||
@@ -295,10 +297,13 @@ class _DeviceProfileCardState extends TbContextState<DeviceProfileCard, _DeviceP
|
||||
child: Stack (
|
||||
children: [
|
||||
SizedBox.expand(
|
||||
child: FittedBox(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
fit: imageFit,
|
||||
child: image
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(padding),
|
||||
child: FittedBox(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
fit: imageFit,
|
||||
child: image
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
@@ -151,8 +151,7 @@ class _DeviceCardState extends TbContextState<DeviceCard, _DeviceCardState> {
|
||||
Widget image;
|
||||
BoxFit imageFit;
|
||||
if (profile.image != null) {
|
||||
var uriData = UriData.parse(profile.image!);
|
||||
image = Image.memory(uriData.contentAsBytes());
|
||||
image = Utils.imageFromBase64(profile.image!);
|
||||
imageFit = BoxFit.contain;
|
||||
} else {
|
||||
image = Image.asset(ThingsboardImage.deviceProfilePlaceholder);
|
||||
@@ -296,8 +295,7 @@ class _DeviceCardState extends TbContextState<DeviceCard, _DeviceCardState> {
|
||||
Widget image;
|
||||
BoxFit imageFit;
|
||||
if (profile.image != null) {
|
||||
var uriData = UriData.parse(profile.image!);
|
||||
image = Image.memory(uriData.contentAsBytes());
|
||||
image = Utils.imageFromBase64(profile.image!);
|
||||
imageFit = BoxFit.contain;
|
||||
} else {
|
||||
image = Image.asset(ThingsboardImage.deviceProfilePlaceholder);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
|
||||
abstract class Utils {
|
||||
@@ -45,4 +47,13 @@ abstract class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
static Widget imageFromBase64(String base64, {Color? color, double? width, double? height, String? semanticLabel}) {
|
||||
var uriData = UriData.parse(base64);
|
||||
if (uriData.mimeType == 'image/svg+xml') {
|
||||
return SvgPicture.memory(uriData.contentAsBytes(), color: color, width: width, height: height, semanticsLabel: semanticLabel);
|
||||
} else {
|
||||
return Image.memory(uriData.contentAsBytes(), color: color, width: width, height: height, semanticLabel: semanticLabel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user