From 64811ea3202b063eee7efd272ae3e788543a5f01 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Tue, 14 Nov 2023 17:25:48 +0100 Subject: [PATCH] feat(neon): Support data URIs in NeonUrlImage Signed-off-by: jld3103 --- packages/neon/neon/lib/src/widgets/image.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/neon/neon/lib/src/widgets/image.dart b/packages/neon/neon/lib/src/widgets/image.dart index 46ed7fd8..5f561c5f 100644 --- a/packages/neon/neon/lib/src/widgets/image.dart +++ b/packages/neon/neon/lib/src/widgets/image.dart @@ -354,19 +354,27 @@ class NeonUrlImage extends StatelessWidget { Widget build(final BuildContext context) { final account = this.account ?? NeonProvider.of(context).activeAccount.value!; + final uri = Uri.parse(url); + final dataUri = uri.data; + return NeonCachedImage( getImage: () async { - final uri = account.completeUri(Uri.parse(url)); + if (dataUri != null) { + return dataUri.contentAsBytes(); + } + + final completedUri = account.completeUri(uri); final headers = {}; // Only send the authentication headers when sending the request to the server of the account - if (uri.toString().startsWith(account.serverURL.toString()) && account.client.authentications.isNotEmpty) { + if (completedUri.toString().startsWith(account.serverURL.toString()) && + account.client.authentications.isNotEmpty) { headers.addAll(account.client.authentications.first.headers); } final response = await account.client.executeRawRequest( 'GET', - uri, + completedUri, headers, null, const {200}, @@ -377,7 +385,7 @@ class NeonUrlImage extends StatelessWidget { cacheKey: '${account.id}-$url', reviver: reviver, writeCache: writeCache, - isSvgHint: isSvgHint, + isSvgHint: isSvgHint || (dataUri?.mimeType.contains('svg') ?? false), size: size, fit: fit, svgColorFilter: svgColorFilter,