m3_lightmeter/screenshots/models/screenshot_args.dart

61 lines
2 KiB
Dart
Raw Normal View History

2024-05-11 12:59:28 +00:00
import 'dart:convert';
class ScreenshotArgs {
final String name;
final String deviceName;
final String platformFolder;
2024-05-15 19:47:03 +00:00
final String backgroundColor;
2024-05-11 12:59:28 +00:00
final bool isDark;
2024-05-15 19:47:03 +00:00
static const _pathArgsDelimited = '_';
ScreenshotArgs({
2024-05-11 12:59:28 +00:00
required this.name,
2024-05-15 19:47:03 +00:00
required String deviceName,
2024-05-11 12:59:28 +00:00
required this.platformFolder,
required this.backgroundColor,
required this.isDark,
2024-05-15 20:14:28 +00:00
}) : deviceName = deviceName.replaceAll(' ', _pathArgsDelimited).replaceAll(RegExp('[(|)]'), '').toLowerCase();
2024-05-15 19:47:03 +00:00
ScreenshotArgs.fromRawName({
required String name,
required String deviceName,
required this.platformFolder,
}) : name = name.split(_pathArgsDelimited)[1],
2024-05-15 20:14:28 +00:00
deviceName = deviceName.replaceAll(' ', _pathArgsDelimited).replaceAll(RegExp('[(|)]'), '').toLowerCase(),
2024-05-15 19:47:03 +00:00
backgroundColor = name.split(_pathArgsDelimited)[2],
isDark = name.contains('dark');
static const _folderPrefix = 'screenshots/generated';
String get nameWithTheme => '${isDark ? 'dark' : 'light'}$_pathArgsDelimited$name';
2024-05-11 12:59:28 +00:00
2024-05-15 19:47:03 +00:00
String toPathRaw() =>
'$_folderPrefix/raw/$platformFolder/$deviceName/$nameWithTheme$_pathArgsDelimited$backgroundColor.png';
2024-05-17 09:01:44 +00:00
String toPath(String layoutName) => '$_folderPrefix/$platformFolder/$layoutName/$nameWithTheme.png';
2024-05-11 12:59:28 +00:00
@override
String toString() => jsonEncode(_toJson());
factory ScreenshotArgs.fromString(String data) => ScreenshotArgs._fromJson(jsonDecode(data) as Map<String, dynamic>);
factory ScreenshotArgs._fromJson(Map<String, dynamic> data) {
return ScreenshotArgs(
name: data['name'] as String,
deviceName: data['deviceName'] as String,
platformFolder: data['platformFolder'] as String,
2024-05-15 19:47:03 +00:00
backgroundColor: data['backgroundColor'] as String,
2024-05-11 12:59:28 +00:00
isDark: data['isDark'] as bool,
);
}
Map<String, dynamic> _toJson() {
return {
"name": name,
"deviceName": deviceName,
"platformFolder": platformFolder,
2024-05-15 19:47:03 +00:00
"backgroundColor": backgroundColor,
2024-05-11 12:59:28 +00:00
"isDark": isDark,
};
}
}