Skip to content

Commit

Permalink
customizer edits
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Nov 21, 2024
1 parent 9a9961c commit 19cd146
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/model/extensions/enums/image_file_type_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension ImageFileTypeX on ImageFileType {

String get fileExtension => toString().split('.').last;

String get fileName => switch (this) {
String get fileType => switch (this) {
ImageFileType.svg => 'Scalable Vector Graphic',
ImageFileType.svgz => 'Scalable Vector Graphic (compressed)',
ImageFileType.png => 'PNG',
Expand All @@ -81,7 +81,7 @@ extension ImageFileTypeX on ImageFileType {
};

/// Builds an [XFile] from the given [imageData] and [fileName].
/// The [fileName] is used as the name of the file.
/// The [fileType] is used as the name of the file.
/// The file extension is determined by the [ImageFileType].
XFile buildXFile(Uint8List imageData, String fileName) => XFile.fromData(imageData, name: "$fileName.$fileExtension");
}
10 changes: 7 additions & 3 deletions lib/model/widget_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ class Uint8ListConverter implements JsonConverter<Uint8List, String> {
class WidgetImage {
final ImageFileType fileType;
final Uint8List imageData;
final String fileName;

String get fullFileName => '$fileName.${fileType.fileType}';

WidgetImage({
required this.fileType,
required this.imageData,
required this.fileName,
});

@override
Expand All @@ -73,15 +77,15 @@ class WidgetImage {
try {
return fileType.buildImageWidget(imageData);
} catch (e) {
Logger.error('Image is not an ${fileType.fileName}, or the image data is corrupted.', error: e);
Logger.error('Image is not an ${fileType.fileType}, or the image data is corrupted.', error: e);
rethrow;
}
}

factory WidgetImage.fromJson(Map<String, dynamic> json) => _$WidgetImageFromJson(json);
Map<String, dynamic> toJson() => _$WidgetImageToJson(this);

XFile? toXFile(String? fileName) {
return fileType.buildXFile(imageData, fileName ?? 'image-${DateTime.now().millisecondsSinceEpoch}');
XFile? toXFile() {
return fileType.buildXFile(imageData, fileName);
}
}
2 changes: 2 additions & 0 deletions lib/model/widget_image.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/utils/customization/application_customization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class ApplicationCustomization {
this.lightTheme = ThemeCustomization.defaultLightTheme,
this.darkTheme = ThemeCustomization.defaultDarkTheme,
this.disabledFeatures = const {},
}) : appIcon = appIcon ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultIconUint8List),
appImage = appImage ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultImageUint8List);
}) : appIcon = appIcon ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultIconUint8List, fileName: 'appIcon'),
appImage = appImage ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultImageUint8List, fileName: 'appImage');

ApplicationCustomization copyWith({
String? appName,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ void _testAppCustomizer() {
appIcon: WidgetImage(
fileType: ImageFileType.png,
imageData: defaultIconUint8List,
fileName: "appIcon",
),
appImage: WidgetImage(
fileType: ImageFileType.png,
imageData: defaultImageUint8List,
fileName: "appImage",
),
lightTheme: ApplicationCustomization.defaultCustomization.lightTheme,
darkTheme: ApplicationCustomization.defaultCustomization.darkTheme,
Expand Down Expand Up @@ -51,10 +53,12 @@ void _testAppCustomizer() {
appIcon: WidgetImage(
fileType: ImageFileType.png,
imageData: defaultImageUint8List,
fileName: "appIcon",
),
appImage: WidgetImage(
fileType: ImageFileType.png,
imageData: defaultIconUint8List,
fileName: "appImage",
),
lightTheme: ApplicationCustomization.defaultCustomization.darkTheme,
darkTheme: ApplicationCustomization.defaultCustomization.lightTheme,
Expand Down

0 comments on commit 19cd146

Please sign in to comment.