11import 'dart:io' ;
2+ import 'package:flutter_launcher_icons/constants.dart' ;
3+ import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart' ;
24import 'package:flutter_launcher_icons/utils.dart' ;
35import 'package:flutter_launcher_icons/xml_templates.dart' as xml_template;
46import 'package:image/image.dart' ;
@@ -29,17 +31,21 @@ List<AndroidIconTemplate> androidIcons = <AndroidIconTemplate>[
2931 AndroidIconTemplate (directoryName: 'mipmap-xxxhdpi' , size: 192 ),
3032];
3133
32- void createDefaultIcons (Map < String , dynamic > flutterLauncherIconsConfig, String ? flavor) {
34+ void createDefaultIcons (FlutterLauncherIconsConfig flutterLauncherIconsConfig, String ? flavor) {
3335 printStatus ('Creating default icons Android' );
34- final String filePath = getAndroidIconPath (flutterLauncherIconsConfig);
36+ // todo: support prefixPath
37+ final String ? filePath = flutterLauncherIconsConfig.getImagePathAndroid ();
38+ if (filePath == null ) {
39+ throw const InvalidConfigException (errorMissingImagePath);
40+ }
3541 final Image ? image = decodeImageFile (filePath);
3642 if (image == null ) {
3743 return ;
3844 }
3945 final File androidManifestFile = File (constants.androidManifestFile);
40- if (isCustomAndroidFile ( flutterLauncherIconsConfig) ) {
46+ if (flutterLauncherIconsConfig.isCustomAndroidFile ) {
4147 printStatus ('Adding a new Android launcher icon' );
42- final String iconName = getNewIconName ( flutterLauncherIconsConfig) ;
48+ final String iconName = flutterLauncherIconsConfig.android ;
4349 isAndroidIconNameCorrectFormat (iconName);
4450 final String iconPath = '$iconName .png' ;
4551 for (AndroidIconTemplate template in androidIcons) {
@@ -64,12 +70,15 @@ bool isAndroidIconNameCorrectFormat(String iconName) {
6470 return true ;
6571}
6672
67- void createAdaptiveIcons (Map < String , dynamic > flutterLauncherIconsConfig, String ? flavor) {
73+ void createAdaptiveIcons (FlutterLauncherIconsConfig flutterLauncherIconsConfig, String ? flavor) {
6874 printStatus ('Creating adaptive icons Android' );
6975
7076 // Retrieve the necessary Flutter Launcher Icons configuration from the pubspec.yaml file
71- final String backgroundConfig = flutterLauncherIconsConfig['adaptive_icon_background' ];
72- final String foregroundImagePath = flutterLauncherIconsConfig['adaptive_icon_foreground' ];
77+ final String ? backgroundConfig = flutterLauncherIconsConfig.adaptiveIconBackground;
78+ final String ? foregroundImagePath = flutterLauncherIconsConfig.adaptiveIconForeground;
79+ if (backgroundConfig == null || foregroundImagePath == null ) {
80+ throw const InvalidConfigException (errorMissingImagePath);
81+ }
7382 final Image ? foregroundImage = decodeImageFile (foregroundImagePath);
7483 if (foregroundImage == null ) {
7584 return ;
@@ -110,9 +119,9 @@ void updateColorsXmlFile(String backgroundConfig, String? flavor) {
110119
111120/// Creates the xml file required for the adaptive launcher icon
112121/// FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml
113- void createAdaptiveIconMipmapXmlFile (Map < String , dynamic > flutterLauncherIconsConfig, String ? flavor) {
114- if (isCustomAndroidFile ( flutterLauncherIconsConfig) ) {
115- File (constants.androidAdaptiveXmlFolder (flavor) + getNewIconName ( flutterLauncherIconsConfig) + '.xml' )
122+ void createAdaptiveIconMipmapXmlFile (FlutterLauncherIconsConfig flutterLauncherIconsConfig, String ? flavor) {
123+ if (flutterLauncherIconsConfig.isCustomAndroidFile ) {
124+ File (constants.androidAdaptiveXmlFolder (flavor) + flutterLauncherIconsConfig.android + '.xml' )
116125 .create (recursive: true )
117126 .then ((File adaptiveIcon) {
118127 adaptiveIcon.writeAsString (xml_template.icLauncherXml);
@@ -128,7 +137,7 @@ void createAdaptiveIconMipmapXmlFile(Map<String, dynamic> flutterLauncherIconsCo
128137
129138/// creates adaptive background using png image
130139void _createAdaptiveBackgrounds (
131- Map < String , dynamic > yamlConfig ,
140+ FlutterLauncherIconsConfig flutterLauncherIconsConfig ,
132141 String adaptiveIconBackgroundImagePath,
133142 String ? flavor,
134143) {
@@ -146,8 +155,8 @@ void _createAdaptiveBackgrounds(
146155
147156 // Creates the xml file required for the adaptive launcher icon
148157 // FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml
149- if (isCustomAndroidFile (yamlConfig) ) {
150- File (constants.androidAdaptiveXmlFolder (flavor) + getNewIconName (yamlConfig) + '.xml' )
158+ if (flutterLauncherIconsConfig. isCustomAndroidFile) {
159+ File (constants.androidAdaptiveXmlFolder (flavor) + flutterLauncherIconsConfig.android + '.xml' )
151160 .create (recursive: true )
152161 .then ((File adaptiveIcon) {
153162 adaptiveIcon.writeAsString (xml_template.icLauncherDrawableBackgroundXml);
@@ -194,19 +203,6 @@ void updateColorsFile(File colorsFile, String backgroundColor) {
194203 colorsFile.writeAsStringSync (lines.join ('\n ' ));
195204}
196205
197- /// Check to see if specified Android config is a string or bool
198- /// String - Generate new launcher icon with the string specified
199- /// bool - override the default flutter project icon
200- bool isCustomAndroidFile (Map <String , dynamic > config) {
201- final dynamic androidConfig = config['android' ];
202- return androidConfig is String ;
203- }
204-
205- /// return the new launcher icon file name
206- String getNewIconName (Map <String , dynamic > config) {
207- return config['android' ];
208- }
209-
210206/// Overrides the existing launcher icons in the project
211207/// Note: Do not change interpolation unless you end up with better results (see issue for result when using cubic
212208/// interpolation)
@@ -271,7 +267,7 @@ List<String> _transformAndroidManifestWithNewLauncherIcon(List<String> oldManife
271267/// - build.gradle: `'android/app/build.gradle'`
272268/// - local.properties: `'android/local.properties'`
273269///
274- /// If found none returns 0
270+ /// If found none returns [constants.androidDefaultAndroidMinSDK]
275271int minSdk () {
276272 final androidGradleFile = File (constants.androidGradleFile);
277273 final androidLocalPropertiesFile = File (constants.androidLocalPropertiesFile);
@@ -346,13 +342,6 @@ int? _getMinSdkFlutterGradle(File localPropertiesFile) {
346342 return null ;
347343}
348344
349- /// Method for the retrieval of the Android icon path
350- /// If image_path_android is found, this will be prioritised over the image_path
351- /// value.
352- String getAndroidIconPath (Map <String , dynamic > config) {
353- return config['image_path_android' ] ?? config['image_path' ];
354- }
355-
356345/// Returns true if the adaptive icon configuration is a PNG image
357346bool isAdaptiveIconConfigPngFile (String backgroundFile) {
358347 return backgroundFile.endsWith ('.png' );
0 commit comments