Skip to content

Commit

Permalink
chore: ran build_runner to generate code
Browse files Browse the repository at this point in the history
  • Loading branch information
OutdatedGuy committed Sep 21, 2024
1 parent b01f601 commit 84f8385
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 50 deletions.
25 changes: 18 additions & 7 deletions lib/config/config.g.dart

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

217 changes: 179 additions & 38 deletions lib/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ void createIcons(Config config, String? flavor) {
String iconName;
String? darkIconName;
String? tintedIconName;
final List<IosIconTemplate> generateIosIcons = (darkImage == null && tintedImage == null) ? legacyIosIcons : iosIcons;
final List<IosIconTemplate> generateIosIcons =
(darkImage == null && tintedImage == null) ? legacyIosIcons : iosIcons;
final dynamic iosConfig = config.ios;
if (flavor != null) {
final String catalogName = 'AppIcon-$flavor';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -290,7 +300,11 @@ Future<void> 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) {
Expand All @@ -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<Map<String, dynamic>> imageList;
if (darkIconName == null && tintedIconName == null) {
imageList = createLegacyImageList(newIconName);
Expand Down Expand Up @@ -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(),
};
}
}
Expand All @@ -388,19 +411,71 @@ class ContentsInfoObject {
/// Create the image list for the Contents.json file for Xcode versions below Xcode 14
List<Map<String, dynamic>> createLegacyImageList(String fileNamePrefix) {
const List<Map<String, dynamic>> 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<Map<String, dynamic>> imageList = <Map<String, dynamic>>[];
Expand All @@ -427,19 +502,77 @@ List<Map<String, dynamic>> createLegacyImageList(String fileNamePrefix) {
}

/// Create the image list for the Contents.json file for Xcode versions Xcode 14 and above
List<Map<String, dynamic>> createImageList(String fileNamePrefix, String? darkFileNamePrefix, String? tintedFileNamePrefix) {
List<Map<String, dynamic>> createImageList(
String fileNamePrefix,
String? darkFileNamePrefix,
String? tintedFileNamePrefix,
) {
const List<Map<String, dynamic>> 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<Map<String, dynamic>> imageList = <Map<String, dynamic>>[];
Expand Down Expand Up @@ -467,7 +600,8 @@ List<Map<String, dynamic>> 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'];
Expand All @@ -483,7 +617,10 @@ List<Map<String, dynamic>> createImageList(String fileNamePrefix, String? darkFi
platform: platform,
scale: scale,
appearances: <ContentsImageAppearanceObject>[
ContentsImageAppearanceObject(appearance: 'luminosity', value: 'dark'),
ContentsImageAppearanceObject(
appearance: 'luminosity',
value: 'dark',
),
],
).toJson(),
);
Expand All @@ -492,7 +629,8 @@ List<Map<String, dynamic>> 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'];
Expand All @@ -508,7 +646,10 @@ List<Map<String, dynamic>> createImageList(String fileNamePrefix, String? darkFi
platform: platform,
scale: scale,
appearances: <ContentsImageAppearanceObject>[
ContentsImageAppearanceObject(appearance: 'luminosity', value: 'tinted'),
ContentsImageAppearanceObject(
appearance: 'luminosity',
value: 'tinted',
),
],
).toJson(),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions test/abs/icon_generator_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions test/macos/macos_icon_generator_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading

0 comments on commit 84f8385

Please sign in to comment.