theme_generator_x 0.0.6 copy "theme_generator_x: ^0.0.6" to clipboard
theme_generator_x: ^0.0.6 copied to clipboard

Theme extension generator

Pub Version Dart SDK Version Pub popularity

Theme generator #

simple dart code generator that can help you to generate flutter extension from JSON code with different formats

Usage #

1. install #

you should install it to pub global as command line tool dart pub global activate theme_generator_x

2. arguments #

  • input - path to your input JSON file

  • output - path to your output .dart file

  • class_name - name of generated extension class, e.g. AppThemeDataColorsX

  • use_dark - flag if you need to generate dark colors too. false by default

  • keys_rename - how to rename JSON keys

    Available options:

    • camel_case - camelCase
    • original - original name
    • snake_case - snake_case

JSON structure #

you can use different JSON key-value structures

Allowed key-values #

{
    "primary": "#f6f4da",
    "secondary": "0xff9e9e9e",
    "some_color": "#ff000011"
}

array of colors

  • 0 item - light color
  • 1 item - dark color
{
    "composite": [
        "#f6f4da",
        "0xff9e9e9e"
    ]
}
{
    "test_color_simple": {
        "light": "#000011"
    },
    "test_color": {
        "dark": "#656213",
        "light": "#000011"
    }
}

also you can generate array of colors

{
 "simple_map_of_array": {
        "light": [
            "#656213",
            "#000011"
        ]
    },
    "simple_map_of_array_dark": {
        "light": [
            "#995577",
            "#000011"
        ],
        "dark": [
            "#110022",
            "#000000"
        ]
    }
}

CMD #

theme_generator_x colors --input example/test_schema.json --output example/output.dart --class_name AppThemeDataColorsX

of course you can use absolute or relative paths to the files

theme_generator_x colors --input /Users/jWinterDay/Documents/app_theme_asset.json --output app_theme_color.dart --class_name AppThemeDataColorsX

Flutter #

now you have the extensions and can use it in the flutter app

MaterialApp(
    ...
    theme: ThemeData(
        useMaterial3: true,
    ).copyWith(
        extensions: <ThemeExtension<dynamic>>[
            lightAppThemeDataColorsXData(), // generated extension function
        ],
    ),
  ...
)
12
likes
140
points
37
downloads

Publisher

unverified uploader

Weekly Downloads

Theme extension generator

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

args, flutter, http, path, recase

More

Packages that depend on theme_generator_x