The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.

Overview

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.

Inspired by SwiftGen.

Motivation

Using asset path string directly is not safe.

# pubspec.yaml
flutter:
  assets:
    - assets/images/profile.jpg

Bad
What would happen if you made a typo?

Widget build(BuildContext context) {
  return Image.asset('assets/images/profile.jpeg');
}

// The following assertion was thrown resolving an image codec:
// Unable to load asset: assets/images/profile.jpeg

⭕️ Good
We want to use it safely.

Widget build(BuildContext context) {
  return Assets.images.profile.image();
}

Installation

Homebrew

Works with MacOS and Linux.

$ brew install FlutterGen/tap/fluttergen

Pub Global

Works with MacOS, Linux and Windows.

$ dart pub global activate flutter_gen

You might need to set up your path.

As a part of build_runner

  1. Add build_runner and FlutterGen to your package's pubspec.yaml file:
dev_dependencies:
  build_runner:
  flutter_gen_runner:
  1. Install FlutterGen
$ flutter pub get
  1. Use FlutterGen
$ flutter packages pub run build_runner build

Usage

Run fluttergen after the configuration pubspec.yaml.

$ fluttergen -h

$ fluttergen -c example/pubspec.yaml

Configuration file

FlutterGen generates dart files based on the key flutter and flutter_gen of pubspec.yaml.

# pubspec.yaml
# ...

flutter_gen:
  output: lib/gen/ # Optional (default: lib/gen/)
  line_length: 80 # Optional (default: 80)

  # Optional
  integrations:
    flutter_svg: true
    flare_flutter: true

  colors:
    inputs:
      - assets/color/colors.xml

flutter:
  uses-material-design: true
  assets:
    - assets/images/

  fonts:
    - family: Raleway
      fonts:
        - asset: assets/fonts/Raleway-Regular.ttf
        - asset: assets/fonts/Raleway-Italic.ttf
          style: italic

Available Parsers

Assets

Just follow the doc Adding assets and images#Specifying assets to specify assets, then FlutterGen will generate related dart files.
No other specific configuration is required.
Ignore duplicated.

# pubspec.yaml
flutter:
  assets:
    - assets/images/
    - assets/images/chip3/chip.jpg
    - assets/images/chip4/chip.jpg
    - assets/images/icons/paint.svg
    - assets/json/fruits.json
    - assets/flare/Penguin.flr
    - pictures/ocean_view.jpg

These configurations will generate assets.gen.dart under the lib/gen/ directory by default.

Usage Example

FlutterGen generates Image class if the asset is Flutter supported image format.

Example results of assets/images/chip.jpg:

  • Assets.images.chip is an implementation of AssetImage class.
  • Assets.images.chip.image(...) returns Image class.
  • Assets.images.chip.path just returns the path string.
Widget build(BuildContext context) {
  return Image(image: Assets.images.chip);
}

