Skip to content

Commit

Permalink
chore: Made SizedScalableImageWidget only supporting project assets…
Browse files Browse the repository at this point in the history
…, not files.
  • Loading branch information
Skyost committed Oct 24, 2024
1 parent 37a0057 commit 9f60f63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
16 changes: 4 additions & 12 deletions lib/utils/jovial_svg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ class JovialSvgUtils {
}
return false;
}

/// Loads an SI graphic from a file or from an asset.
static ScalableImageSource siFromFileOrAsset(String source) {
File file = File(source);
return file.existsSync()
? SIFileSource(file, null)
: ScalableImageSource.fromSI(
rootBundle,
source,
);
}
}

/// Allows to load a SI image from a file.
Expand All @@ -49,7 +38,10 @@ class SIFileSource extends ScalableImageSource {
final Color? currentColor;

/// Creates a new SI file source instance.
SIFileSource(this.file, this.currentColor);
SIFileSource({
required this.file,
this.currentColor,
});

@override
Future<ScalableImage> get si => createSI();
Expand Down
7 changes: 5 additions & 2 deletions lib/widgets/sized_scalable_image.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jovial_svg/jovial_svg.dart';
import 'package:open_authenticator/utils/jovial_svg.dart';

/// A sized scalable image widget.
class SizedScalableImageWidget extends StatelessWidget {
Expand Down Expand Up @@ -40,7 +40,10 @@ class SizedScalableImageWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget child = ScalableImageWidget.fromSISource(
si: JovialSvgUtils.siFromFileOrAsset(asset),
si: ScalableImageSource.fromSI(
rootBundle,
asset,
),
fit: fit,
alignment: alignment,
);
Expand Down
12 changes: 7 additions & 5 deletions lib/widgets/smart_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:io';
import 'package:flutter/material.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';
import 'package:open_authenticator/utils/jovial_svg.dart';

/// Displays a classic image or a vector image.
class SmartImageWidget extends StatelessWidget {
Expand Down Expand Up @@ -80,12 +80,14 @@ class SmartImageWidget extends StatelessWidget {
fit: fit,
),
),
ImageType.si => SizedScalableImageWidget(
ImageType.si => SizedBox(
width: width,
height: height,
asset: source,
key: imageKey,
fit: fit,
child: ScalableImageWidget.fromSISource(
si: SIFileSource(file: file),
key: imageKey,
fit: fit,
),
),
ImageType.other => Image.file(
file,
Expand Down

0 comments on commit 9f60f63

Please sign in to comment.