diff --git a/screenshots/assets/content/screenshot_titles_en.json b/screenshots/assets/content/screenshot_titles_en.json index 710944d..b983b7d 100644 --- a/screenshots/assets/content/screenshot_titles_en.json +++ b/screenshots/assets/content/screenshot_titles_en.json @@ -1,27 +1,27 @@ { "screenshots": [ { - "screenshotName": "light-metering_reflected", + "screenshotName": "light_metering-reflected", "title": "Quick & easy to use", "subtitle": "with all the necessary controls\nunder your thumb" }, { - "screenshotName": "light-metering_iso_picker", + "screenshotName": "light_metering-iso-picker", "title": "Lots of ISO values", "subtitle": "From 3 and up to 6400" }, { - "screenshotName": "light-settings", + "screenshotName": "light_settings", "title": "Useful settings", "subtitle": "to get the most accurate\nmetering results" }, { - "screenshotName": "light-equipment_profiles", + "screenshotName": "light_equipment-profiles", "title": "Create multiple profiles", "subtitle": "to match your\ncamera & lens setups" }, { - "screenshotName": "dark-metering_reflected", + "screenshotName": "dark_metering-reflected", "title": "Matches your style", "subtitle": "with various theme types and colors" } diff --git a/screenshots/convert_to_store_screenshot.dart b/screenshots/convert_to_store_screenshot.dart index 09949ba..1362973 100644 --- a/screenshots/convert_to_store_screenshot.dart +++ b/screenshots/convert_to_store_screenshot.dart @@ -14,7 +14,7 @@ extension ScreenshotImage on Image { required ScreenshotArgs args, required ScreenshotLayout layout, }) { - if (_configs[args.name] == null) { + if (_configs[args.nameWithTheme] == null) { return this; } return _addSystemOverlay( @@ -23,17 +23,12 @@ extension ScreenshotImage on Image { ) ._addDeviceFrame( screenshotDevices[args.deviceName]!, - ColorRgba8( - args.backgroundColor.r, - args.backgroundColor.g, - args.backgroundColor.b, - args.backgroundColor.a, - ), + args.backgroundColor, ) ._applyLayout( layout, - _configs[args.name]!.title, - _configs[args.name]!.subtitle, + _configs[args.nameWithTheme]!.title, + _configs[args.nameWithTheme]!.subtitle, isDark: args.isDark, ); } @@ -47,7 +42,13 @@ extension ScreenshotImage on Image { return compositeImage(this, statusBar); } - Image _addDeviceFrame(ScreenshotDevice device, Color backgroundColor) { + Image _addDeviceFrame(ScreenshotDevice device, String color) { + final backgroundColor = ColorRgba8( + int.parse(color.substring(2, 4), radix: 16), + int.parse(color.substring(4, 6), radix: 16), + int.parse(color.substring(6, 8), radix: 16), + int.parse(color.substring(0, 2), radix: 16), + ); final screenshotRounded = copyCrop( this, x: 0, diff --git a/screenshots/generate_screenshots.dart b/screenshots/generate_screenshots.dart index f47e285..d4a03c5 100644 --- a/screenshots/generate_screenshots.dart +++ b/screenshots/generate_screenshots.dart @@ -81,36 +81,36 @@ void main() { ); await tester.takePhoto(); - await tester.takeScreenshot(binding, 'light-metering_reflected'); + await tester.takeScreenshotLight(binding, 'metering-reflected'); if (Platform.isAndroid) { await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor)); await tester.pumpAndSettle(); await tester.toggleIncidentMetering(7.3); - await tester.takeScreenshot(binding, 'light-metering_incident'); + await tester.takeScreenshotLight(binding, 'metering-incident'); } await tester.openAnimatedPicker(); - await tester.takeScreenshot(binding, 'light-metering_iso_picker'); + await tester.takeScreenshotLight(binding, 'metering-iso-picker'); await tester.tapCancelButton(); await tester.tap(find.byTooltip(S.current.tooltipOpenSettings)); await tester.pumpAndSettle(); - await tester.takeScreenshot(binding, 'light-settings'); + await tester.takeScreenshotLight(binding, 'settings'); await tester.tapDescendantTextOf(S.current.meteringScreenLayout); - await tester.takeScreenshot(binding, 'light-settings_metering_screen_layout'); + await tester.takeScreenshotLight(binding, 'settings-metering-screen-layout'); await tester.tapCancelButton(); await tester.tapDescendantTextOf(S.current.equipmentProfiles); await tester.pumpAndSettle(); await tester.tapDescendantTextOf(mockEquipmentProfiles.first.name); await tester.pumpAndSettle(); - await tester.takeScreenshot(binding, 'light-equipment_profiles'); + await tester.takeScreenshotLight(binding, 'equipment-profiles'); await tester.tap(find.byIcon(Icons.iso).first); await tester.pumpAndSettle(); - await tester.takeScreenshot(binding, 'light-equipment_profiles_iso_picker'); + await tester.takeScreenshotLight(binding, 'equipment-profiles-iso-picker'); }); /// and the additionally the first one with the dark theme @@ -125,13 +125,13 @@ void main() { ); await tester.takePhoto(); - await tester.takeScreenshot(binding, 'dark-metering_reflected'); + await tester.takeScreenshotDark(binding, 'metering-reflected'); if (Platform.isAndroid) { await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor)); await tester.pumpAndSettle(); await tester.toggleIncidentMetering(7.3); - await tester.takeScreenshot(binding, 'dark-metering_incident'); + await tester.takeScreenshotDark(binding, 'metering-incident'); } }, ); @@ -140,21 +140,20 @@ void main() { final String _platformFolder = Platform.isAndroid ? 'android' : 'ios'; extension on WidgetTester { - Future takeScreenshot(IntegrationTestWidgetsFlutterBinding binding, String name) async { - final bool isDark = name.contains('dark-'); - final Color backgroundColor = (isDark ? _themeDark : _themeLight).colorScheme.surface; + Future takeScreenshotLight(IntegrationTestWidgetsFlutterBinding binding, String name) => + _takeScreenshot(binding, name, _themeLight); + Future takeScreenshotDark(IntegrationTestWidgetsFlutterBinding binding, String name) => + _takeScreenshot(binding, name, _themeDark); + + Future _takeScreenshot(IntegrationTestWidgetsFlutterBinding binding, String name, ThemeData theme) async { + final Color backgroundColor = theme.colorScheme.surface; await binding.takeScreenshot( ScreenshotArgs( name: name, - deviceName: const String.fromEnvironment('deviceName').replaceAll(' ', '_').toLowerCase(), + deviceName: const String.fromEnvironment('deviceName'), platformFolder: _platformFolder, - backgroundColor: ( - r: backgroundColor.red, - g: backgroundColor.green, - b: backgroundColor.blue, - a: backgroundColor.alpha, - ), - isDark: isDark, + backgroundColor: backgroundColor.value.toRadixString(16), + isDark: theme.brightness == Brightness.dark, ).toString(), ); await pumpAndSettle(); diff --git a/screenshots/main.dart b/screenshots/main.dart index c27c647..5ffa2a0 100644 --- a/screenshots/main.dart +++ b/screenshots/main.dart @@ -31,23 +31,15 @@ Future main(List args) async { final screenshotName = filePath.path.split('/').last.replaceAll('.png', ''); final screenshotBytes = File(filePath.path).readAsBytesSync(); final screenshot = decodePng(Uint8List.fromList(screenshotBytes))!; - final topLeftPixel = screenshot.getPixel(0, 0); - final screenshotArgs = ScreenshotArgs( + final screenshotArgs = ScreenshotArgs.fromRawName( name: screenshotName, deviceName: device, platformFolder: platform, - backgroundColor: ( - r: topLeftPixel.r.toInt(), - g: topLeftPixel.g.toInt(), - b: topLeftPixel.b.toInt(), - a: topLeftPixel.a.toInt(), - ), - isDark: filePath.path.contains('dark-'), ); final file = - await File('screenshots/generated/$platform/${layout.name}/$screenshotName.png').create(recursive: true); + await File('screenshots/generated/$platform/${layout.name}/${screenshotArgs.name}.png').create(recursive: true); file.writeAsBytesSync( encodePng( screenshot.convertToStoreScreenshot( diff --git a/screenshots/models/screenshot_args.dart b/screenshots/models/screenshot_args.dart index 96d779d..50307f8 100644 --- a/screenshots/models/screenshot_args.dart +++ b/screenshots/models/screenshot_args.dart @@ -4,19 +4,34 @@ class ScreenshotArgs { final String name; final String deviceName; final String platformFolder; - final ({int r, int g, int b, int a}) backgroundColor; + final String backgroundColor; final bool isDark; - const ScreenshotArgs({ + static const _pathArgsDelimited = '_'; + + ScreenshotArgs({ required this.name, - required this.deviceName, + required String deviceName, required this.platformFolder, required this.backgroundColor, required this.isDark, - }); + }) : deviceName = deviceName.replaceAll(' ', _pathArgsDelimited).toLowerCase(); - String toPathRaw() => 'screenshots/generated/raw/$platformFolder/$deviceName/$name.png'; - String toPath() => 'screenshots/generated/$platformFolder/$deviceName/$name.png'; + ScreenshotArgs.fromRawName({ + required String name, + required String deviceName, + required this.platformFolder, + }) : name = name.split(_pathArgsDelimited)[1], + deviceName = deviceName.replaceAll(' ', _pathArgsDelimited).toLowerCase(), + backgroundColor = name.split(_pathArgsDelimited)[2], + isDark = name.contains('dark'); + + static const _folderPrefix = 'screenshots/generated'; + String get nameWithTheme => '${isDark ? 'dark' : 'light'}$_pathArgsDelimited$name'; + + String toPathRaw() => + '$_folderPrefix/raw/$platformFolder/$deviceName/$nameWithTheme$_pathArgsDelimited$backgroundColor.png'; + String toPath() => '$_folderPrefix/$platformFolder/$deviceName/$name.png'; @override String toString() => jsonEncode(_toJson()); @@ -24,17 +39,11 @@ class ScreenshotArgs { factory ScreenshotArgs.fromString(String data) => ScreenshotArgs._fromJson(jsonDecode(data) as Map); factory ScreenshotArgs._fromJson(Map data) { - final colorChannels = data['backgroundColor'] as List; return ScreenshotArgs( name: data['name'] as String, deviceName: data['deviceName'] as String, platformFolder: data['platformFolder'] as String, - backgroundColor: ( - r: colorChannels[0] as int, - g: colorChannels[1] as int, - b: colorChannels[2] as int, - a: colorChannels[3] as int, - ), + backgroundColor: data['backgroundColor'] as String, isDark: data['isDark'] as bool, ); } @@ -44,12 +53,7 @@ class ScreenshotArgs { "name": name, "deviceName": deviceName, "platformFolder": platformFolder, - "backgroundColor": [ - backgroundColor.r, - backgroundColor.g, - backgroundColor.b, - backgroundColor.a, - ], + "backgroundColor": backgroundColor, "isDark": isDark, }; }