Skip to content

Commit

Permalink
fix: Fixed some SI files that were not loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Oct 23, 2024
1 parent ad15112 commit be0cf0c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
49 changes: 45 additions & 4 deletions lib/widgets/sized_scalable_image.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jovial_svg/jovial_svg.dart';
import 'package:jovial_svg/src/compact.dart';

/// A sized scalable image widget.
class SizedScalableImageWidget extends StatelessWidget {
Expand Down Expand Up @@ -39,11 +42,14 @@ class SizedScalableImageWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
File file = File(asset);
Widget child = ScalableImageWidget.fromSISource(
si: ScalableImageSource.fromSI(
rootBundle,
asset,
),
si: file.existsSync()
? _SIFileSource(file, null)
: ScalableImageSource.fromSI(
rootBundle,
asset,
),
fit: fit,
alignment: alignment,
);
Expand Down Expand Up @@ -74,3 +80,38 @@ class SizedScalableImageWidget extends StatelessWidget {
return child;
}
}

class _SIFileSource extends ScalableImageSource {
final File file;
final Color? currentColor;

_SIFileSource(this.file, this.currentColor);

@override
Future<ScalableImage> get si => createSI();

@override
Future<ScalableImage> createSI({bool compact = false}) async {
ScalableImageCompact scalableImageCompact = ScalableImageCompact.fromBytes(file.readAsBytesSync(), currentColor: currentColor);
if (compact) {
return scalableImageCompact;
} else {
return scalableImageCompact.toDag();
}
}

@override
bool operator ==(final Object other) {
if (other is _SIFileSource) {
return file == other.file && currentColor == other.currentColor;
} else {
return false;
}
}

@override
int get hashCode => 0xf67cd716 ^ Object.hash(file, currentColor);

@override
String toString() => '__SIFileSource($file $currentColor)';
}
3 changes: 1 addition & 2 deletions lib/widgets/smart_image.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jovial_svg/jovial_svg.dart';
import 'package:open_authenticator/utils/image_type.dart';
import 'package:open_authenticator/widgets/sized_scalable_image.dart';
Expand Down Expand Up @@ -76,7 +75,7 @@ class SmartImageWidget extends StatelessWidget {
width: width,
height: height,
child: ScalableImageWidget.fromSISource(
si: ScalableImageSource.fromSvg(rootBundle, source),
si: ScalableImageSource.fromSvgFile(file, () => file.readAsString()),
key: imageKey,
fit: fit,
),
Expand Down

0 comments on commit be0cf0c

Please sign in to comment.