diff --git a/analysis_options.yaml b/analysis_options.yaml index 37f1c95755..15d3b9b962 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -40,6 +40,7 @@ linter: - avoid_types_as_parameter_names - avoid_unused_constructor_parameters - avoid_void_async + - unawaited_futures - await_only_futures - camel_case_types - cancel_subscriptions diff --git a/lib/android.dart b/lib/android.dart index a9e8327b9a..1b7fa0b312 100644 --- a/lib/android.dart +++ b/lib/android.dart @@ -193,11 +193,10 @@ void createMipmapXmlFile( ); } - mipmapXmlFile.create(recursive: true).then((File adaptiveIconFile) { - adaptiveIconFile.writeAsString( - xml_template.mipmapXmlFile.replaceAll('{{CONTENT}}', xmlContent), - ); - }); + mipmapXmlFile.createSync(recursive: true); + mipmapXmlFile.writeAsStringSync( + xml_template.mipmapXmlFile.replaceAll('{{CONTENT}}', xmlContent), + ); } /// Retrieves the colors.xml file for the project. @@ -249,13 +248,10 @@ void _createAdaptiveBackgrounds( /// Creates a colors.xml file if it was missing from android/app/src/main/res/values/colors.xml void createNewColorsFile(String backgroundColor, String? flavor) { - File(constants.androidColorsFile(flavor)) - .create(recursive: true) - .then((File colorsFile) { - colorsFile.writeAsString(xml_template.colorsXml).then((File file) { - updateColorsFile(colorsFile, backgroundColor); - }); - }); + final colorsFile = File(constants.androidColorsFile(flavor)); + colorsFile.createSync(recursive: true); + colorsFile.writeAsStringSync(xml_template.colorsXml); + updateColorsFile(colorsFile, backgroundColor); } /// Updates the colors.xml with the new adaptive launcher icon color @@ -296,14 +292,14 @@ void overwriteExistingIcons( String? flavor, ) { final Image newFile = utils.createResizedImage(template.size, image); - File( + final file = File( constants.androidResFolder(flavor) + template.directoryName + '/' + filename, - ).create(recursive: true).then((File file) { - file.writeAsBytesSync(encodePng(newFile)); - }); + ); + file.createSync(recursive: true); + file.writeAsBytesSync(encodePng(newFile)); } /// Saves new launcher icons to the project, keeping the old launcher icons. @@ -316,30 +312,30 @@ void _saveNewImages( String? flavor, ) { final Image newFile = utils.createResizedImage(template.size, image); - File( + final file = File( constants.androidResFolder(flavor) + template.directoryName + '/' + iconFilePath, - ).create(recursive: true).then((File file) { - file.writeAsBytesSync(encodePng(newFile)); - }); + ); + file.createSync(recursive: true); + file.writeAsBytesSync(encodePng(newFile)); } /// Updates the line which specifies the launcher icon within the AndroidManifest.xml /// with the new icon name (only if it has changed) /// /// Note: default iconName = "ic_launcher" -Future overwriteAndroidManifestWithNewLauncherIcon( +void overwriteAndroidManifestWithNewLauncherIcon( String iconName, File androidManifestFile, -) async { +) { // we do not use `file.readAsLinesSync()` here because that always gets rid of the last empty newline final List oldManifestLines = - (await androidManifestFile.readAsString()).split('\n'); + androidManifestFile.readAsStringSync().split('\n'); final List transformedLines = _transformAndroidManifestWithNewLauncherIcon(oldManifestLines, iconName); - await androidManifestFile.writeAsString(transformedLines.join('\n')); + androidManifestFile.writeAsStringSync(transformedLines.join('\n')); } /// Updates only the line containing android:icon with the specified iconName diff --git a/lib/ios.dart b/lib/ios.dart index 5fad0e7da2..7b3386db62 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -123,11 +123,9 @@ void overwriteDefaultIcons(IosIconTemplate template, Image image) { void saveNewIcons(IosIconTemplate template, Image image, String newIconName) { final String newIconFolder = iosAssetFolder + newIconName + '.appiconset/'; final Image newFile = createResizedImage(template, image); - File(newIconFolder + newIconName + template.name + '.png') - .create(recursive: true) - .then((File file) { - file.writeAsBytesSync(encodePng(newFile)); - }); + final file = File(newIconFolder + newIconName + template.name + '.png'); + file.createSync(recursive: true); + file.writeAsBytesSync(encodePng(newFile)); } /// create resized icon image @@ -152,7 +150,7 @@ Image createResizedImage(IosIconTemplate template, Image image) { /// Change the iOS launcher icon Future changeIosLauncherIcon(String iconName, String? flavor) async { final File iOSConfigFile = File(iosConfigFile); - final List lines = await iOSConfigFile.readAsLines(); + final List lines = iOSConfigFile.readAsLinesSync(); bool onConfigurationSection = false; String? currentConfig; @@ -180,18 +178,17 @@ Future changeIosLauncherIcon(String iconName, String? flavor) async { } final String entireFile = '${lines.join('\n')}\n'; - await iOSConfigFile.writeAsString(entireFile); + iOSConfigFile.writeAsStringSync(entireFile); } /// Create the Contents.json file void modifyContentsFile(String newIconName) { final String newIconFolder = iosAssetFolder + newIconName + '.appiconset/Contents.json'; - File(newIconFolder).create(recursive: true).then((File contentsJsonFile) { - final String contentsFileContent = - generateContentsFileAsString(newIconName); - contentsJsonFile.writeAsString(contentsFileContent); - }); + final contentsJsonFile = File(newIconFolder); + contentsJsonFile.createSync(recursive: true); + final String contentsFileContent = generateContentsFileAsString(newIconName); + contentsJsonFile.writeAsStringSync(contentsFileContent); } String generateContentsFileAsString(String newIconName) { diff --git a/lib/main.dart b/lib/main.dart index 4b235fa33a..f8e1831144 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -87,7 +87,7 @@ Future createIconsFromArguments(List arguments) async { ); } try { - await createIconsFromConfig( + createIconsFromConfig( flutterLauncherIconsConfigs, logger, prefixPath, @@ -109,7 +109,7 @@ Future createIconsFromArguments(List arguments) async { 'No configuration found for $flavor flavor.', ); } - await createIconsFromConfig( + createIconsFromConfig( flutterLauncherIconsConfigs, logger, prefixPath, @@ -125,12 +125,12 @@ Future createIconsFromArguments(List arguments) async { } } -Future createIconsFromConfig( +void createIconsFromConfig( Config flutterConfigs, FLILogger logger, String prefixPath, [ String? flavor, -]) async { +]) { if (!flutterConfigs.hasPlatformConfig) { throw const InvalidConfigException(errorMissingPlatform); } diff --git a/test/android_test.dart b/test/android_test.dart index f65fb8b8de..e72ac3bdbf 100644 --- a/test/android_test.dart +++ b/test/android_test.dart @@ -71,7 +71,7 @@ void main() { await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { androidManifestFile.writeAsStringSync(inputManifest); - await android.overwriteAndroidManifestWithNewLauncherIcon( + android.overwriteAndroidManifestWithNewLauncherIcon( 'ic_other_icon_name', androidManifestFile, ); @@ -89,7 +89,7 @@ void main() { await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { androidManifestFile.writeAsStringSync(inputManifest); - await android.overwriteAndroidManifestWithNewLauncherIcon( + android.overwriteAndroidManifestWithNewLauncherIcon( 'ic_launcher', androidManifestFile, ); @@ -106,7 +106,7 @@ void main() { await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { androidManifestFile.writeAsStringSync(inputManifest); - await android.overwriteAndroidManifestWithNewLauncherIcon( + android.overwriteAndroidManifestWithNewLauncherIcon( 'ic_launcher', androidManifestFile, ); @@ -124,7 +124,7 @@ void main() { await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { androidManifestFile.writeAsStringSync(inputManifest); - await android.overwriteAndroidManifestWithNewLauncherIcon( + android.overwriteAndroidManifestWithNewLauncherIcon( 'ic_launcher', androidManifestFile, ); @@ -142,7 +142,7 @@ void main() { await withTempFile('AndroidManifest.xml', (File androidManifestFile) async { androidManifestFile.writeAsStringSync(inputManifest); - await android.overwriteAndroidManifestWithNewLauncherIcon( + android.overwriteAndroidManifestWithNewLauncherIcon( 'ic_launcher', androidManifestFile, );