Skip to content

Commit 4416dbe

Browse files
hugobrancowbMarkOSullivan94
authored andcommitted
chore: Formats code running dart format .
Signed-off-by: Hugo Branco <[email protected]>
1 parent 77d102f commit 4416dbe

21 files changed

+616
-306
lines changed

bin/main.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'flutter_launcher_icons.dart' as flutter_launcher_icons;
22

33
void main(List<String> arguments) {
4-
print('This command is deprecated and replaced with "flutter pub run flutter_launcher_icons"');
4+
print(
5+
'This command is deprecated and replaced with "flutter pub run flutter_launcher_icons"',
6+
);
57
flutter_launcher_icons.main(arguments);
68
}

lib/abs/icon_generator.dart

+16-9
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,31 @@ void generateIconsFor({
7272
required List<IconGenerator> Function(IconGeneratorContext context) platforms,
7373
}) {
7474
try {
75-
final platformList = platforms(IconGeneratorContext(
76-
config: config,
77-
logger: logger,
78-
prefixPath: prefixPath,
79-
flavor: flavor,
80-
));
75+
final platformList = platforms(
76+
IconGeneratorContext(
77+
config: config,
78+
logger: logger,
79+
prefixPath: prefixPath,
80+
flavor: flavor,
81+
),
82+
);
8183
if (platformList.isEmpty) {
8284
// ? maybe we can print help
8385
logger.info('No platform provided');
8486
}
8587

8688
for (final platform in platformList) {
87-
final progress = logger.progress('Creating Icons for ${platform.platformName}');
88-
logger.verbose('Validating platform requirements for ${platform.platformName}');
89+
final progress =
90+
logger.progress('Creating Icons for ${platform.platformName}');
91+
logger.verbose(
92+
'Validating platform requirements for ${platform.platformName}',
93+
);
8994
// in case a platform throws an exception it should not effect other platforms
9095
try {
9196
if (!platform.validateRequirements()) {
92-
logger.error('Requirements failed for platform ${platform.platformName}. Skipped');
97+
logger.error(
98+
'Requirements failed for platform ${platform.platformName}. Skipped',
99+
);
93100
progress.cancel();
94101
continue;
95102
}

lib/android.dart

+126-46
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import 'dart:io';
2+
23
import 'package:flutter_launcher_icons/constants.dart';
4+
import 'package:flutter_launcher_icons/constants.dart' as constants;
5+
import 'package:flutter_launcher_icons/custom_exceptions.dart';
36
import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart';
47
import 'package:flutter_launcher_icons/utils.dart';
58
import 'package:flutter_launcher_icons/xml_templates.dart' as xml_template;
69
import 'package:image/image.dart';
7-
import 'package:flutter_launcher_icons/custom_exceptions.dart';
8-
import 'package:flutter_launcher_icons/constants.dart' as constants;
910
import 'package:path/path.dart' as path;
1011

1112
class AndroidIconTemplate {
@@ -31,7 +32,10 @@ List<AndroidIconTemplate> androidIcons = <AndroidIconTemplate>[
3132
AndroidIconTemplate(directoryName: 'mipmap-xxxhdpi', size: 192),
3233
];
3334

34-
void createDefaultIcons(FlutterLauncherIconsConfig flutterLauncherIconsConfig, String? flavor) {
35+
void createDefaultIcons(
36+
FlutterLauncherIconsConfig flutterLauncherIconsConfig,
37+
String? flavor,
38+
) {
3539
printStatus('Creating default icons Android');
3640
// todo: support prefixPath
3741
final String? filePath = flutterLauncherIconsConfig.getImagePathAndroid();
@@ -53,29 +57,46 @@ void createDefaultIcons(FlutterLauncherIconsConfig flutterLauncherIconsConfig, S
5357
}
5458
overwriteAndroidManifestWithNewLauncherIcon(iconName, androidManifestFile);
5559
} else {
56-
printStatus('Overwriting the default Android launcher icon with a new icon');
60+
printStatus(
61+
'Overwriting the default Android launcher icon with a new icon',
62+
);
5763
for (AndroidIconTemplate template in androidIcons) {
58-
overwriteExistingIcons(template, image, constants.androidFileName, flavor);
64+
overwriteExistingIcons(
65+
template,
66+
image,
67+
constants.androidFileName,
68+
flavor,
69+
);
5970
}
60-
overwriteAndroidManifestWithNewLauncherIcon(constants.androidDefaultIconName, androidManifestFile);
71+
overwriteAndroidManifestWithNewLauncherIcon(
72+
constants.androidDefaultIconName,
73+
androidManifestFile,
74+
);
6175
}
6276
}
6377

6478
/// Ensures that the Android icon name is in the correct format
6579
bool isAndroidIconNameCorrectFormat(String iconName) {
6680
// assure the icon only consists of lowercase letters, numbers and underscore
6781
if (!RegExp(r'^[a-z0-9_]+$').hasMatch(iconName)) {
68-
throw const InvalidAndroidIconNameException(constants.errorIncorrectIconName);
82+
throw const InvalidAndroidIconNameException(
83+
constants.errorIncorrectIconName,
84+
);
6985
}
7086
return true;
7187
}
7288

73-
void createAdaptiveIcons(FlutterLauncherIconsConfig flutterLauncherIconsConfig, String? flavor) {
89+
void createAdaptiveIcons(
90+
FlutterLauncherIconsConfig flutterLauncherIconsConfig,
91+
String? flavor,
92+
) {
7493
printStatus('Creating adaptive icons Android');
7594

7695
// Retrieve the necessary Flutter Launcher Icons configuration from the pubspec.yaml file
77-
final String? backgroundConfig = flutterLauncherIconsConfig.adaptiveIconBackground;
78-
final String? foregroundImagePath = flutterLauncherIconsConfig.adaptiveIconForeground;
96+
final String? backgroundConfig =
97+
flutterLauncherIconsConfig.adaptiveIconBackground;
98+
final String? foregroundImagePath =
99+
flutterLauncherIconsConfig.adaptiveIconForeground;
79100
if (backgroundConfig == null || foregroundImagePath == null) {
80101
throw const InvalidConfigException(errorMissingImagePath);
81102
}
@@ -86,12 +107,21 @@ void createAdaptiveIcons(FlutterLauncherIconsConfig flutterLauncherIconsConfig,
86107

87108
// Create adaptive icon foreground images
88109
for (AndroidIconTemplate androidIcon in adaptiveForegroundIcons) {
89-
overwriteExistingIcons(androidIcon, foregroundImage, constants.androidAdaptiveForegroundFileName, flavor);
110+
overwriteExistingIcons(
111+
androidIcon,
112+
foregroundImage,
113+
constants.androidAdaptiveForegroundFileName,
114+
flavor,
115+
);
90116
}
91117

92118
// Create adaptive icon background
93119
if (isAdaptiveIconConfigPngFile(backgroundConfig)) {
94-
_createAdaptiveBackgrounds(flutterLauncherIconsConfig, backgroundConfig, flavor);
120+
_createAdaptiveBackgrounds(
121+
flutterLauncherIconsConfig,
122+
backgroundConfig,
123+
flavor,
124+
);
95125
} else {
96126
createAdaptiveIconMipmapXmlFile(flutterLauncherIconsConfig, flavor);
97127
updateColorsXmlFile(backgroundConfig, flavor);
@@ -112,24 +142,33 @@ void updateColorsXmlFile(String backgroundConfig, String? flavor) {
112142
updateColorsFile(colorsXml, backgroundConfig);
113143
} else {
114144
printStatus('No colors.xml file found in your Android project');
115-
printStatus('Creating colors.xml file and adding it to your Android project');
145+
printStatus(
146+
'Creating colors.xml file and adding it to your Android project',
147+
);
116148
createNewColorsFile(backgroundConfig, flavor);
117149
}
118150
}
119151

120152
/// Creates the xml file required for the adaptive launcher icon
121153
/// FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml
122-
void createAdaptiveIconMipmapXmlFile(FlutterLauncherIconsConfig flutterLauncherIconsConfig, String? flavor) {
154+
void createAdaptiveIconMipmapXmlFile(
155+
FlutterLauncherIconsConfig flutterLauncherIconsConfig,
156+
String? flavor,
157+
) {
123158
if (flutterLauncherIconsConfig.isCustomAndroidFile) {
124-
File(constants.androidAdaptiveXmlFolder(flavor) + flutterLauncherIconsConfig.android + '.xml')
125-
.create(recursive: true)
126-
.then((File adaptiveIcon) {
159+
File(
160+
constants.androidAdaptiveXmlFolder(flavor) +
161+
flutterLauncherIconsConfig.android +
162+
'.xml',
163+
).create(recursive: true).then((File adaptiveIcon) {
127164
adaptiveIcon.writeAsString(xml_template.icLauncherXml);
128165
});
129166
} else {
130-
File(constants.androidAdaptiveXmlFolder(flavor) + constants.androidDefaultIconName + '.xml')
131-
.create(recursive: true)
132-
.then((File adaptiveIcon) {
167+
File(
168+
constants.androidAdaptiveXmlFolder(flavor) +
169+
constants.androidDefaultIconName +
170+
'.xml',
171+
).create(recursive: true).then((File adaptiveIcon) {
133172
adaptiveIcon.writeAsString(xml_template.icLauncherXml);
134173
});
135174
}
@@ -150,29 +189,40 @@ void _createAdaptiveBackgrounds(
150189
// creates a png image (ic_adaptive_background.png) for the adaptive icon background in each of the locations
151190
// it is required
152191
for (AndroidIconTemplate androidIcon in adaptiveForegroundIcons) {
153-
_saveNewImages(androidIcon, image, constants.androidAdaptiveBackgroundFileName, flavor);
192+
_saveNewImages(
193+
androidIcon,
194+
image,
195+
constants.androidAdaptiveBackgroundFileName,
196+
flavor,
197+
);
154198
}
155199

156200
// Creates the xml file required for the adaptive launcher icon
157201
// FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml
158202
if (flutterLauncherIconsConfig.isCustomAndroidFile) {
159-
File(constants.androidAdaptiveXmlFolder(flavor) + flutterLauncherIconsConfig.android + '.xml')
160-
.create(recursive: true)
161-
.then((File adaptiveIcon) {
203+
File(
204+
constants.androidAdaptiveXmlFolder(flavor) +
205+
flutterLauncherIconsConfig.android +
206+
'.xml',
207+
).create(recursive: true).then((File adaptiveIcon) {
162208
adaptiveIcon.writeAsString(xml_template.icLauncherDrawableBackgroundXml);
163209
});
164210
} else {
165-
File(constants.androidAdaptiveXmlFolder(flavor) + constants.androidDefaultIconName + '.xml')
166-
.create(recursive: true)
167-
.then((File adaptiveIcon) {
211+
File(
212+
constants.androidAdaptiveXmlFolder(flavor) +
213+
constants.androidDefaultIconName +
214+
'.xml',
215+
).create(recursive: true).then((File adaptiveIcon) {
168216
adaptiveIcon.writeAsString(xml_template.icLauncherDrawableBackgroundXml);
169217
});
170218
}
171219
}
172220

173221
/// Creates a colors.xml file if it was missing from android/app/src/main/res/values/colors.xml
174222
void createNewColorsFile(String backgroundColor, String? flavor) {
175-
File(constants.androidColorsFile(flavor)).create(recursive: true).then((File colorsFile) {
223+
File(constants.androidColorsFile(flavor))
224+
.create(recursive: true)
225+
.then((File colorsFile) {
176226
colorsFile.writeAsString(xml_template.colorsXml).then((File file) {
177227
updateColorsFile(colorsFile, backgroundColor);
178228
});
@@ -197,7 +247,10 @@ void updateColorsFile(File colorsFile, String backgroundColor) {
197247

198248
// Add new line if we didn't find an existing value
199249
if (!foundExisting) {
200-
lines.insert(lines.length - 1, '\t<color name="ic_launcher_background">$backgroundColor</color>');
250+
lines.insert(
251+
lines.length - 1,
252+
'\t<color name="ic_launcher_background">$backgroundColor</color>',
253+
);
201254
}
202255

203256
colorsFile.writeAsStringSync(lines.join('\n'));
@@ -214,21 +267,32 @@ void overwriteExistingIcons(
214267
String? flavor,
215268
) {
216269
final Image newFile = createResizedImage(template.size, image);
217-
File(constants.androidResFolder(flavor) + template.directoryName + '/' + filename)
218-
.create(recursive: true)
219-
.then((File file) {
270+
File(
271+
constants.androidResFolder(flavor) +
272+
template.directoryName +
273+
'/' +
274+
filename,
275+
).create(recursive: true).then((File file) {
220276
file.writeAsBytesSync(encodePng(newFile));
221277
});
222278
}
223279

224280
/// Saves new launcher icons to the project, keeping the old launcher icons.
225281
/// Note: Do not change interpolation unless you end up with better results
226282
/// https://github.com/fluttercommunity/flutter_launcher_icons/issues/101#issuecomment-495528733
227-
void _saveNewImages(AndroidIconTemplate template, Image image, String iconFilePath, String? flavor) {
283+
void _saveNewImages(
284+
AndroidIconTemplate template,
285+
Image image,
286+
String iconFilePath,
287+
String? flavor,
288+
) {
228289
final Image newFile = createResizedImage(template.size, image);
229-
File(constants.androidResFolder(flavor) + template.directoryName + '/' + iconFilePath)
230-
.create(recursive: true)
231-
.then((File file) {
290+
File(
291+
constants.androidResFolder(flavor) +
292+
template.directoryName +
293+
'/' +
294+
iconFilePath,
295+
).create(recursive: true).then((File file) {
232296
file.writeAsBytesSync(encodePng(newFile));
233297
});
234298
}
@@ -237,15 +301,23 @@ void _saveNewImages(AndroidIconTemplate template, Image image, String iconFilePa
237301
/// with the new icon name (only if it has changed)
238302
///
239303
/// Note: default iconName = "ic_launcher"
240-
Future<void> overwriteAndroidManifestWithNewLauncherIcon(String iconName, File androidManifestFile) async {
304+
Future<void> overwriteAndroidManifestWithNewLauncherIcon(
305+
String iconName,
306+
File androidManifestFile,
307+
) async {
241308
// we do not use `file.readAsLinesSync()` here because that always gets rid of the last empty newline
242-
final List<String> oldManifestLines = (await androidManifestFile.readAsString()).split('\n');
243-
final List<String> transformedLines = _transformAndroidManifestWithNewLauncherIcon(oldManifestLines, iconName);
309+
final List<String> oldManifestLines =
310+
(await androidManifestFile.readAsString()).split('\n');
311+
final List<String> transformedLines =
312+
_transformAndroidManifestWithNewLauncherIcon(oldManifestLines, iconName);
244313
await androidManifestFile.writeAsString(transformedLines.join('\n'));
245314
}
246315

247316
/// Updates only the line containing android:icon with the specified iconName
248-
List<String> _transformAndroidManifestWithNewLauncherIcon(List<String> oldManifestLines, String iconName) {
317+
List<String> _transformAndroidManifestWithNewLauncherIcon(
318+
List<String> oldManifestLines,
319+
String iconName,
320+
) {
249321
return oldManifestLines.map((String line) {
250322
if (line.contains('android:icon')) {
251323
// Using RegExp replace the value of android:icon to point to the new icon
@@ -255,7 +327,10 @@ List<String> _transformAndroidManifestWithNewLauncherIcon(List<String> oldManife
255327
// repeat as often as wanted with no quote at start: [^"]*(\"[^"]*)*
256328
// escaping the slash to place in string: [^"]*(\\"[^"]*)*"
257329
// result: any string which does only include escaped quotes
258-
return line.replaceAll(RegExp(r'android:icon="[^"]*(\\"[^"]*)*"'), 'android:icon="@mipmap/$iconName"');
330+
return line.replaceAll(
331+
RegExp(r'android:icon="[^"]*(\\"[^"]*)*"'),
332+
'android:icon="@mipmap/$iconName"',
333+
);
259334
} else {
260335
return line;
261336
}
@@ -286,7 +361,8 @@ int? _getMinSdkFromFile(File file) {
286361
final List<String> lines = file.readAsLinesSync();
287362
for (String line in lines) {
288363
if (line.contains('minSdkVersion')) {
289-
if (line.contains('//') && line.indexOf('//') < line.indexOf('minSdkVersion')) {
364+
if (line.contains('//') &&
365+
line.indexOf('//') < line.indexOf('minSdkVersion')) {
290366
// This line is commented
291367
continue;
292368
}
@@ -307,7 +383,8 @@ String? _getFlutterSdkPathFromLocalProperties(File file) {
307383
if (!line.contains('flutter.sdk=')) {
308384
continue;
309385
}
310-
if (line.contains('#') && line.indexOf('#') < line.indexOf('flutter.sdk=')) {
386+
if (line.contains('#') &&
387+
line.indexOf('#') < line.indexOf('flutter.sdk=')) {
311388
continue;
312389
}
313390
final flutterSdkPath = line.split('=').last.trim();
@@ -321,19 +398,22 @@ String? _getFlutterSdkPathFromLocalProperties(File file) {
321398

322399
/// Retrives value of `minSdkVersion` from `flutter.gradle`
323400
int? _getMinSdkFlutterGradle(File localPropertiesFile) {
324-
final flutterRoot = _getFlutterSdkPathFromLocalProperties(localPropertiesFile);
401+
final flutterRoot =
402+
_getFlutterSdkPathFromLocalProperties(localPropertiesFile);
325403
if (flutterRoot == null) {
326404
return null;
327405
}
328406

329-
final flutterGradleFile = File(path.join(flutterRoot, constants.androidFlutterGardlePath));
407+
final flutterGradleFile =
408+
File(path.join(flutterRoot, constants.androidFlutterGardlePath));
330409

331410
final List<String> lines = flutterGradleFile.readAsLinesSync();
332411
for (String line in lines) {
333412
if (!line.contains('static int minSdkVersion =')) {
334413
continue;
335414
}
336-
if (line.contains('//') && line.indexOf('//') < line.indexOf('static int minSdkVersion =')) {
415+
if (line.contains('//') &&
416+
line.indexOf('//') < line.indexOf('static int minSdkVersion =')) {
337417
continue;
338418
}
339419
final minSdk = line.split('=').last.trim();

0 commit comments

Comments
 (0)