assets_annotations 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

assets_plugin #

Code generator for assets plugin

This plugin consist of three packages:

Getting Started #

This package should use with the asset_annotation package. The main idea of this is a generating dart class with fields, which can help you access your assets in code and give you autocomplete and static preload of text assets in one place. For an example of usage go-to example project. You can configure the generator in a build.ya?ml file of your project. At now the only thing is an extension of files, which can be preloaded. By default, it is a .txt and .json files, but you can pass your additional types in this manner:

targets:
  $default:
    builders:
      assets_codegen:
        options:
          preload:
            - your_file_type
            - other_your_file_type

To use this package - install it and create file such as

import 'package:assets_annotations/assets_annotations.dart';
import 'package:flutter/services.dart'; // <== IT IMPORT IS REQUIRED FOR WORKING AUTO-PRELOAD FOR DEFINED FILE EXTENSIONS (json, txt, etc...)

part 'asset_helper.g.dart';

@AstHelp()
class AssetHelper with _$TextHelper {}

Plugin will search assets section in your pubspec.ya?ml file and watch directories, which is described there and deeper (recursive), after you run

flutter pub run build_runner build|watch [--delete-conflicting-outputs]

plugin will generate mixin near your annotated file-class.

1.0.0 - Initial release #

example/lib/main.dart

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Assets demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  assets_annotations: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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_annotations/assets_annotations.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
8
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 < 3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test