Giter Site home page Giter Site logo

ruijinyao / assets-scanner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from littlegnal/assets-scanner

0.0 0.0 0.0 425 KB

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

Home Page: https://pub.dev/packages/assets_scanner/

License: Apache License 2.0

Shell 0.35% Objective-C 0.11% Kotlin 1.26% Dart 97.03% Swift 1.24%

assets-scanner's Introduction

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.

assets-scanner's People

Contributors

littlegnal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.