Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoCherHong committed May 5, 2023
1 parent 397ca81 commit 281edaa
Show file tree
Hide file tree
Showing 45 changed files with 967 additions and 648 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd-pub-deploy-published-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v2
- name: Run a one-line script
uses: k-paxian/dart-package-publisher@v1.2
uses: k-paxian/dart-package-publisher@v1.5.1
with:
accessToken: ${{ secrets.PUB_ACCESS_TOKEN }}
refreshToken: ${{ secrets.PUB_REFRESH_TOKEN}}
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# Changelog

## 0.11.0 (27th September 2022)
## 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)
- Can use command `flutter pub run flutter_launcher_icons:generate` to automatically generate config file [#475](https://github.com/fluttercommunity/flutter_launcher_icons/pull/475)


## 0.13.0 (7th April 2023)

- Fix remove alpha for iOS [#464](https://github.com/fluttercommunity/flutter_launcher_icons/pull/464)
- Updating code style [#472](https://github.com/fluttercommunity/flutter_launcher_icons/pull/472)
- Updated out of bounds dependency [#473](https://github.com/fluttercommunity/flutter_launcher_icons/pull/473)

## 0.12.0 (24th February 2023)

- Updated image package and other packages [#447](https://github.com/fluttercommunity/flutter_launcher_icons/pull/447)

## 0.11.0 (27th September 2022)

- Support for Macos Icons [#407](https://github.com/fluttercommunity/flutter_launcher_icons/pull/407)
- Cli-improvement [#400](https://github.com/fluttercommunity/flutter_launcher_icons/pull/400)
- Add `repository` and `issue_tracker` [#411](https://github.com/fluttercommunity/flutter_launcher_icons/pull/411) (thanks to [@patelpathik](https://github.com/patelpathik))
Expand Down
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,44 @@

[![Flutter Community: flutter_launcher_icons](https://fluttercommunity.dev/_github/header/flutter_launcher_icons)](https://github.com/fluttercommunity/community)

[![Build Status](https://travis-ci.org/fluttercommunity/flutter_launcher_icons.svg?branch=master)](https://travis-ci.org/MarkOSullivan94/flutter_launcher_icons) [![pub package](https://img.shields.io/pub/v/flutter_launcher_icons.svg)](https://pub.dartlang.org/packages/flutter_launcher_icons)
[![pub package](https://img.shields.io/pub/v/flutter_launcher_icons.svg)](https://pub.dartlang.org/packages/flutter_launcher_icons)

A command-line tool which simplifies the task of updating your Flutter app's launcher icon. Fully flexible, allowing you to choose what platform you wish to update the launcher icon for and if you want, the option to keep your old launcher icon in case you want to revert back sometime in the future.

## :book: Guide

### 1. Setup the config file

Add your Flutter Launcher Icons configuration to your `pubspec.yaml` or create a new config file called `flutter_launcher_icons.yaml`.
Run the following command to create a new config automatically:

```shell
flutter pub run flutter_launcher_icons:generate
```

This will create a new file called `flutter_launcher_icons.yaml` in your `flutter` project's root directory.

If you want to override the default location or name of the config file, use the `-f` flag:

```shell
flutter pub run flutter_launcher_icons:generate -f <your config file name here>
```

To override an existing config file, use the `-o` flag:

```shell
flutter pub run flutter_launcher_icons:generate -o
```

OR

Add your Flutter Launcher Icons configuration to your `pubspec.yaml`.
An example is shown below. More complex examples [can be found in the example projects](https://github.com/fluttercommunity/flutter_launcher_icons/tree/master/example).

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

flutter_icons:
flutter_launcher_icons:
android: "launcher_icon"
ios: true
image_path: "assets/icon/icon.png"
Expand All @@ -36,25 +58,25 @@ flutter_icons:
image_path: "path/to/image.png"
```
If you name your configuration file something other than `flutter_launcher_icons.yaml` or `pubspec.yaml` you will need to specify
the name of the file when running the package.
### 2. Run the package
After setting up the configuration, all that is left to do is run the package.
```shell
flutter pub get
flutter pub run flutter_launcher_icons -f <your config file name here>
flutter pub run flutter_launcher_icons
```

Note: If you are not using the existing `pubspec.yaml` ensure that your config file is located in the same directory as it.

### 2. Run the package

After setting up the configuration, all that is left to do is run the package.
If you name your configuration file something other than `flutter_launcher_icons.yaml` or `pubspec.yaml` you will need to specify
the name of the file when running the package.

```shell
flutter pub get
flutter pub run flutter_launcher_icons
flutter pub run flutter_launcher_icons -f <your config file name here>
```

Note: If you are not using the existing `pubspec.yaml` ensure that your config file is located in the same directory as it.

If you encounter any issues [please report them here](https://github.com/fluttercommunity/flutter_launcher_icons/issues).

In the above configuration, the package is setup to replace the existing launcher icons in both the Android and iOS project
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ analyzer:
- "lib/src/http/**"
- "example/**"
- "**/*.g.dart"
- "lib/src/version.dart"

linter:
rules:
Expand Down
113 changes: 113 additions & 0 deletions bin/generate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'dart:io';

import 'package:args/args.dart';

import 'package:flutter_launcher_icons/constants.dart';
import 'package:flutter_launcher_icons/src/version.dart';

const _defaultConfigFileName = './flutter_launcher_icons.yaml';

/// The function will be called from command line
/// using the following command:
/// ```sh
/// flutter pub run flutter_launcher_icons:generate
/// ```
///
/// Calling this function will generate a flutter_launcher_icons.yaml file
/// with a default config template.
///
/// This command can take 2 optional arguments:
/// - --override: This will override the current `flutter_launcher_icons.yaml`
/// file if it exists, if not provided, the file will not be overridden and
/// a message will be printed to the console.
///
/// - --fileName: This flag will take a file name as an argument and
/// will generate the config format in that file instead of the default
/// `flutter_launcher_icons.yaml` file, if not provided,
/// the default file will be used.
void main(List<String> arguments) {
print(introMessage(packageVersion));

final parser = ArgParser()
..addFlag('override', abbr: 'o', defaultsTo: false)
..addOption(
'fileName',
abbr: 'f',
defaultsTo: _defaultConfigFileName,
);

final results = parser.parse(arguments);
final override = results['override'] as bool;
final fileName = results['fileName'] as String;

// Check if fileName is valid and has a .yaml extension
if (!fileName.endsWith('.yaml')) {
print('Invalid file name, please provide a valid file name');
return;
}

final file = File(fileName);
if (file.existsSync()) {
if (override) {
print('File already exists, overriding...');
_generateConfigFile(file);
} else {
print(
'File already exists, use --override flag to override the file, or use --fileName flag to use a different file name',
);
}
} else {
try {
file.createSync(recursive: true);
_generateConfigFile(file);
} on Exception catch (e) {
print('Error creating file: $e');
}
}
}

void _generateConfigFile(File configFile) {
try {
configFile.writeAsStringSync(_configFileTemplate);

print('\nConfig file generated successfully 🎉');
print(
'You can now use this new config file by using the command below:\n\n'
'flutter pub run flutter_launcher_icons'
'${configFile.path == _defaultConfigFileName ? '' : ' -f ${configFile.path}'}\n',
);
} on Exception catch (e) {
print('Error generating config file: $e');
}
}

const _configFileTemplate = '''
# flutter pub run flutter_launcher_icons
flutter_launcher_icons:
image_path: "assets/icon/icon.png"
android: "launcher_icon"
# image_path_android: "assets/icon/icon.png"
min_sdk_android: 21 # android min sdk min:16, default 21
# adaptive_icon_background: "assets/icon/background.png"
# adaptive_icon_foreground: "assets/icon/foreground.png"
ios: true
# image_path_ios: "assets/icon/icon.png"
remove_alpha_channel_ios: true
web:
generate: true
image_path: "path/to/image.png"
background_color: "#hexcode"
theme_color: "#hexcode"
windows:
generate: true
image_path: "path/to/image.png"
icon_size: 48 # min:48, max:256, default: 48
macos:
generate: true
image_path: "path/to/image.png"
''';
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'
4 changes: 2 additions & 2 deletions example/default_example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A new Flutter project to quickly test flutter_launcher_icons.
version: 1.0.0+1

environment:
sdk: ">=2.13.0 <3.0.0"
sdk: ">=2.17.0 <3.0.0"

dependencies:
flutter:
Expand All @@ -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
2 changes: 1 addition & 1 deletion example/flavors/flutter_launcher_icons-development.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flutter_icons:
flutter_launcher_icons:
android: true
ios: true
image_path: "assets/launcher_icon/demo-icon-dev.png"
2 changes: 1 addition & 1 deletion example/flavors/flutter_launcher_icons-integration.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flutter_icons:
flutter_launcher_icons:
android: true
ios: true
image_path: "assets/launcher_icon/demo-icon-int.png"
2 changes: 1 addition & 1 deletion example/flavors/flutter_launcher_icons-production.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flutter_icons:
flutter_launcher_icons:
android: true
ios: true
image_path: "assets/launcher_icon/demo-icon.png"
11 changes: 7 additions & 4 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 Expand Up @@ -111,7 +114,7 @@ void generateIconsFor({
}
}
} catch (e, st) {
// todo: better error handling
// TODO(RatakondalaArun): better error handling
// stacktrace should only print when verbose is turned on
// else a normal help line
logger
Expand Down
Loading

0 comments on commit 281edaa

Please sign in to comment.