r_flutter 0.4.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

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:

    sdk: flutter

  r_flutter: <version>
  1. Add r_flutter configuration in your pubspec.yaml:
# important: this is root level option
  intl: lib/i18n/en.arb
    - lib/assets/sub/ignore1 #use ignore option to skip 
    - lib/assets/sub/ignore2
    - lib/i18n


  • 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. 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. assets.dart will be generated into .dart_tool/build/generated/YOUR_PACKAGE_NAME/assets.dart

  2. Import assets.dart and start using it:

import 'assets.dart'
Image(image: Images.image)

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

I18n #

  1. Add default localization file to pubspec.yaml
  intl: lib/i18n/en.arb

Other locales will be searched at lib/i18n/<locale>.arb

  1. Add it to your app.
  title: 'r_flutter',
  supportedLocales: I18n.supportedLocales,
  localizationsDelegates: [
  home: HomePage(),
  1. Use it
import 'assets.dart'

Custom asset classes #

r_flutter supports third party packages like flutter_svg by providing option to convert generated constants directly into the desired class. To use it, you need to configure which file extension should by handled by which class, for example:

      import: asset_classes.dart
      class: SvgFile

And then, r_flutter will use SvgFile class for all svg assets:

static const SvgFile svg = SvgFile("lib/assets/svg.svg")

Troubleshooting #

assets.dart not found

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. assets.dart will be generated into .dart_tool/build/generated/YOUR_PACKAGE_NAME/assets.dart

news keys not resolvable in IDE #

When assets.dart is regenerated, sometimes it is not correctly indexed by the IDE: Building should run anyway, even though that the IDE shows an error.

If the error constits, check the assets.dart and maybe add a Whitespace somewhere. That will trigger the IDE to re-index.

iOS won't show the correct language #

The iOS project need to be updated: Documentation

Examples #

Images #

Instead of writing:

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

you can write:

Image(image: Images.image)
Fonts #

Instead of writing:

    fontFamily: "Roboto",

you can write:

    fontFamily: Fonts.roboto,
Fonts #

Instead of writing:

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

you can write:

await rootBundle.loadString(Assets.data)

0.4.1 #

  • fix crash when none default locales have additional keys

0.4.0 #

  • generate complete i18n code.
    • there is no need for the RuntimeArb anymore
    • see the README for integration steps

0.3.1 #

  • fix NullPointerException when trying to access undefined asset classes

0.3.0 #

  • add custom asset classes support. Thanks to @szotp
  • add file uri comments to assets to get image preview in autocomplete
  • ignore .DS_Store from code generation

0.2.1 #

  • add support to dart builder to automatically integrate into the normal build process. Thanks to @szotp


example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  r_flutter: ^0.4.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:r_flutter/builder.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 23, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms: Flutter, other

Platform components identified in package: build, io.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
args >=0.12.1 <2.0.0 1.5.2
build ^1.1.4 1.2.0
build_config ^0.4.0 0.4.1+1
dart_style ^1.0.0 1.3.2
path >=0.9.0 <2.0.0 1.6.4
recase ^2.0.1 2.0.1
yaml ^2.1.15 2.2.0
Transitive dependencies
analyzer 0.38.5 0.39.0
async 2.4.0
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
front_end 0.1.27 0.1.28
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
json_annotation 3.0.0
kernel 0.3.27 0.3.28
logging 0.11.3+2
meta 1.1.7
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
pedantic 1.8.0+1
pub_semver 1.4.2
pubspec_parse 0.1.5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
Dev dependencies
build_test any
test any