Skip to content

Commit

Permalink
support ios background color when removing alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoCherHong committed Jan 18, 2023
1 parent 9a48d68 commit 397ca81
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/flutter_launcher_icons_config.dart
Expand Up @@ -50,6 +50,10 @@ class FlutterLauncherIconsConfig {
@JsonKey(name: 'remove_alpha_ios')
final bool removeAlphaIOS;

/// IOS background_color_ios
@JsonKey(name: 'background_color_ios')
final String backgroundColorIOS;

/// Web platform config
@JsonKey(name: 'web')
final WebConfig? webConfig;
Expand All @@ -73,6 +77,7 @@ class FlutterLauncherIconsConfig {
this.adaptiveIconBackground,
this.minSdkAndroid = constants.androidDefaultAndroidMinSDK,
this.removeAlphaIOS = false,
this.backgroundColorIOS = '#ffffff',
this.webConfig,
this.windowsConfig,
this.macOSConfig,
Expand Down
4 changes: 4 additions & 0 deletions lib/flutter_launcher_icons_config.g.dart

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

10 changes: 10 additions & 0 deletions lib/ios.dart
Expand Up @@ -52,7 +52,17 @@ void createIcons(FlutterLauncherIconsConfig config, String? flavor) {
return;
}
if (config.removeAlphaIOS) {
final backgroundColorHex = config.backgroundColorIOS.startsWith('#') ? config.backgroundColorIOS.substring(1) : config.backgroundColorIOS;
if (backgroundColorHex.length != 6) {
throw Exception('background_color_ios hex should be 6 characters long');
}
final backgroundByte = int.parse(backgroundColorHex, radix: 16);
final data = image.data;
for (var i = 0; i < data.length; i++) {
data[i] = alphaBlendColors(backgroundByte, data[i]);
}
image.channels = Channels.rgb;

}
if (image.channels == Channels.rgba) {
print(
Expand Down
5 changes: 5 additions & 0 deletions test/abs/icon_generator_test.mocks.dart
Expand Up @@ -50,6 +50,11 @@ class MockFlutterLauncherIconsConfig extends _i1.Mock
returnValue: false,
) as bool);
@override
String get backgroundColorIOS => (super.noSuchMethod(
Invocation.getter(#backgroundColorIOS),
returnValue: '',
) as String);
@override
bool get hasAndroidAdaptiveConfig => (super.noSuchMethod(
Invocation.getter(#hasAndroidAdaptiveConfig),
returnValue: false,
Expand Down
6 changes: 6 additions & 0 deletions test/macos/macos_icon_generator_test.mocks.dart
Expand Up @@ -58,6 +58,12 @@ class MockFlutterLauncherIconsConfig extends _i1.Mock
returnValueForMissingStub: false,
) as bool);
@override
String get backgroundColorIOS => (super.noSuchMethod(
Invocation.getter(#backgroundColorIOS),
returnValue: '',
returnValueForMissingStub: '',
) as String);
@override
bool get hasAndroidAdaptiveConfig => (super.noSuchMethod(
Invocation.getter(#hasAndroidAdaptiveConfig),
returnValue: false,
Expand Down
5 changes: 5 additions & 0 deletions test/windows/windows_icon_generator_test.mocks.dart
Expand Up @@ -60,6 +60,11 @@ class MockFlutterLauncherIconsConfig extends _i1.Mock
returnValue: false,
) as bool);
@override
String get backgroundColorIOS => (super.noSuchMethod(
Invocation.getter(#backgroundColorIOS),
returnValue: '',
) as String);
@override
bool get hasAndroidAdaptiveConfig => (super.noSuchMethod(
Invocation.getter(#hasAndroidAdaptiveConfig),
returnValue: false,
Expand Down

0 comments on commit 397ca81

Please sign in to comment.