r_flutter 0.2.0 copy "r_flutter: ^0.2.0" to clipboard
r_flutter: ^0.2.0 copied to clipboard

outdated

Generate constants for resources which require using them as a String like fonts and assets.

r_flutter #

Generate constants for resources which require using them as a String like fonts and assets. Generated file will look like this: assets.dart

Setup #

  1. Ensure that your assets and localization files are inside lib directory. This is required for builder plugin to detect changes.

  2. Add dependencies in your pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  runtime_arb:
    git: 
      url:https://github.com/szotp/r_flutter.git
      path: runtime_arb

builders:
  r_flutter:
    git: https://github.com/szotp/r_flutter.git
  1. Add r_flutter configuration in your pubspec.yaml:
# important: this is root level option
r_flutter:
  intl: lib/i18n/en.arb
  ignore:
    - lib/assets/sub/ignore1 #use ignore option to skip 
    - lib/assets/sub/ignore2
    - lib/i18n

Options:

  • intl: Points to a localization file that would be used to generate localization keys. arb files are essentialy json files with some special, optional keys. Specifing this is optional.
  • ignore: specifies a list of files/directories that should be skipped during code generation.
  1. Import runtime_arb package and add RuntimeArbDelegate to your localization delegates:
MaterialApp(
  title: 'r_flutter',
  localizationsDelegates: [
    // runtimeArbDelegate will expect lib/i18n/en.arb and lib/i18n/en.arb to exist in your app
    // make sure they have been added to your assets
    RuntimeArbDelegate({'en', 'pl'})
  ],
  home: HomePage(),
)
  1. Execute flutter generate command in your project's directory. You could also run tests or just build the app. Compiler must run at least once to generate the file.

  2. Import assets.yaml and start using it:

import 'assets.yaml'
Text(i18n.hello_there)

Note: if something doesn't work, check the example project.

Examples #

Images

Instead of writing:

Image(image: AssetImage("assets/path/to/image.png"))

you can write:

Image(image: Images.image)
Fonts

Instead of writing:

TextStyle(
    fontFamily: "Roboto",
)

you can write:

TextStyle(
    fontFamily: Fonts.roboto,
)
Fonts

Instead of writing:

await rootBundle.loadString("assets/path/to/data.json")

you can write:

await rootBundle.loadString(Assets.data)
20
likes
0
pub points
68%
popularity

Publisher

unverified uploader

Generate constants for resources which require using them as a String like fonts and assets.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

args, build, build_config, dart_style, path, recase, yaml

More

Packages that depend on r_flutter