fluttercommunity / flutter_launcher_icons

Flutter Launcher Icons - A package 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. Maintainer: @MarkOSullivan94

Home Page:https://pub.dev/packages/flutter_launcher_icons

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] printStatus not using configured logger

vanlooverenkoen opened this issue · comments

ℹ️ Info

Version: 0.13.1

💬 Description

void printStatus(String message) {
  print('• $message');
}

printStatus will just print to the console even if another Logger is configured. This makes it hard to disable logs. For a dart script where we want to have control over the output. So we can show data to the user that is usefull.

This is the output I see:

• Creating default icons Android
• Overwriting the default Android launcher icon with a new icon
• Creating mipmap xml file Android
• Overwriting default iOS launcher icon with new icon

with this code:

final flutterConfig = Config(
   imagePath: 'app_icon.png',
   android: true,
   ios: true,
   removeAlphaIOS: true,
);
await createIconsFromConfig(flutterConfig, FLILogger(false), '.');

Expected behaviour:

printStatus should use the FLILogger instead of using print.

It would also be nice to have the option to set a NoopLogger. (which I created myself to disable all logs)

class NoopLogger implements FLILogger {
  NoopLogger();

  @override
  void error(Object? message) {}

  @override
  void info(Object? message) {}

  @override
  bool get isVerbose => false;

  @override
  Progress progress(String message) => NoopProgress(message);

  @override
  Logger get rawLogger => Logger.verbose();

  @override
  void verbose(Object? message) {}
}

class NoopProgress implements Progress {
  final String _message;

  late final DateTime _dateTime;

  NoopProgress(this._message) {
    _dateTime = DateTime.now();
  }
  @override
  void cancel() {}

  @override
  Duration get elapsed => _dateTime.difference(DateTime.now());

  @override
  void finish({String? message, bool showTiming = false}) {}

  @override
  String get message => _message;
}

📜 Pubspec.yaml

No dependencies.

Workaround but not a fix

Override the printToZone meaning we have to runZoned in order to override the print.

      runZoned(() {
        final flutterConfig = Config(
          imagePath: 'app_icon.png',
          android: true,
          ios: true,
          removeAlphaIOS: true,
        );
        await createIconsFromConfig(flutterConfig, FLILogger(false), '.');
      }, zoneSpecification: ZoneSpecification(print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
         // skip the logs or do something custom
      }));