Skip to content

Commit

Permalink
related to [issue #96], Suggestion for an easier way to apply foregro…
Browse files Browse the repository at this point in the history
…und inset (#563)

* add adaptive icon foreground inset

* update README (added )

* add monochrome icons inset
  • Loading branch information
LOCKEDFILE authored Sep 21, 2024
1 parent 93a697f commit 8cf8aef
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Shown below is the full list of attributes which you can specify within your Flu
be used to fill out the background of the adaptive icon.
- `adaptive_icon_foreground`: The image asset which will be used for the icon foreground of the adaptive icon
*Note: Adaptive Icons will only be generated when both adaptive_icon_background and adaptive_icon_foreground are specified. (the image_path is not automatically taken as foreground)*
- `adaptive_icon_foreground_inset`: This is used to add padding to the icon when applying an adaptive icon. The default value is `16`.
- `adaptive_icon_monochrome`: The image asset which will be used for the icon
foreground of the Android 13+ themed icon. For more information see [Android Adaptive Icons](https://developer.android.com/develop/ui/views/launch/icon_design_adaptive#user-theming)

Expand Down
1 change: 1 addition & 0 deletions example/default_example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ flutter_launcher_icons:
ios: true # can specify file name here e.g. "My-Launcher-Icon"
adaptive_icon_background: "assets/images/christmas-background.png" # only available for Android 8.0 devices and above
adaptive_icon_foreground: "assets/images/icon-foreground-432x432.png" # only available for Android 8.0 devices and above
adaptive_icon_foreground_inset: 16 # only available for Android 8.0 devices and above
adaptive_icon_monochrome: "assets/images/icon-monochrome-432x432.png" # only available for Android 13 devices and above
min_sdk_android: 21 # android min sdk min:16, default 21
remove_alpha_ios: true
Expand Down
18 changes: 14 additions & 4 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,23 @@ void createMipmapXmlFile(
' <background android:drawable="@color/ic_launcher_background"/>\n';
}

xmlContent +=
' <foreground android:drawable="@drawable/ic_launcher_foreground"/>\n';
xmlContent += '''
<foreground>
<inset
android:drawable="@drawable/ic_launcher_foreground"
android:inset="${config.adaptiveIconForegroundInset}%" />
</foreground>
''';
}

if (config.hasAndroidAdaptiveMonochromeConfig) {
xmlContent +=
' <monochrome android:drawable="@drawable/ic_launcher_monochrome"/>\n';
xmlContent += '''
<monochrome>
<inset
android:drawable="@drawable/ic_launcher_monochrome"
android:inset="${config.adaptiveIconForegroundInset}%" />
</monochrome>
''';
}

late File mipmapXmlFile;
Expand Down
5 changes: 5 additions & 0 deletions lib/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Config {
this.imagePathIOSDarkTransparent,
this.imagePathIOSTintedGrayscale,
this.adaptiveIconForeground,
this.adaptiveIconForegroundInset = 16,
this.adaptiveIconBackground,
this.adaptiveIconMonochrome,
this.minSdkAndroid = constants.androidDefaultAndroidMinSDK,
Expand Down Expand Up @@ -132,6 +133,10 @@ class Config {
@JsonKey(name: 'adaptive_icon_foreground')
final String? adaptiveIconForeground;

/// android adaptive_icon_foreground inset
@JsonKey(name: 'adaptive_icon_foreground_inset')
final int adaptiveIconForegroundInset;

/// android adaptive_icon_background image
@JsonKey(name: 'adaptive_icon_background')
final String? adaptiveIconBackground;
Expand Down
4 changes: 4 additions & 0 deletions lib/config/config.g.dart

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

0 comments on commit 8cf8aef

Please sign in to comment.