Skip to content

Commit

Permalink
docs: added documentation and disabled linter for some files
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkOSullivan94 committed Feb 24, 2023
1 parent 1749b94 commit 323cbff
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Expand Up @@ -20,6 +20,7 @@ analyzer:
- "lib/src/http/**"
- "example/**"
- "**/*.g.dart"
- "lib/src/version.dart"

linter:
rules:
Expand Down
2 changes: 1 addition & 1 deletion lib/abs/icon_generator.dart
Expand Up @@ -111,7 +111,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
7 changes: 5 additions & 2 deletions lib/android.dart
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'dart:io';

import 'package:flutter_launcher_icons/constants.dart';
Expand Down Expand Up @@ -37,7 +39,7 @@ void createDefaultIcons(
String? flavor,
) {
utils.printStatus('Creating default icons Android');
// todo: support prefixPath
// TODO(p-mazhnik): support prefixPath
final String? filePath = flutterLauncherIconsConfig.getImagePathAndroid();
if (filePath == null) {
throw const InvalidConfigException(errorMissingImagePath);
Expand Down Expand Up @@ -139,7 +141,8 @@ void updateColorsXmlFile(String backgroundConfig, String? flavor) {
final File colorsXml = File(constants.androidColorsFile(flavor));
if (colorsXml.existsSync()) {
utils.printStatus(
'Updating colors.xml with color for adaptive icon background');
'Updating colors.xml with color for adaptive icon background',
);
updateColorsFile(colorsXml, backgroundConfig);
} else {
utils.printStatus('No colors.xml file found in your Android project');
Expand Down
4 changes: 3 additions & 1 deletion lib/constants.dart
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'package:path/path.dart' as path;

/// Relative path to android resource folder
Expand Down Expand Up @@ -44,7 +46,7 @@ String webIconsDirPath = path.join(webDirPath, 'icons');

/// Relative web manifest.json file path
String webManifestFilePath = path.join(webDirPath, 'manifest.json');
// todo: support for other images formats
// TODO(RatakondalaArun): support for other images formats
/// Relative favicon.png path
String webFaviconFilePath = path.join(webDirPath, 'favicon.png');

Expand Down
20 changes: 16 additions & 4 deletions lib/custom_exceptions.dart
@@ -1,7 +1,10 @@
import 'package:flutter_launcher_icons/utils.dart';

class InvalidAndroidIconNameException implements Exception {
const InvalidAndroidIconNameException([this.message]);
/// Exception to be thrown whenever we have an invalid configuration
class InvalidConfigException implements Exception {
/// Constructs instance
const InvalidConfigException([this.message]);
/// Message for the exception
final String? message;

@override
Expand All @@ -10,8 +13,11 @@ class InvalidAndroidIconNameException implements Exception {
}
}

class InvalidConfigException implements Exception {
const InvalidConfigException([this.message]);
/// Exception to be thrown whenever using an invalid Android icon name
class InvalidAndroidIconNameException implements Exception {
/// Constructs instance of this exception
const InvalidAndroidIconNameException([this.message]);
/// Message for the exception
final String? message;

@override
Expand All @@ -20,8 +26,11 @@ class InvalidConfigException implements Exception {
}
}

/// Exception to be thrown whenever no config is found
class NoConfigFoundException implements Exception {
/// Constructs instance of this exception
const NoConfigFoundException([this.message]);
/// Message for the exception
final String? message;

@override
Expand All @@ -30,8 +39,11 @@ class NoConfigFoundException implements Exception {
}
}

/// Exception to be thrown whenever there is no decoder for the image format
class NoDecoderForImageFormatException implements Exception {
/// Constructs instance of this exception
const NoDecoderForImageFormatException([this.message]);
/// Message for the exception
final String? message;

@override
Expand Down
11 changes: 8 additions & 3 deletions lib/flutter_launcher_icons_config.dart
Expand Up @@ -82,6 +82,7 @@ class FlutterLauncherIconsConfig {
factory FlutterLauncherIconsConfig.fromJson(Map json) =>
_$FlutterLauncherIconsConfigFromJson(json);

/// whether or not there is configuration for adaptive icons for android
bool get hasAndroidAdaptiveConfig =>
isNeedingNewAndroidIcon &&
adaptiveIconForeground != null &&
Expand All @@ -101,16 +102,20 @@ class FlutterLauncherIconsConfig {
/// bool - override the default flutter project icon
bool get isCustomAndroidFile => android is String;

/// if we are needing a new Android icon
bool get isNeedingNewAndroidIcon => android != false;

/// if we are needing a new iOS icon
bool get isNeedingNewIOSIcon => ios != false;

/// Method for the retrieval of the Android icon path
/// If image_path_android is found, this will be prioritised over the image_path
/// value.
String? getImagePathAndroid() => imagePathAndroid ?? imagePath;
// todo: refactor after Android & iOS configs will be refactored to the new schema

// TODO(RatakondalaArun): refactor after Android & iOS configs will be refactored to the new schema
// https://github.com/fluttercommunity/flutter_launcher_icons/issues/394
/// get the image path for IOS
String? getImagePathIOS() => imagePathIOS ?? imagePath;

/// Converts config to [Map]
Expand Down Expand Up @@ -144,7 +149,7 @@ class FlutterLauncherIconsConfig {
return yaml.checkedYamlDecode<FlutterLauncherIconsConfig?>(
configContent,
(json) {
// todo: add support for new scheme https://github.com/fluttercommunity/flutter_launcher_icons/issues/373
// TODO(RatakondalaArun): add support for new scheme https://github.com/fluttercommunity/flutter_launcher_icons/issues/373
return json == null || json['flutter_icons'] == null
? null
: FlutterLauncherIconsConfig.fromJson(json['flutter_icons']);
Expand All @@ -169,7 +174,7 @@ class FlutterLauncherIconsConfig {
return yaml.checkedYamlDecode<FlutterLauncherIconsConfig?>(
pubspecContent,
(json) {
// todo: add support for new scheme https://github.com/fluttercommunity/flutter_launcher_icons/issues/373
// TODO(RatakondalaArun): add support for new scheme https://github.com/fluttercommunity/flutter_launcher_icons/issues/373
return json == null || json['flutter_icons'] == null
? null
: FlutterLauncherIconsConfig.fromJson(json['flutter_icons']);
Expand Down
12 changes: 11 additions & 1 deletion lib/ios.dart
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'dart:convert';
import 'dart:io';

Expand All @@ -9,12 +11,16 @@ import 'package:image/image.dart';

/// File to handle the creation of icons for iOS platform
class IosIconTemplate {
/// constructs an instance of [IosIconTemplate]
IosIconTemplate({required this.size, required this.name});

/// suffix of the icon name
final String name;
/// the size of the icon
final int size;
}

/// details of the ios icons which need to be generated
List<IosIconTemplate> iosIcons = <IosIconTemplate>[
IosIconTemplate(name: '-20x20@1x', size: 20),
IosIconTemplate(name: '-20x20@2x', size: 40),
Expand All @@ -39,8 +45,9 @@ List<IosIconTemplate> iosIcons = <IosIconTemplate>[
IosIconTemplate(name: '-1024x1024@1x', size: 1024),
];

/// create the ios icons
void createIcons(FlutterLauncherIconsConfig config, String? flavor) {
// todo: support prefixPath
// TODO(p-mazhnik): support prefixPath
final String? filePath = config.getImagePathIOS();
if (filePath == null) {
throw const InvalidConfigException(errorMissingImagePath);
Expand Down Expand Up @@ -116,6 +123,7 @@ void saveNewIcons(IosIconTemplate template, Image image, String newIconName) {
});
}

/// create resized icon image
Image createResizedImage(IosIconTemplate template, Image image) {
if (image.width >= template.size) {
return copyResize(
Expand All @@ -134,6 +142,7 @@ Image createResizedImage(IosIconTemplate template, Image image) {
}
}

/// Change the iOS launcher icon
Future<void> changeIosLauncherIcon(String iconName, String? flavor) async {
final File iOSConfigFile = File(iosConfigFile);
final List<String> lines = await iOSConfigFile.readAsLines();
Expand Down Expand Up @@ -186,6 +195,7 @@ String generateContentsFileAsString(String newIconName) {
return json.encode(contentJson);
}


class ContentsImageObject {
ContentsImageObject({
required this.size,
Expand Down
5 changes: 4 additions & 1 deletion lib/main.dart
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'dart:io';

import 'package:args/args.dart';
Expand All @@ -14,6 +16,7 @@ import 'package:flutter_launcher_icons/web/web_icon_generator.dart';
import 'package:flutter_launcher_icons/windows/windows_icon_generator.dart';
import 'package:path/path.dart' as path;


const String fileOption = 'file';
const String helpFlag = 'help';
const String verboseFlag = 'verbose';
Expand Down Expand Up @@ -153,7 +156,7 @@ Future<void> createIconsFromConfig(
WebIconGenerator(context),
WindowsIconGenerator(context),
MacOSIconGenerator(context),
// todo: add other platforms
// TODO(RatakondalaArun): add other platforms
],
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/utils.dart
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'dart:convert';
import 'dart:io';

Expand Down
10 changes: 1 addition & 9 deletions lib/web/web_icon_generator.dart
Expand Up @@ -75,7 +75,7 @@ class WebIconGenerator extends IconGenerator {
);
_updateManifestFile();

// todo: update index.html in web/index.html
// TODO(RatakondalaArun): update index.html in web/index.html
// as we are using flutter default config we no need
// to update index.html for now
// _updateIndexFile();
Expand Down Expand Up @@ -138,14 +138,6 @@ class WebIconGenerator extends IconGenerator {
}
}

// void _updateIndexFile() {
// todo
// final indexFile = File(constants.webIndexFilePath);
// if (!indexFile.existsSync()) {
// throw FileNotFoundException(constants.webFaviconFilePath);
// }
// }

void _updateManifestFile() {
final manifestFile = utils.createFileIfNotExist(
path.join(context.prefixPath, constants.webManifestFilePath),
Expand Down
2 changes: 2 additions & 0 deletions lib/xml_templates.dart
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

const String icLauncherXml = '''
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
Expand Down

0 comments on commit 323cbff

Please sign in to comment.