AngeloAvv / flutter_flavorizr

A flutter utility to easily create flavors in your flutter application
https://pub.dev/packages/flutter_flavorizr
MIT License
428 stars 76 forks source link

Add Contents.json file to icon set #266

Open vinifig opened 3 weeks ago

vinifig commented 3 weeks ago

Expected with contents.json:

image image

Actual without contents.json:

image

Causing:

image
dragongesa commented 3 weeks ago

+1

vinifig commented 3 weeks ago

Temporarily I've made this script with many more to adjust flavorizr to our internal processes and necessities:

import 'dart:io';

import 'package:flutter_flavorizr/src/parser/parser.dart';
import 'package:yaml/yaml.dart';

Future<void> main() async {
  await _fixLaunchIcons();
}

List<FlavorizrData> getFlavorizrData() {
  Parser parser = const Parser(
    pubspecPath: 'pubspec.yaml',
    flavorizrPath: flavorizrPath,
  );

  final config = parser.parse();
  return config.flavors.entries.map(_extractFlavorData).toList();
}

Future<void> _fixLaunchIcons() async {
  final flavors = getFlavorizrData();
  final contentsJSON = await File(
    'ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json',
  ).readAsString();
  for (final flavor in flavors) {
    final flavorName = flavor.name;
    await File(
      'ios/Runner/Assets.xcassets/${flavorName}AppIcon.appiconset/Contents.json',
    ).writeAsString(contentsJSON);
  }
}

if it's of any help to any of you, run it after running flavorizr (be it on the ci or your local machine that will solve your problem whilst it's not fixed on the lib)