Skip to content

Commit

Permalink
refactor: can now use flutter_launcher_icons key in pubspec instead o…
Browse files Browse the repository at this point in the history
…f flutter_icons
  • Loading branch information
MarkOSullivan94 committed Apr 15, 2023
1 parent f954a34 commit d314ca8
Show file tree
Hide file tree
Showing 30 changed files with 655 additions and 536 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.13.1 (15th April 2023)

- Can now use `flutter_launcher_icons` instead of `flutter_icons` [#478](https://github.com/fluttercommunity/flutter_launcher_icons/pull/478)


## 0.13.0 (7th April 2023)

- Fix remove alpha for iOS [#464](https://github.com/fluttercommunity/flutter_launcher_icons/pull/464)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ An example is shown below. More complex examples [can be found in the example pr

```yaml
dev_dependencies:
flutter_launcher_icons: "^0.13.0"
flutter_launcher_icons: "^0.13.1"

flutter_icons:
flutter_launcher_icons:
android: "launcher_icon"
ios: true
image_path: "assets/icon/icon.png"
Expand Down
41 changes: 38 additions & 3 deletions example/default_example/.metadata
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: ce40de69b7b4f89c66d19c8dbd3bd86ae30f1bc6
channel: dev
revision: f72efea43c3013323d1b95cff571f3c1caa37583
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
- platform: android
create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
- platform: ios
create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
- platform: linux
create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
- platform: macos
create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
- platform: web
create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
- platform: windows
create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
base_revision: f72efea43c3013323d1b95cff571f3c1caa37583

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
2 changes: 1 addition & 1 deletion example/default_example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
flutter_launcher_icons:
path: ../..

flutter_icons:
flutter_launcher_icons:
# image_path: "assets/images/icon-128x128.png"
image_path_android: "assets/images/icon-710x599-android.png"
image_path_ios: "assets/images/icon-1024x1024.png"
Expand Down
9 changes: 6 additions & 3 deletions lib/abs/icon_generator.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:io';

import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart';
import 'package:flutter_launcher_icons/config/config.dart';
import 'package:flutter_launcher_icons/config/macos_config.dart';
import 'package:flutter_launcher_icons/config/web_config.dart';
import 'package:flutter_launcher_icons/config/windows_config.dart';
import 'package:flutter_launcher_icons/logger.dart';

/// A base class to generate icons
Expand Down Expand Up @@ -34,7 +37,7 @@ abstract class IconGenerator {
/// Provides easy access to user arguments and configuration
class IconGeneratorContext {
/// Contains configuration from configuration file
final FlutterLauncherIconsConfig config;
final Config config;

/// A logger
final FLILogger logger;
Expand Down Expand Up @@ -65,7 +68,7 @@ class IconGeneratorContext {

/// Generates Icon for given platforms
void generateIconsFor({
required FlutterLauncherIconsConfig config,
required Config config,
required String? flavor,
required String prefixPath,
required FLILogger logger,
Expand Down
32 changes: 16 additions & 16 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'dart:io';
import 'package:flutter_launcher_icons/constants.dart';
import 'package:flutter_launcher_icons/constants.dart' as constants;
import 'package:flutter_launcher_icons/custom_exceptions.dart';
import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart';
import 'package:flutter_launcher_icons/config/config.dart';
import 'package:flutter_launcher_icons/utils.dart' as utils;
import 'package:flutter_launcher_icons/xml_templates.dart' as xml_template;
import 'package:image/image.dart';
Expand Down Expand Up @@ -35,12 +35,12 @@ List<AndroidIconTemplate> androidIcons = <AndroidIconTemplate>[
];

void createDefaultIcons(
FlutterLauncherIconsConfig flutterLauncherIconsConfig,
Config config,
String? flavor,
) {
utils.printStatus('Creating default icons Android');
// TODO(p-mazhnik): support prefixPath
final String? filePath = flutterLauncherIconsConfig.getImagePathAndroid();
final String? filePath = config.getImagePathAndroid();
if (filePath == null) {
throw const InvalidConfigException(errorMissingImagePath);
}
Expand All @@ -49,9 +49,9 @@ void createDefaultIcons(
return;
}
final File androidManifestFile = File(constants.androidManifestFile);
if (flutterLauncherIconsConfig.isCustomAndroidFile) {
if (config.isCustomAndroidFile) {
utils.printStatus('Adding a new Android launcher icon');
final String iconName = flutterLauncherIconsConfig.android;
final String iconName = config.android;
isAndroidIconNameCorrectFormat(iconName);
final String iconPath = '$iconName.png';
for (AndroidIconTemplate template in androidIcons) {
Expand Down Expand Up @@ -89,16 +89,16 @@ bool isAndroidIconNameCorrectFormat(String iconName) {
}

void createAdaptiveIcons(
FlutterLauncherIconsConfig flutterLauncherIconsConfig,
Config config,
String? flavor,
) {
utils.printStatus('Creating adaptive icons Android');

// Retrieve the necessary Flutter Launcher Icons configuration from the pubspec.yaml file
final String? backgroundConfig =
flutterLauncherIconsConfig.adaptiveIconBackground;
config.adaptiveIconBackground;
final String? foregroundImagePath =
flutterLauncherIconsConfig.adaptiveIconForeground;
config.adaptiveIconForeground;
if (backgroundConfig == null || foregroundImagePath == null) {
throw const InvalidConfigException(errorMissingImagePath);
}
Expand All @@ -120,12 +120,12 @@ void createAdaptiveIcons(
// Create adaptive icon background
if (isAdaptiveIconConfigPngFile(backgroundConfig)) {
_createAdaptiveBackgrounds(
flutterLauncherIconsConfig,
config,
backgroundConfig,
flavor,
);
} else {
createAdaptiveIconMipmapXmlFile(flutterLauncherIconsConfig, flavor);
createAdaptiveIconMipmapXmlFile(config, flavor);
updateColorsXmlFile(backgroundConfig, flavor);
}
}
Expand Down Expand Up @@ -156,13 +156,13 @@ void updateColorsXmlFile(String backgroundConfig, String? flavor) {
/// Creates the xml file required for the adaptive launcher icon
/// FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml
void createAdaptiveIconMipmapXmlFile(
FlutterLauncherIconsConfig flutterLauncherIconsConfig,
Config config,
String? flavor,
) {
if (flutterLauncherIconsConfig.isCustomAndroidFile) {
if (config.isCustomAndroidFile) {
File(
constants.androidAdaptiveXmlFolder(flavor) +
flutterLauncherIconsConfig.android +
config.android +
'.xml',
).create(recursive: true).then((File adaptiveIcon) {
adaptiveIcon.writeAsString(xml_template.icLauncherXml);
Expand All @@ -180,7 +180,7 @@ void createAdaptiveIconMipmapXmlFile(

/// creates adaptive background using png image
void _createAdaptiveBackgrounds(
FlutterLauncherIconsConfig flutterLauncherIconsConfig,
Config config,
String adaptiveIconBackgroundImagePath,
String? flavor,
) {
Expand All @@ -203,10 +203,10 @@ void _createAdaptiveBackgrounds(

// Creates the xml file required for the adaptive launcher icon
// FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml
if (flutterLauncherIconsConfig.isCustomAndroidFile) {
if (config.isCustomAndroidFile) {
File(
constants.androidAdaptiveXmlFolder(flavor) +
flutterLauncherIconsConfig.android +
config.android +
'.xml',
).create(recursive: true).then((File adaptiveIcon) {
adaptiveIcon.writeAsString(xml_template.icLauncherDrawableBackgroundXml);
Expand Down
Loading

0 comments on commit d314ca8

Please sign in to comment.