From bfa41c8d327e1147388c3b02fd942b835203c106 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Wed, 4 Dec 2024 11:16:47 +0300 Subject: [PATCH] fix --- lib/android.dart | 8 ++++---- test/android_test.dart | 38 ++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/android.dart b/lib/android.dart index 30249890f4..995fcd40b1 100644 --- a/lib/android.dart +++ b/lib/android.dart @@ -116,7 +116,7 @@ void createAdaptiveIcons( } // Create adaptive icon background - if (isAdaptiveIconConfigPngFile(backgroundConfig)) { + if (!isAdaptiveIconConfigColor(backgroundConfig)) { _createAdaptiveBackgrounds( config, backgroundConfig, @@ -163,7 +163,7 @@ void createMipmapXmlFile( String xmlContent = ''; if (config.hasAndroidAdaptiveConfig) { - if (isAdaptiveIconConfigPngFile(config.adaptiveIconBackground!)) { + if (!isAdaptiveIconConfigColor(config.adaptiveIconBackground!)) { xmlContent += ' \n'; } else { @@ -462,8 +462,8 @@ int? _getMinSdkFlutterGradle(File localPropertiesFile) { } /// Returns true if the adaptive icon configuration is a PNG image -bool isAdaptiveIconConfigPngFile(String backgroundFile) { - return backgroundFile.endsWith('.png'); +bool isAdaptiveIconConfigColor(String backgroundFile) { + return backgroundFile.startsWith('#'); } /// (NOTE THIS IS JUST USED FOR UNIT TEST) diff --git a/test/android_test.dart b/test/android_test.dart index f65fb8b8de..9b535e1add 100644 --- a/test/android_test.dart +++ b/test/android_test.dart @@ -20,6 +20,13 @@ void main() { ); }); + test('Adaptive icon color', () { + //for file not in only png format + expect(android.isAdaptiveIconConfigColor('assets/icons/adaptive_icon_background.jpg'), equals(false)); + //for color bg + expect(android.isAdaptiveIconConfigColor('#FFFFFF'), equals(true)); + }); + test('Correct number of adaptive foreground icons', () { expect(android.adaptiveForegroundIcons.length, 5); }); @@ -79,13 +86,9 @@ void main() { }); }); - test( - 'Transforming manifest with icon already in place should leave it unchanged', - () async { - final String inputManifest = - getAndroidManifestExample('android:icon="@mipmap/ic_launcher"'); - final String expectedManifest = - getAndroidManifestExample('android:icon="@mipmap/ic_launcher"'); + test('Transforming manifest with icon already in place should leave it unchanged', () async { + final String inputManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"'); + final String expectedManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"'); await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { androidManifestFile.writeAsStringSync(inputManifest); @@ -97,11 +100,8 @@ void main() { }); }); - test( - 'Transforming manifest with trailing newline should keep newline untouched', - () async { - final String inputManifest = - getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') + '\n'; + test('Transforming manifest with trailing newline should keep newline untouched', () async { + final String inputManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') + '\n'; final String expectedManifest = inputManifest; await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { @@ -114,12 +114,8 @@ void main() { }); }); - test( - 'Transforming manifest with 3 trailing newlines should keep newlines untouched', - () async { - final String inputManifest = - getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') + - '\n\n\n'; + test('Transforming manifest with 3 trailing newlines should keep newlines untouched', () async { + final String inputManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') + '\n\n\n'; final String expectedManifest = inputManifest; await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { @@ -132,12 +128,10 @@ void main() { }); }); - test( - 'Transforming manifest with special newline characters should leave special newline characters untouched', + test('Transforming manifest with special newline characters should leave special newline characters untouched', () async { final String inputManifest = - getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') - .replaceAll('\n', '\r\n'); + getAndroidManifestExample('android:icon="@mipmap/ic_launcher"').replaceAll('\n', '\r\n'); final String expectedManifest = inputManifest; await withTempFile('AndroidManifest.xml', (File androidManifestFile) async {