From 84f83859f09f0cfd41b4b981bed08f0ce5664284 Mon Sep 17 00:00:00 2001 From: OutdatedGuy Date: Fri, 29 Dec 2023 23:51:34 +0530 Subject: [PATCH] chore: ran build_runner to generate code --- lib/config/config.g.dart | 25 +- lib/ios.dart | 217 +++++++++++++++--- pubspec.yaml | 2 +- test/abs/icon_generator_test.mocks.dart | 6 + .../macos_icon_generator_test.mocks.dart | 7 + test/main_test.dart | 15 +- .../windows_icon_generator_test.mocks.dart | 8 +- 7 files changed, 230 insertions(+), 50 deletions(-) diff --git a/lib/config/config.g.dart b/lib/config/config.g.dart index 5087f1846d..337a9b00ce 100644 --- a/lib/config/config.g.dart +++ b/lib/config/config.g.dart @@ -23,8 +23,9 @@ Config _$ConfigFromJson(Map json) => $checkedCreate( 'image_path_ios_tinted_grayscale', (v) => v as String?), adaptiveIconForeground: $checkedConvert('adaptive_icon_foreground', (v) => v as String?), - adaptiveIconForegroundInset: - $checkedConvert('adaptive_icon_foreground_inset', (v) => v as int? ?? 16), + adaptiveIconForegroundInset: $checkedConvert( + 'adaptive_icon_foreground_inset', + (v) => (v as num?)?.toInt() ?? 16), adaptiveIconBackground: $checkedConvert('adaptive_icon_background', (v) => v as String?), adaptiveIconMonochrome: @@ -41,11 +42,21 @@ Config _$ConfigFromJson(Map json) => $checkedCreate( backgroundColorIOS: $checkedConvert( 'background_color_ios', (v) => v as String? ?? '#ffffff'), webConfig: $checkedConvert( - 'web', (v) => v == null ? null : WebConfig.fromJson(v as Map)), - windowsConfig: $checkedConvert('windows', - (v) => v == null ? null : WindowsConfig.fromJson(v as Map)), - macOSConfig: $checkedConvert('macos', - (v) => v == null ? null : MacOSConfig.fromJson(v as Map)), + 'web', + (v) => v == null + ? null + : WebConfig.fromJson(Map.from(v as Map))), + windowsConfig: $checkedConvert( + 'windows', + (v) => v == null + ? null + : WindowsConfig.fromJson( + Map.from(v as Map))), + macOSConfig: $checkedConvert( + 'macos', + (v) => v == null + ? null + : MacOSConfig.fromJson(Map.from(v as Map))), ); return val; }, diff --git a/lib/ios.dart b/lib/ios.dart index 907e056b31..918317123a 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -132,7 +132,8 @@ void createIcons(Config config, String? flavor) { String iconName; String? darkIconName; String? tintedIconName; - final List generateIosIcons = (darkImage == null && tintedImage == null) ? legacyIosIcons : iosIcons; + final List generateIosIcons = + (darkImage == null && tintedImage == null) ? legacyIosIcons : iosIcons; final dynamic iosConfig = config.ios; if (flavor != null) { final String catalogName = 'AppIcon-$flavor'; @@ -217,10 +218,19 @@ void createIcons(Config config, String? flavor) { /// Note: Do not change interpolation unless you end up with better results (see issue for result when using cubic /// interpolation) /// https://github.com/fluttercommunity/flutter_launcher_icons/issues/101#issuecomment-495528733 -void overwriteDefaultIcons(IosIconTemplate template, Image image, [String iconNameSuffix = '']) { +void overwriteDefaultIcons( + IosIconTemplate template, + Image image, [ + String iconNameSuffix = '', +]) { final Image newFile = createResizedImage(template, image); - File(iosDefaultIconFolder + iosDefaultIconName + iconNameSuffix + template.name + '.png') - ..writeAsBytesSync(encodePng(newFile)); + File( + iosDefaultIconFolder + + iosDefaultIconName + + iconNameSuffix + + template.name + + '.png', + )..writeAsBytesSync(encodePng(newFile)); } /// Note: Do not change interpolation unless you end up with better results (see issue for result when using cubic @@ -290,7 +300,11 @@ Future changeIosLauncherIcon(String iconName, String? flavor) async { } /// Create the Contents.json file -void modifyContentsFile(String newIconName, String? darkIconName, String? tintedIconName) { +void modifyContentsFile( + String newIconName, + String? darkIconName, + String? tintedIconName, +) { final String newIconFolder = iosAssetFolder + newIconName + '.appiconset/Contents.json'; File(newIconFolder).create(recursive: true).then((File contentsJsonFile) { @@ -301,17 +315,25 @@ void modifyContentsFile(String newIconName, String? darkIconName, String? tinted } /// Modify default Contents.json file -void modifyDefaultContentsFile(String newIconName, String? darkIconName, String? tintedIconName) { +void modifyDefaultContentsFile( + String newIconName, + String? darkIconName, + String? tintedIconName, +) { const String newIconFolder = iosAssetFolder + 'AppIcon.appiconset/Contents.json'; File(newIconFolder).create(recursive: true).then((File contentsJsonFile) { final String contentsFileContent = - generateContentsFileAsString(newIconName, darkIconName, tintedIconName); + generateContentsFileAsString(newIconName, darkIconName, tintedIconName); contentsJsonFile.writeAsString(contentsFileContent); }); } -String generateContentsFileAsString(String newIconName, String? darkIconName, String? tintedIconName) { +String generateContentsFileAsString( + String newIconName, + String? darkIconName, + String? tintedIconName, +) { final List> imageList; if (darkIconName == null && tintedIconName == null) { imageList = createLegacyImageList(newIconName); @@ -366,7 +388,8 @@ class ContentsImageObject { 'filename': filename, 'scale': scale, if (platform != null) 'platform': platform, - if (appearances != null) 'appearances': appearances!.map((e) => e.toJson()).toList(), + if (appearances != null) + 'appearances': appearances!.map((e) => e.toJson()).toList(), }; } } @@ -388,19 +411,71 @@ class ContentsInfoObject { /// Create the image list for the Contents.json file for Xcode versions below Xcode 14 List> createLegacyImageList(String fileNamePrefix) { const List> imageConfigurations = [ - {'size': '20x20', 'idiom': 'iphone', 'scales': ['2x', '3x']}, - {'size': '29x29', 'idiom': 'iphone', 'scales': ['1x', '2x', '3x']}, - {'size': '40x40', 'idiom': 'iphone', 'scales': ['2x', '3x']}, - {'size': '57x57', 'idiom': 'iphone', 'scales': ['1x', '2x']}, - {'size': '60x60', 'idiom': 'iphone', 'scales': ['2x', '3x']}, - {'size': '20x20', 'idiom': 'ipad', 'scales': ['1x', '2x']}, - {'size': '29x29', 'idiom': 'ipad', 'scales': ['1x', '2x']}, - {'size': '40x40', 'idiom': 'ipad', 'scales': ['1x', '2x']}, - {'size': '50x50', 'idiom': 'ipad', 'scales': ['1x', '2x']}, - {'size': '72x72', 'idiom': 'ipad', 'scales': ['1x', '2x']}, - {'size': '76x76', 'idiom': 'ipad', 'scales': ['1x', '2x']}, - {'size': '83.5x83.5', 'idiom': 'ipad', 'scales': ['2x']}, - {'size': '1024x1024', 'idiom': 'ios-marketing', 'scales': ['1x']}, + { + 'size': '20x20', + 'idiom': 'iphone', + 'scales': ['2x', '3x'], + }, + { + 'size': '29x29', + 'idiom': 'iphone', + 'scales': ['1x', '2x', '3x'], + }, + { + 'size': '40x40', + 'idiom': 'iphone', + 'scales': ['2x', '3x'], + }, + { + 'size': '57x57', + 'idiom': 'iphone', + 'scales': ['1x', '2x'], + }, + { + 'size': '60x60', + 'idiom': 'iphone', + 'scales': ['2x', '3x'], + }, + { + 'size': '20x20', + 'idiom': 'ipad', + 'scales': ['1x', '2x'], + }, + { + 'size': '29x29', + 'idiom': 'ipad', + 'scales': ['1x', '2x'], + }, + { + 'size': '40x40', + 'idiom': 'ipad', + 'scales': ['1x', '2x'], + }, + { + 'size': '50x50', + 'idiom': 'ipad', + 'scales': ['1x', '2x'], + }, + { + 'size': '72x72', + 'idiom': 'ipad', + 'scales': ['1x', '2x'], + }, + { + 'size': '76x76', + 'idiom': 'ipad', + 'scales': ['1x', '2x'], + }, + { + 'size': '83.5x83.5', + 'idiom': 'ipad', + 'scales': ['2x'], + }, + { + 'size': '1024x1024', + 'idiom': 'ios-marketing', + 'scales': ['1x'], + }, ]; final List> imageList = >[]; @@ -427,19 +502,77 @@ List> createLegacyImageList(String fileNamePrefix) { } /// Create the image list for the Contents.json file for Xcode versions Xcode 14 and above -List> createImageList(String fileNamePrefix, String? darkFileNamePrefix, String? tintedFileNamePrefix) { +List> createImageList( + String fileNamePrefix, + String? darkFileNamePrefix, + String? tintedFileNamePrefix, +) { const List> imageConfigurations = [ - {'size': '20x20', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x', '3x']}, - {'size': '29x29', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x', '3x']}, - {'size': '38x38', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x', '3x']}, - {'size': '40x40', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x', '3x']}, - {'size': '60x60', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x', '3x']}, - {'size': '64x64', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x', '3x']}, - {'size': '68x68', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x']}, - {'size': '76x76', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x']}, - {'size': '83.5x83.5', 'idiom': 'universal', 'platform': 'ios', 'scales': ['2x']}, - {'size': '1024x1024', 'idiom': 'universal', 'platform': 'ios', 'scales': ['1x']}, - {'size': '1024x1024', 'idiom': 'ios-marketing', 'scales': ['1x']}, + { + 'size': '20x20', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x', '3x'], + }, + { + 'size': '29x29', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x', '3x'], + }, + { + 'size': '38x38', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x', '3x'], + }, + { + 'size': '40x40', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x', '3x'], + }, + { + 'size': '60x60', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x', '3x'], + }, + { + 'size': '64x64', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x', '3x'], + }, + { + 'size': '68x68', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x'], + }, + { + 'size': '76x76', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x'], + }, + { + 'size': '83.5x83.5', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['2x'], + }, + { + 'size': '1024x1024', + 'idiom': 'universal', + 'platform': 'ios', + 'scales': ['1x'], + }, + { + 'size': '1024x1024', + 'idiom': 'ios-marketing', + 'scales': ['1x'], + }, ]; final List> imageList = >[]; @@ -467,7 +600,8 @@ List> createImageList(String fileNamePrefix, String? darkFi // Prevent ios-marketing icon from being tinted or dark if (darkFileNamePrefix != null) { - for (final config in imageConfigurations.where((e) => e['idiom'] == 'universal')) { + for (final config + in imageConfigurations.where((e) => e['idiom'] == 'universal')) { final size = config['size']!; final idiom = config['idiom']!; final platform = config['platform']; @@ -483,7 +617,10 @@ List> createImageList(String fileNamePrefix, String? darkFi platform: platform, scale: scale, appearances: [ - ContentsImageAppearanceObject(appearance: 'luminosity', value: 'dark'), + ContentsImageAppearanceObject( + appearance: 'luminosity', + value: 'dark', + ), ], ).toJson(), ); @@ -492,7 +629,8 @@ List> createImageList(String fileNamePrefix, String? darkFi } if (tintedFileNamePrefix != null) { - for (final config in imageConfigurations.where((e) => e['idiom'] == 'universal')) { + for (final config + in imageConfigurations.where((e) => e['idiom'] == 'universal')) { final size = config['size']!; final idiom = config['idiom']!; final platform = config['platform']; @@ -508,7 +646,10 @@ List> createImageList(String fileNamePrefix, String? darkFi platform: platform, scale: scale, appearances: [ - ContentsImageAppearanceObject(appearance: 'luminosity', value: 'tinted'), + ContentsImageAppearanceObject( + appearance: 'luminosity', + value: 'tinted', + ), ], ).toJson(), ); diff --git a/pubspec.yaml b/pubspec.yaml index f35f8462a8..d2c80d45b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: checked_yaml: ^2.0.2 cli_util: ^0.4.0 image: ^4.0.15 - json_annotation: ^4.8.0 + json_annotation: ^4.8.1 path: ^1.8.2 yaml: ^3.1.1 diff --git a/test/abs/icon_generator_test.mocks.dart b/test/abs/icon_generator_test.mocks.dart index 8d60d4b125..3d349591ee 100644 --- a/test/abs/icon_generator_test.mocks.dart +++ b/test/abs/icon_generator_test.mocks.dart @@ -40,6 +40,12 @@ class MockConfig extends _i1.Mock implements _i3.Config { _i1.throwOnMissingStub(this); } + @override + int get adaptiveIconForegroundInset => (super.noSuchMethod( + Invocation.getter(#adaptiveIconForegroundInset), + returnValue: 0, + ) as int); + @override int get minSdkAndroid => (super.noSuchMethod( Invocation.getter(#minSdkAndroid), diff --git a/test/macos/macos_icon_generator_test.mocks.dart b/test/macos/macos_icon_generator_test.mocks.dart index 47b5dc9128..be401029fa 100644 --- a/test/macos/macos_icon_generator_test.mocks.dart +++ b/test/macos/macos_icon_generator_test.mocks.dart @@ -47,6 +47,13 @@ class _FakeProgress_1 extends _i1.SmartFake implements _i2.Progress { /// /// See the documentation for Mockito's code generation for more information. class MockConfig extends _i1.Mock implements _i3.Config { + @override + int get adaptiveIconForegroundInset => (super.noSuchMethod( + Invocation.getter(#adaptiveIconForegroundInset), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + @override int get minSdkAndroid => (super.noSuchMethod( Invocation.getter(#minSdkAndroid), diff --git a/test/main_test.dart b/test/main_test.dart index a2fb25848f..7d0a982262 100644 --- a/test/main_test.dart +++ b/test/main_test.dart @@ -32,19 +32,28 @@ void main() { test( 'iOS image list used to generate Contents.json for icon directory is correct size (with dark icon)', () { - expect(ios.createImageList('blah', 'dark-blah', null).length, 16 * 2 + 1); // 16 normal, 16 dark icons + 1 marketing icon + expect( + ios.createImageList('blah', 'dark-blah', null).length, + 16 * 2 + 1, + ); // 16 normal, 16 dark icons + 1 marketing icon }); test( 'iOS image list used to generate Contents.json for icon directory is correct size (with tinted icon)', () { - expect(ios.createImageList('blah', null, 'tinted-blah').length, 16 * 2 + 1); // 16 normal, 16 tinted icons + 1 marketing icon + expect( + ios.createImageList('blah', null, 'tinted-blah').length, + 16 * 2 + 1, + ); // 16 normal, 16 tinted icons + 1 marketing icon }); test( 'iOS image list used to generate Contents.json for icon directory is correct size (with dark and tinted icon)', () { - expect(ios.createImageList('blah', 'dark-blah', 'tinted-blah').length, 16 * 3 + 1); // 16 normal, 16 dark, 16 tinted icons + 1 marketing icon + expect( + ios.createImageList('blah', 'dark-blah', 'tinted-blah').length, + 16 * 3 + 1, + ); // 16 normal, 16 dark, 16 tinted icons + 1 marketing icon }); group('config file from args', () { diff --git a/test/windows/windows_icon_generator_test.mocks.dart b/test/windows/windows_icon_generator_test.mocks.dart index cb96f9d5c4..17ed3f784f 100644 --- a/test/windows/windows_icon_generator_test.mocks.dart +++ b/test/windows/windows_icon_generator_test.mocks.dart @@ -51,6 +51,12 @@ class MockConfig extends _i1.Mock implements _i3.Config { _i1.throwOnMissingStub(this); } + @override + int get adaptiveIconForegroundInset => (super.noSuchMethod( + Invocation.getter(#adaptiveIconForegroundInset), + returnValue: 0, + ) as int); + @override int get minSdkAndroid => (super.noSuchMethod( Invocation.getter(#minSdkAndroid), @@ -162,7 +168,7 @@ class MockWindowsConfig extends _i1.Mock implements _i5.WindowsConfig { #toJson, [], ), - returnValue: {}, + returnValue: {}, ) as Map); }