assets_scanner 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

Assets Scanner #

Build Status

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.
/// 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
}

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.

1.0.1 #

Fix the generated content not respect the directory behavior of assets, that describe on https://flutter.dev/docs/development/ui/assets-and-images#specifying-assets

Note: Only files located directly in the directory are included. To add files located in subdirectories, create an entry per directory.

1.0.0 #

Refactor the assets_scanner to generate the r.dart file, and custom it by adding assets_scanner_options.yaml file, see more detail from README.md.

0.0.2 #

Allow not generate comment for asset path by setting const bool isIgnoreComment = true;

0.0.1 #

Release 0.0.1

example/lib/main.dart

import 'package:example/src/r.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        backgroundColor: Colors.blue,
        body: SafeArea(
          child: Center(
            child: Column(
              children: <Widget>[
                Image(
                  image: AssetImage(R.alarm_white),
                ),
                Image(
                  image: AssetImage(R.baseline_3d_rotation_white),
                ),
                Image(
                  image: AssetImage(R.arrow_right_alt_white),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  assets_scanner: ^1.0.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:assets_scanner/assets_scanner_builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
31
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on May 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
analyzer ^0.39.4 0.39.8
build ^1.2.2 1.3.0
glob ^1.2.0 1.2.0
path ^1.6.4 1.7.0
yaml ^2.2.0 2.2.1
Transitive dependencies
_fe_analyzer_shared 3.0.0
args 1.6.0
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
html 0.14.0+3
js 0.6.1+1
logging 0.11.4
meta 1.1.8
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
pedantic 1.9.0
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+15
Dev dependencies
build_test ^0.10.12+1
test ^1.14.2