Widget build(BuildContext context) {
  return Assets.images.chip.image(
    width: 120,
    height: 120,
    fit: BoxFit.scaleDown,
  );

Widget build(BuildContext context) {
  // Assets.images.chip.path = 'assets/images/chip3/chip3.jpg'
  return Image.asset(Assets.images.chip.path);
}

If you are using SVG images with flutter_svg you can use the integration feature.

# pubspec.yaml
flutter_gen:
  integrations:
    flutter_svg: true

flutter:
  assets:
    - assets/images/icons/paint.svg
Widget build(BuildContext context) {
  return Assets.images.icons.paint.svg(
    width: 120,
    height: 120
  );
}

Available Integrations

Packages File extension Setting Usage
flutter_svg .svg flutter_svg: true Assets.images.icons.paint.svg()
flare_flutter .flr flare_flutter: true Assets.flare.penguin.flare()

In other cases, the asset is generated as String class.

// If don't use the Integrations.
final svg = SvgPicture.asset(Assets.images.icons.paint);

final json = await rootBundle.loadString(Assets.json.fruits);

FlutterGen also support generating other style of Assets class:

# pubspec.yaml
flutter_gen:
  assets:
    # Assets.imagesChip
    # style: camel-case

    # Assets.images_chip
    # style: snake-case

    # Assets.images.chip (default style)
    # style: dot-delimiter

flutter:
  assets:
    - assets/images/chip.png

The root directory will be omitted if it is either assets or asset.

assets/images/chip3/chip.jpg  => Assets.images.chip3.chip
assets/images/chip4/chip.jpg  => Assets.images.chip4.chip
assets/images/icons/paint.svg => Assets.images.icons.paint
assets/json/fruits.json       => Assets.json.fruits
pictures/ocean_view.jpg       => Assets.pictures.oceanView
Example of code generated by FlutterGen

/// GENERATED CODE - DO NOT MODIFY BY HAND
/// *****************************************************
///  FlutterGen
/// *****************************************************

import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter/services.dart';
import 'package:flare_flutter/flare_actor.dart';
import 'package:flare_flutter/flare_controller.dart';

class $PicturesGen {
  const $PicturesGen();

  AssetGenImage get chip5 => const AssetGenImage('pictures/chip5.jpg');
}

class $AssetsFlareGen {
  const $AssetsFlareGen();

  FlareGenImage get penguin => const FlareGenImage('assets/flare/Penguin.flr');
}

class $AssetsImagesGen {
  const $AssetsImagesGen();

  AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg');
  AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
  $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen();
  $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
  $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();
  AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
  AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
}

class $AssetsJsonGen {
  const $AssetsJsonGen();

  String get fruits => 'assets/json/fruits.json';
}

class $AssetsMovieGen {
  const $AssetsMovieGen();

  String get theEarth => 'assets/movie/the_earth.mp4';
}

class $AssetsUnknownGen {
  const $AssetsUnknownGen();

  String get unknownMimeType => 'assets/unknown/unknown_mime_type.bk';
}

class $AssetsImagesChip3Gen {
  const $AssetsImagesChip3Gen();

  AssetGenImage get chip3 =>
      const AssetGenImage('assets/images/chip3/chip3.jpg');
}

class $AssetsImagesChip4Gen {
  const $AssetsImagesChip4Gen();

  AssetGenImage get chip4 =>
      const AssetGenImage('assets/images/chip4/chip4.jpg');
}

class $AssetsImagesIconsGen {
  const $AssetsImagesIconsGen();

  SvgGenImage get fuchsia =>
      const SvgGenImage('assets/images/icons/fuchsia.svg');
  SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg');
  SvgGenImage get paint => const SvgGenImage('assets/images/icons/paint.svg');
}

class Assets {
  Assets._();

  static const $AssetsFlareGen flare = $AssetsFlareGen();
  static const $AssetsImagesGen images = $AssetsImagesGen();
  static const $AssetsJsonGen json = $AssetsJsonGen();
  static const $AssetsMovieGen movie = $AssetsMovieGen();
  static const $AssetsUnknownGen unknown = $AssetsUnknownGen();
  static const $PicturesGen pictures = $PicturesGen();
}

class AssetGenImage extends AssetImage {
  const AssetGenImage(String assetName)
      : _assetName = assetName,
        super(assetName);
  final String _assetName;

  Image image({
    Key key,
    ImageFrameBuilder frameBuilder,
    ImageLoadingBuilder loadingBuilder,
    ImageErrorWidgetBuilder errorBuilder,
    String semanticLabel,
    bool excludeFromSemantics = false,
    double width,
    double height,
    Color color,
    BlendMode colorBlendMode,
    BoxFit fit,
    AlignmentGeometry alignment = Alignment.center,
    ImageRepeat repeat = ImageRepeat.noRepeat,
    Rect centerSlice,
    bool matchTextDirection = false,
    bool gaplessPlayback = false,
    bool isAntiAlias = false,
    FilterQuality filterQuality = FilterQuality.low,
  }) {
    return Image(
      key: key,
      image: this,
      frameBuilder: frameBuilder,
      loadingBuilder: loadingBuilder,
      errorBuilder: errorBuilder,
      semanticLabel: semanticLabel,
      excludeFromSemantics: excludeFromSemantics,
      width: width,
      height: height,
      color: color,
      colorBlendMode: colorBlendMode,
      fit: fit,
      alignment: alignment,
      repeat: repeat,
      centerSlice: centerSlice,
      matchTextDirection: matchTextDirection,
      gaplessPlayback: gaplessPlayback,
      isAntiAlias: isAntiAlias,
      filterQuality: filterQuality,
    );
  }

  String get path => _assetName;
}

class SvgGenImage {
  const SvgGenImage(this._assetName);

  final String _assetName;

  SvgPicture svg({
    Key key,
    bool matchTextDirection = false,
    AssetBundle bundle,
    String package,
    double width,
    double height,
    BoxFit fit = BoxFit.contain,
    AlignmentGeometry alignment = Alignment.center,
    bool allowDrawingOutsideViewBox = false,
    WidgetBuilder placeholderBuilder,
    Color color,
    BlendMode colorBlendMode = BlendMode.srcIn,
    String semanticsLabel,
    bool excludeFromSemantics = false,
    Clip clipBehavior = Clip.hardEdge,
  }) {
    return SvgPicture.asset(
      _assetName,
      key: key,
      matchTextDirection: matchTextDirection,
      bundle: bundle,
      package: package,
      width: width,
      height: height,
      fit: fit,
      alignment: alignment,
      allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
      placeholderBuilder: placeholderBuilder,
      color: color,
      colorBlendMode: colorBlendMode,
      semanticsLabel: semanticsLabel,
      excludeFromSemantics: excludeFromSemantics,
      clipBehavior: clipBehavior,
    );
  }

  String get path => _assetName;
}

class FlareGenImage {
  const FlareGenImage(this._assetName);

  final String _assetName;

  FlareActor flare({
    String boundsNode,
    String animation,
    BoxFit fit = BoxFit.contain,
    Alignment alignment = Alignment.center,
    bool isPaused = false,
    bool snapToEnd = false,
    FlareController controller,
    FlareCompletedCallback callback,
    Color color,
    bool shouldClip = true,
    bool sizeFromArtboard = false,
    String artboard,
    bool antialias = true,
  }) {
    return FlareActor(
      _assetName,
      boundsNode: boundsNode,
      animation: animation,
      fit: fit,
      alignment: alignment,
      isPaused: isPaused,
      snapToEnd: snapToEnd,
      controller: controller,
      callback: callback,
      color: color,
      shouldClip: shouldClip,
      sizeFromArtboard: sizeFromArtboard,
      artboard: artboard,
      antialias: antialias,
    );
  }

  String get path => _assetName;
}

Fonts

Just follow the doc Use a custom font to specify fonts, then FlutterGen will generate related dart files.
No other specific configuration is required.
Ignore duplicated.

# pubspec.yaml
flutter:
  fonts:
    - family: Raleway
      fonts:
        - asset: assets/fonts/Raleway-Regular.ttf
        - asset: assets/fonts/Raleway-Italic.ttf
          style: italic
    - family: RobotoMono
      fonts:
        - asset: assets/fonts/RobotoMono-Regular.ttf
        - asset: assets/fonts/RobotoMono-Bold.ttf
          weight: 700

These configurations will generate fonts.gen.dart under the lib/gen/ directory by default.

Usage Example

Text(
  'Hi there, I\'m FlutterGen',
  style: TextStyle(
    fontFamily: FontFamily.robotoMono,
    fontFamilyFallback: const [FontFamily.raleway],
  ),
Example of code generated by FlutterGen

/// GENERATED CODE - DO NOT MODIFY BY HAND
/// *****************************************************
///  FlutterGen
/// *****************************************************

class FontFamily {
  FontFamily._();

  static const String raleway = 'Raleway';
  static const String robotoMono = 'RobotoMono';
}

Colors

FlutterGen supports generating colors from XML format files.
Ignore duplicated.

# pubspec.yaml
flutter_gen:
  colors:
    inputs:
      - assets/color/colors.xml
      - assets/color/colors2.xml

FlutterGen can generate a Color class based on the name attribute and the color hex value. If the element has the attribute type, then a specially color will be generated.

Currently supported special color types:

Noticed that there is no official material color generation algorithm. The implementation is based on the mcg project.

<color name="milk_tea">#F5CB84</color>
<color name="cinnamon" type="material">#955E1C</color>
<color name="yellow_ocher" type="material material-accent">#DF9527</color>

These configurations will generate colors.gen.dart under the lib/gen/ directory by default.

Usage Example

Text(
  'Hi there, I\'m FlutterGen',
  style: TextStyle(
    color: ColorName.denim,
  ),
Example of code generated by FlutterGen

/// GENERATED CODE - DO NOT MODIFY BY HAND
/// *****************************************************
///  FlutterGen
/// *****************************************************

import 'package:flutter/painting.dart';
import 'package:flutter/material.dart';

class ColorName {
  ColorName._();

  static const Color black = Color(0xFF000000);
  static const Color black30 = Color(0x4D000000);
  static const Color black40 = Color(0x66000000);
  static const Color black50 = Color(0x80000000);
  static const Color black60 = Color(0x99000000);
  static const MaterialColor crimsonRed = MaterialColor(
    0xFFCF2A2A,
    <int, Color>{
      50: Color(0xFFF9E5E5),
      100: Color(0xFFF1BFBF),
      200: Color(0xFFE79595),
      300: Color(0xFFDD6A6A),
      400: Color(0xFFD64A4A),
      500: Color(0xFFCF2A2A),
      600: Color(0xFFCA2525),
      700: Color(0xFFC31F1F),
      800: Color(0xFFBD1919),
      900: Color(0xFFB20F0F),
    },
  );
  static const Color gray410 = Color(0xFF979797);
  static const Color gray70 = Color(0xFFEEEEEE);
  static const Color white = Color(0xFFFFFFFF);
  static const MaterialColor yellowOcher = MaterialColor(
    0xFFDF9527,
    <int, Color>{
      50: Color(0xFFFBF2E5),
      100: Color(0xFFF5DFBE),
      200: Color(0xFFEFCA93),
      300: Color(0xFFE9B568),
      400: Color(0xFFE4A547),
      500: Color(0xFFDF9527),
      600: Color(0xFFDB8D23),
      700: Color(0xFFD7821D),
      800: Color(0xFFD27817),
      900: Color(0xFFCA670E),
    },
  );
  static const MaterialAccentColor yellowOcherAccent = MaterialAccentColor(
    0xFFFFBCA3,
    <int, Color>{
      100: Color(0xFFFFE8E0),
      200: Color(0xFFFFBCA3),
      400: Color(0xFFFFA989),
      700: Color(0xFFFF9E7A),
    },
  );
}

Default Settings

The following are the default settings. The options you set in pubspec.yaml will override the corresponding default options.

flutter_gen:
  output: lib/gen/
  line_length: 80

  integrations:
    flutter_svg: false
    flare_flutter: false

  assets:
    enabled: true
    style: dot-delimiter
    
  fonts:
    enabled: true

  colors:
    enabled: true
    inputs: []

flutter:
  assets: []
  fonts: []

Credits

The material color generation implementation is based on mcg and TinyColor.

Issues

Please file FlutterGen specific issues, bugs, or feature requests in our issue tracker.

Plugin issues that are not specific to FlutterGen can be filed in the Flutter issue tracker.

Contributing

We are looking for co-developers.

If you wish to contribute a change to any of the existing plugins in this repo, please review our contribution guide and open a pull request.

Comments
  • [BUG]: The path of assets is not correct

    [BUG]: The path of assets is not correct

    Is there an existing issue for this?

    • [X] I have searched the existing issues

    Version

    No response

    Command type

    Dart command

    What happened?

    The plugin of svg, lottie, flare and rive generate the wrong path of the related assets. I have raised a PR https://github.com/FlutterGen/flutter_gen/pull/321. Not sure if it is a bug. If I am wrong, I think we can add a feature to show the correct path of assets under packages. :)

    Relevant a pubspec.yaml.

    No response

    Relevant log output

    No response

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    bug 
    opened by jinaiyuanbaojie 16
  • NoSuchMethodError: The method 'cast' was called on null.

    NoSuchMethodError: The method 'cast' was called on null.

    hi, I can't generate asset, maybe cause by code error. image Dart SDK version: 2.9.0-21.10.beta (beta) (Tue Jul 21 10:46:30 2020 +0200) on "windows_x64"

    opened by blue7wings 8
  • how to get only String for image

    how to get only String for image

    now i get

       static const AssetGenImage imagesChip1 = 
           AssetGenImage('assets/images/chip1.jpg'); 
    

    i want this

     static const String imagesChip1 = 
           'assets/images/chip1.jpg'; 
    

    if image path string is AssetGenImage i can't make the widget const

    opened by samithe7 7
  • Add Lottie integration

    Add Lottie integration

    What does this change?

    • Adds lottie integration.

    • Checks for lottie files by in json tags

    • Example includes on how to use it

    • Docs changed accordingly

    Related

    Initial Feature Request: https://github.com/FlutterGen/flutter_gen/issues/47 Previous PR that tried to introduce support for Lottie: https://github.com/FlutterGen/flutter_gen/pull/70

    What's different now?

    Previously HiroyukiTamura https://github.com/FlutterGen/flutter_gen/pull/70 implemented a Lottie integration per request https://github.com/FlutterGen/flutter_gen/issues/47#issuecomment-1151910798 but as stated by britannio's https://github.com/FlutterGen/flutter_gen/pull/70#issuecomment-769968336 in the initial PR, their implementation will be better off checking for keys in the file itself, rather than only it's extension *_lottie.json as it was initially requested two years ago.

    So I did.

    Other issues

    Why there is a lot of changes to tests

    Initially Implementation of this feature required File read access, there was no issues with that if you run code as designed e.g

    flutter packages pub run build_runner build
    

    But if you try to run tests you might ended up seeing that the relative asset path that you get in isSupport is not relative to the Directory.current.path and the code in 'packages/core/lib' can't access it while running tests.

    So I introduced mocked rootPath #assets_gen_integrations_test.dart#L13 for tests and now the AssetType has field for absolutePath that is constructed from the passed rootPath (config.rootPath) and the key/path. Other integrations haven't tried to read files, cause they don't need it, so here we are, feel free to propose a better solution.

    What is the value of this and can you measure success?

    Measure

    • Pass tests.

    • No linting issues with generated code.

    • Example runs, plays the animation and works well.

    Value

    • Others who tends to use Lottie in their projects will be happy to know that flutter_gen supports it
    opened by onlymice 6
  • Added 'gen_for_package:true/false' param to support asset generation for a package

    Added 'gen_for_package:true/false' param to support asset generation for a package

    Why fix is required?

    Currently if we use fluttergen then the asset path generated won't work for packages as it expects assets path from packages/<package_name>/<asset_path>

    What is changed/added?

    Added flutter package support:

    • By added gen_for_package:true to the fluttergen config it will generate assets with path that can be resolved in a package.
    opened by urvesh-open 6
  • Extending package information to asset types other than AssetGenImage.

    Extending package information to asset types other than AssetGenImage.

    As for now the package information is only passed to the AssetGenImage class as a parameter.

    This PR extends the package information to other asset types.

    opened by abelokon0711 6
  • gen runner fails with Bad state: No element

    gen runner fails with Bad state: No element

    The current version of flutter_gen_runner failes with the following error:

    [SEVERE] flutter_gen_runner:flutter_gen_runner on $package$ (cached):
    
    Bad state: No element
    [SEVERE] Failed after 16.0s
    

    Running the build runner in verbose mode does not reveal anything else about the error.

    I tried deleting all image and font assets, but that did not fix the problem, so it seems it has nothing to do with a broken file or something like that. I attached the pubspec and lockfile of the project for reference.

    pubspec.yaml.txt pubspec.lock.txt

    opened by felix-barz-brickmakers 5
  • Make default scale value null so that Flutter decides the one to use

    Make default scale value null so that Flutter decides the one to use

    If you have an image with different resolution variants:

    assets/images/myImage.png
    assets/images/2.0x/myImage.png
    assets/images/3.0x/myImage.png
    

    At the moment, if you use the generated image() method with the default parameters. Eg:

    Assets.images.myImage.image()
    

    It will always use assets/images/myImage.png independently of the pixel ratio of the device. This happens because the default parameter of scale is 1.0:

    Image image({
        Key? key,
        AssetBundle? bundle,
        ImageFrameBuilder? frameBuilder,
        ImageErrorWidgetBuilder? errorBuilder,
        String? semanticLabel,
        bool excludeFromSemantics = false,
        double? scale = 1.0, // <-- THIS
        //...
    })
    

    To workaround this issue at the moment you always have to set scale to null:

    Assets.images.myImage.image(scale: null)
    

    Proposed fix: I believe the default value of scale should not be 1.0 but null as it is in the Flutter's Image.asset constructor.

    opened by davidmigloz 5
  • Fluttergen v4.1.5 on Homebrew has

    Fluttergen v4.1.5 on Homebrew has "SHA256 mismatch" error

    ❯ brew install fluttergen
    ==> Downloading https://github.com/FlutterGen/flutter_gen/releases/download/v4.1.5/fluttergen-macos.tar.gz
    ==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/289226906/f1c85a7e-da86-4494-a1b1-5b21de949
    ######################################################################## 100.0%
    Error: fluttergen: SHA256 mismatch
    Expected: a83d283440fc90fbb828f1ace7be60bdb61a265c6b8b408738e8419b3d460b3d
      Actual: 918e4c3db67b4997819100fd1017456c2a19f37e6ce17b26583cf001ed089821
        File: /Users/someone/Library/Caches/Homebrew/downloads/36470e4795412f8a64492be2516a8bffad6b93fe813d4f1a286f598562d0b344--fluttergen-macos.tar.gz
    To retry an incomplete download, remove the file above.
    

    Have tested several Homebrew environments on different machines to validate the same behavior.

    ❯ brew info fluttergen
    fluttergen/tap/fluttergen: stable v4.1.5
    A command-line tool for The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs. by Dart.
    https://github.com/FlutterGen/flutter_gen
    Not installed
    From: https://github.com/fluttergen/homebrew-tap/blob/HEAD/Formula/fluttergen.rb
    
    opened by themartorana 5
  • Optional Nullability

    Optional Nullability

    First of all, amazing tool! Use it on the daily!

    Is there a way to tell the tool not to generate dart 2.12 optional fields? Many of my projects are still on non null-sound libraries, it's quite tedious to go and delete all the ? every time the tool runs

    opened by cesarferreira 5
  • update json_annotation dependency

    update json_annotation dependency

    When I run "pub get" appears this error

    Because flutter_gen >=2.0.1 <2.0.2 depends on flutter_gen_core ^2.0.1 and flutter_gen >=2.0.2 depends on flutter_gen_core ^2.0.2, flutter_gen >=2.0.1 requires flutter_gen_core ^2.0.1.
    And because flutter_gen_core >=2.0.1-dev.0 depends on json_annotation ^3.1.0, flutter_gen >=2.0.1 requires json_annotation ^3.1.0.
    So, because your_project depends on both json_annotation ^4.0.0 and flutter_gen ^2.0.1, version solving failed.
    

    Can you please update the dependency?

    opened by EmanueleVinci 5
  • ignore invalid asset names

    ignore invalid asset names

    What does this change?

    Ignore assets that has invalid name (start with number, equal a dart keyword,...)

    Type of change

    Please delete options that are not relevant.

    • [x] Bug fix (non-breaking change which fixes an issue)

    Checklist:

    Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

    • [x] Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
      • [x] Ensure the tests (melos run unit:test)
      • [x] Ensure the analyzer and formatter pass (melos run format to automatically apply formatting)
    opened by ankiimation 0
  • [BUG]: Cannot generate colors

    [BUG]: Cannot generate colors

    Is there an existing issue for this?

    • [X] I have searched the existing issues

    Version

    5.1.0+1

    Command type

    build_runner (Default)

    What happened?

    First time checking out this package.

    Attempting to run with the following colors file (taken from the example dir)

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="white">#FFFFFF</color>
        <color name="black">#000000</color>
        <color name="gray_70">#EEEEEE</color>
        <color name="gray_410">#979797</color>
        <color name="crimson_red" type="material">#CF2A2A</color>
        <color name="yellow_ocher" type="material material-accent">#DF9527</color>
    </resources>
    

    throws

    Unhandled exception:
    FormatException: Invalid radix-16 number (at line 2, character 2)
    

    Not sure what I'm doing wrong here or if it's a legitimate bug 🤷

    Relevant a pubspec.yaml.

    name: theme_x
    version: 0.1.0+1
    publish_to: none
    
    environment:
      sdk: '>=2.18.0 <3.0.0'
      flutter: 3.3.8
    
    dependencies:
      flutter:
        sdk: flutter
    
    dev_dependencies:
      build_runner: ^2.3.3
      flutter_gen_runner: ^5.1.0+1
      flutter_test:
        sdk: flutter
      very_good_analysis: ^3.1.0
    
    flutter_gen:
      colors:
        inputs:
          - assets/colors/colors.xml
    
    flutter:
      uses-material-design: true # Include the Material Icons font
    
      # Assets for the application
      assets:
        - assets/audio/
        - assets/images/
        - assets/text/
        - assets/translations/
    
      fonts:
        - family: Graphik
          fonts:
            - asset: assets/fonts/Graphik-Regular.otf
              weight: 400
            - asset: assets/fonts/Graphik-Medium.otf
              weight: 500
            - asset: assets/fonts/Graphik-Semibold.otf
              weight: 600
        - family: Boing
          fonts:
            - asset: assets/fonts/Boing-Medium.ttf
              weight: 500
        - family: Icons
          fonts:
            - asset: assets/fonts/Stile_X_Icons.ttf
    

    Relevant log output

    FlutterGen v5.1.0+1 Loading ... theme_x/pubspec.yaml
    Unhandled exception:
    FormatException: Invalid radix-16 number (at line 2, character 2)
    
     ^
    
    #0      int._handleFormatError (dart:core-patch/integers_patch.dart:131)
    #1      int._parse (dart:core-patch/integers_patch.dart:72)
    #2      int.parse (dart:core-patch/integers_patch.dart:65)
    #3      new HexColor (package:color/hex_color.dart:18)
    #4      swatchFromPrimaryHex (package:flutter_gen_core/utils/color.dart:20)
    #5      _colorStatement (package:flutter_gen_core/generators/colors_generator.dart:64)
    #6      MappedListIterable.elementAt (dart:_internal/iterable.dart:413)
    #7      ListIterable.forEach (dart:_internal/iterable.dart:39)
    #8      generateColors (package:flutter_gen_core/generators/colors_generator.dart:55)
    #9      FlutterGenerator.build (package:flutter_gen_core/flutter_generator.dart:53)
    #10     main (file:///Users/runner/work/flutter_gen/flutter_gen/packages/command/bin/flutter_gen_command.dart:48)
    #11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295)
    #12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192)
    

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    bug 
    opened by DJTB 3
  • chore: update dependency node to v18

    chore: update dependency node to v18

    Mend Renovate

    This PR contains the following updates:

    | Package | Update | Change | |---|---|---| | node (source) | major | 16.18.1 -> 18.13.0 |


    Release Notes

    nodejs/node

    v18.13.0: 2023-01-05, Version 18.13.0 'Hydrogen' (LTS), @​danielleadams

    Compare Source

    Notable changes
    Add support for externally shared js builtins

    By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed.

    Contributed by Michael Dawson in #​44376

    Introduce File

    The File class is part of the FileAPI. It can be used anywhere a Blob can, for example in URL.createObjectURL and FormData. It contains two properties that Blobs do not have: lastModified, the last time the file was modified in ms, and name, the name of the file.

    Contributed by Khafra in #​45139

    Support function mocking on Node.js test runner

    The node:test module supports mocking during testing via a top-level mock object.

    test('spies on an object method', (t) => {
      const number = {
        value: 5,
        add(a) {
          return this.value + a;
        },
      };
      t.mock.method(number, 'add');
    
      assert.strictEqual(number.add(3), 8);
      assert.strictEqual(number.add.mock.calls.length, 1);
    });
    

    Contributed by Colin Ihrig in #​45326

    Other notable changes
    • build:
      • disable v8 snapshot compression by default (Joyee Cheung) #​45716
    • crypto:
      • update root certificates (Luigi Pinca) #​45490
    • deps:
      • update ICU to 72.1 (Michaël Zasso) #​45068
    • doc:
      • add doc-only deprecation for headers/trailers setters (Rich Trott) #​45697
      • add Rafael to the tsc (Michael Dawson) #​45691
      • deprecate use of invalid ports in url.parse (Antoine du Hamel) #​45576
      • add lukekarrys to collaborators (Luke Karrys) #​45180
      • add anonrig to collaborators (Yagiz Nizipli) #​45002
      • deprecate url.parse() (Rich Trott) #​44919
    • lib:
      • drop fetch experimental warning (Matteo Collina) #​45287
    • net:
      • (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) #​44731
    • src:
      • (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) #​45639
      • (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) #​42869
    • test_runner:
      • (SEMVER-MINOR) add t.after() hook (Colin Ihrig) #​45792
      • (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) #​45792
    • tls:
      • (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) #​44935
      • remove trustcor root ca certificates (Ben Noordhuis) #​45776
    • tools:
      • update certdata.txt (Luigi Pinca) #​45490
    • util:
      • add fast path for utf8 encoding (Yagiz Nizipli) #​45412
      • improve textdecoder decode performance (Yagiz Nizipli) #​45294
      • (SEMVER-MINOR) add MIME utilities (#​21128) (Bradley Farias) #​21128
    Commits

    Configuration

    📅 Schedule: Branch creation - "before 10am on monday" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    dependencies 
    opened by renovate[bot] 1
  • chore: update dependency husky to v8

    chore: update dependency husky to v8

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | husky (source) | 7.0.4 -> 8.0.3 | age | adoption | passing | confidence |


    Release Notes

    typicode/husky

    v8.0.3

    Compare Source

    • fix: add git not installed message #​1208

    v8.0.2

    Compare Source

    • docs: remove deprecated npm set-script

    v8.0.1

    Compare Source

    • fix: use POSIX equality operator

    v8.0.0

    Compare Source

    What's Changed

    Feats
    Fixes
    Docs
    Chore

    Configuration

    📅 Schedule: Branch creation - "before 10am on monday" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    dependencies 
    opened by renovate[bot] 1
  • chore: update dependency node to v16.19.0

    chore: update dependency node to v16.19.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Update | Change | |---|---|---| | node (source) | minor | 16.18.1 -> 16.19.0 |


    Release Notes

    nodejs/node

    v16.19.0: 2022-12-13, Version 16.19.0 'Gallium' (LTS), @​richardlau

    Compare Source

    Notable Changes
    OpenSSL 1.1.1s

    This update is a bugfix release and does not address any security vulnerabilities.

    Root certificates updated to NSS 3.85

    Certificates added:

    • Autoridad de Certificacion Firmaprofesional CIF A626340
    • Certainly Root E1
    • Certainly Root R1
    • D-TRUST BR Root CA 1 2020
    • D-TRUST EV Root CA 1 2020
    • DigiCert TLS ECC P384 Root G5
    • DigiCert TLS RSA4096 Root G5
    • E-Tugra Global Root CA ECC v3
    • E-Tugra Global Root CA RSA v3
    • HiPKI Root CA - G1
    • ISRG Root X2
    • Security Communication ECC RootCA1
    • Security Communication RootCA3
    • Telia Root CA v2
    • vTrus ECC Root CA
    • vTrus Root CA

    Certificates removed:

    • Cybertrust Global Root
    • DST Root CA X3
    • GlobalSign Root CA - R2
    • Hellenic Academic and Research Institutions RootCA 2011
    Time zone update to 2022f

    Time zone data has been updated to 2022f. This includes changes to Daylight Savings Time (DST) for Fiji and Mexico. For more information, see https://mm.icann.org/pipermail/tz-announce/2022-October/000075.html.

    Other Notable Changes

    Dependency updates:

    Experimental features:

    Commits

    Configuration

    📅 Schedule: Branch creation - "before 10am on monday" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    dependencies 
    opened by renovate[bot] 1
  • [FR]: Custom Constants Generate from XML.

    [FR]: Custom Constants Generate from XML.

    Is there an existing issue for this?

    • [X] I have searched the existing issues

    Describe the problem

    Producing our const files in our projects through files like strings.xml is something that can really speed up our development speed.

    For example. When we switch to a new project, we could change the data we store under lib/core, which we want to get from the previous project and fill with new information, via xml.

    Describe the solution

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <cons name="appName" type="string" static=false>App Name HERE</color>
        <cons name="consName" type="bool" static=false>true</color>
       ... like
    </resources>
    

    Additional context

    No response

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    enhancement 
    opened by ismailcaakir 0
Releases(v5.1.0+1)
Owner
FlutterGen
FlutterGen is a Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
FlutterGen
VS Code `.code-workspace` file generator

VS Code .code-workspace file generator (for monorepositories with Dart and Flutter projects) TL;DR; Create yaml file config.yaml (check #Format sectio

Mike T 1 Feb 18, 2022
Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter

Code partially generated with chopper ?? Build dart types from Swagger/OpenAPI schemas SwaggerDartCodeGenerator is a code generator that looks for *.s

null 187 Jan 5, 2023
🚀The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

Flutter Gen Zeplin Extension ?? The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time. ⬇ 1.1k Getti

NAVER 49 Oct 12, 2022
The Dart code generator for your package versions. 🎯

The Dart code generator for your package versions. There is no way to get the package version from the code in the Dart ecosystem. Installation Add bu

Daichi Furiya 12 Dec 14, 2022
The diozz package helps you to deal with APIs easily and speed up the process of writing code.

Diozz The diozz package helps you to deal with APIs easily and speed up the process of writing code. Installation Diozz Use that command in the termin

Mohamed Abu.elezz 4 Nov 13, 2022
custom assets loaders for easy_localization

Custom assets loaders for Easy Localization package Supported formats JSON (JsonAssetLoader) CSV (CsvAssetLoader) HTTP (HttpAssetLoader) XML (XmlAsset

Aye7 34 Nov 11, 2022
A simple Flutter / Dart Utility class for converting complex objects to uri and query string

A simple Flutter / Dart Utility class for converting complex or nested objects to uri and query strings you can follow the the article on how this cla

Opata Joshua 5 Sep 7, 2022
Generate random data(string, integer, IPs etc...) using Dart.

Generate random data using Features API provides generation of: Integers in any range of numbers Strings with various characters and length Colors rep

Dinko Pehar 14 Apr 17, 2022
Parse cron string to schedule and generate previous or next schedule item

Parse cron string to schedule and generate previous or next schedule item

Pokhodyun Alexander 2 Apr 17, 2022
Starter project and code generator for Flutter/Redux

Flutter Redux Starter/Code Generator Videos Short video ~ 1 minute Long video ~ 10 minutes We're using this approach to develop the Flutter app for In

Hillel Coren 278 Dec 12, 2022
Dart Code Generator for generating mapper classes

Smartstruct - Dart bean mappings - the easy nullsafe way! Code generator for generating type-safe mappers in dart, inspired by https://mapstruct.org/

Nils 28 Nov 29, 2022
A Flutter plugin that exposes Monet (Material You, Material 3) system colors on Android 12.

Monet Colors A Flutter plugin that exposes Monet (Material You, Material 3) system colors on Android 12. Returns null on unsupported platforms and lea

İhsan Işık 3 Aug 26, 2022
The convenient enum of 256 colors for console

The convenient enum of 256 colors for console. Console Color gives the color code for the console an easily recognizable name.

Kato Shinya 1 Mar 2, 2022
Official Git of flutter code-push made by Chimera inc. If you want to get more info or seek for biz corporation, you can contact [email protected].

中文版 Chimera Flutter Code Push Chimera is a Dart compiler developed by ourselves, which generates interpretable and executable bytecode to implement co

Waytoon 21 Oct 6, 2022
A mobile map based application to help people everywhere around the world get help

Wonder This is a mobile application made by flutter. The application is called "Wonder" because it will help people everywhere around the world to get

Sara Nersisian 1 Dec 2, 2021
This package wraps Airtime, Sms, and Voice call from Africa's Talking APIs.

This package wraps some functionalities from Africa's Talking API The functionalities implemented are; Sms send message fetch messages generate checko

Eddie Genius 7 May 31, 2022
Environment specific config generator for Dart and Flutter applications during CI/CD builds

Environment Config Generator Environment specific config generator. Allows to specify env configuration during CI/CD build. Primarily created to simpl

Denis Beketsky 86 Dec 2, 2022
A Flutter curl-command generator for Dio

curl_logger_dio_interceptor A Flutter curl-command generator for Dio. Easily test your Flutter-made requests in your favorite terminal or even in Post

null 7 Nov 17, 2022
OpenAPI generator for Dart & Flutter

Fantom Fantom is a cli tool for generating API layer based on OpenAPI Spec. Usage Install fantom $ dart pub global activate fantom Generate API client

6thSolution 13 Oct 18, 2022