Skip to content

Commit

Permalink
feat(neon): Support data URIs in NeonUrlImage
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <jld3103yt@gmail.com>
  • Loading branch information
provokateurin committed Nov 16, 2023
1 parent ab892ee commit d1b796b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/neon/neon/lib/src/widgets/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,19 +354,27 @@ class NeonUrlImage extends StatelessWidget {
Widget build(final BuildContext context) {
final account = this.account ?? NeonProvider.of<AccountsBloc>(context).activeAccount.value!;

final uri = Uri.parse(url);
final dataUri = uri.isScheme('data') ? UriData.fromUri(uri) : null;

return NeonCachedImage(
getImage: () async {
final uri = account.completeUri(Uri.parse(url));
if (dataUri != null) {
return dataUri.contentAsBytes();
}

final completedUri = account.completeUri(uri);
final headers = <String, String>{};

// 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},
Expand All @@ -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,
Expand Down

0 comments on commit d1b796b

Please sign in to comment.