assets_scanner 2.0.0 copy "assets_scanner: ^2.0.0" to clipboard
assets_scanner: ^2.0.0 copied to clipboard

assets_scanner helps you generate assets path constants to r.dart file, you can preview the images assets by hovering over the constants.

Assets Scanner #

Build Status pub package

As you know, you need to use the image path to load image in Flutter , e.g., AssetImage('graphics/background.png'). However, this approach is prone to errors, such as the spelling of the path, you can only find this error after the program runs, and you may not be able to intuitively know which picture this is through the path. Assets Scanner helps you generate constants for assets, reducing the probability of misspellings. At the same time, you can hover over the constants to preview the images more intuitively.

Usage #

In your pubspec.yaml, add the following:

dev_dependencies:
    assets_scanner: ^1.0.0

Then run flutter packages pub run build_runner build, assets_scanner will generate a r.dart file in the lib/ for you, such like below:

/// GENERATED BY assets_scanner. DO NOT MODIFY BY HAND.
/// See more detail on https://github.com/littleGnAl/assets-scanner.
class R {
  static const package = "example";

  /// ![](.../assets-scanner/example/assets/baseline_3d_rotation_white.png)
  static const baseline_3d_rotation_white = "assets/baseline_3d_rotation_white.png";

// ignore_for_file:lines_longer_than_80_chars,constant_identifier_names
}

NOTE:

  • For package assets, it will generate another class according to the package name.

  • If the asset's name is not a legal dart identifier, the illegal characters will be converted to _, .e.g, the asset name 2TXsXk.jpg!w1280h1000.jpg will generate the property name r_2TXsXk_jpg_w1280h1000.

Now, you can preview images assets by hovering to the constants:

Custom the assets_scanner_options.yaml #

By default, assets_scanner generate the r.dart in the lib/, the class name with R, etc. You can custom some options by adding a assets_scanner_options.yaml file, the supported keys list below:

  • path: The path where the r.dart file locate. Note that the path should be sub-path of lib/.

  • className: The class name of the r.dart.

  • ignoreComment: Indicate the comments need to be generated or not. Note that the you can't preview the images assets if ignoreComment is true.

Here the example of the assets_scanner_options.yaml file:

# assets_scanner_options.yaml

path: "lib/src"
className: "MainAssets"
ignoreComment: true

License #

Copyright (C) 2020 littlegnal

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
17
likes
120
pub points
60%
popularity

Publisher

unverified uploader

assets_scanner helps you generate assets path constants to r.dart file, you can preview the images assets by hovering over the constants.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

build, glob, meta, path, yaml

More

Packages that depend on assets_scanner