Imports resource files as string or binary literals in Dart code.

Overview

resource_importer

Imports resource files as string or binary literals in Dart code.

What?

resource_importer probably is best described with an example. You can add a resource_importer block to your Dart package's pubspec.yaml file that specifies some resource files:

resource_importer:
  resources:
    myImage: 'assets/image.png'
    myLicense:
      path: 'LICENSE'
      type: String

Running resource_importer then will generate a file (by default named lib/resources.resource_importer.dart) that looks like:

var myImage = Uint8List.fromList(const [
  0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00,
  0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x30,
  // ...
]);

var myLicense =
    "Copyright (C) 2022 James D. Lin\n\nThis software is provided 'as-is', ..."

That file then can be imported by other Dart code:

import 'package:my_package/resources.resource_importer.dart' as resources;

void main() {
  print(resources.myLicense);
}

Why?

Honestly, most people probably shouldn't be using this. Flutter projects instead should use proper assets that are packaged with your application. You usually don't want large textual representations of binary files in your source tree, wasting cycles from the Dart compiler and analyzer and possibly wasting space in your source control system. (You often shouldn't be committing generated files to source control, though.)

This is primarily intended for non-Flutter Dart projects where bundling additional files can be inconvenient (e.g. console programs distributed as standalone executables, tests for Dart for the Web).

How?

Configuration syntax

See the example.

Usage

  1. Modify your pubspec.yaml file to add:

    dev_dependencies:
      resource_importer: ^0.1.0
  2. Add a resource_importer block to your pubspec.yaml file as described in the example.

  3. Run dart run resource_importer from the directory that contains your pubspec.yaml file to generate code. Currently this is not automatic and instead is expected to be run manually as needed.

The Base64Data and GzippedData types are custom classes provided by resource_importer. If you use them, you must use a regular dependency:

dependencies:
  resource_importer: ^0.1.0

and then use Base64Data.data() or GzippedData.data() respectively to access their decoded bytes as Uint8Lists. Note that GzippedData depends on dart:io and therefore cannot be used for Dart for the Web.

You might also like...

Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your device and upload them to Firebase.

Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your device and upload them to Firebase.

Flutter Tutorial - Upload Files To Firebase Storage Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your devic

Dec 28, 2022

A Dart package that constantly writes a string to an IOSink, simillarly to the UNIX yes utility.

yes A Dart package that constantly writes a string to an IOSink, simillarly to the UNIX yes utility. Usage // Write to stdout for 5 seconds. final con

Sep 22, 2022

Dart duration iso parser - Package to parse duration from ISO 8601 string

duration_iso_parser Package for parsing ISO 8601 durations string to the Duratio

Jan 18, 2022

Simple, random string generator for Dart

Simple Random String Simple, random string generator Features Lower characters Upper characters Numbers Customizable special characters Repeatable or

Dec 19, 2022

Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON.

JSON to Dart Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON. This library is designed to ge

Dec 25, 2022

Flutter package to create list of radio button, by providing a list of objects it can be a String list or list of Map.

Flutter package to create list of radio button, by providing a list of objects it can be a String list or list of Map.

Custom Radio Group List Flutter package to create list of radio button, by providing a list of objects it can be a String list or list of Map. Feature

Nov 30, 2021

Zooper flutter encoding utf16 - Helper classes to encode and decode UTF16 string to List

zooper_flutter_encoding_utf16 Helper classes to encode and decode UTF16 string t

Feb 10, 2022

This is a Flutter plugin that takes a JSON string and converts it onto a customizable Flutter Widget.

This is a Flutter plugin that takes a JSON string and converts it onto a customizable Flutter Widget.

Colored JSON Convert JSON string into customizable widget. Getting Started ColoredJson is a stateless widget that produces a structured view of JSON s

May 20, 2022

Flutter plugin which helps you to find links in String using NSDataDetector and Linkify

Flutter plugin which helps you to find links in String using NSDataDetector and Linkify

Flutter's Native Linkify native_linkify is a Flutter plugin. Use it to find links in plain-text. The plugin uses NSDataDetector for iOS and macOS; Lin

Nov 29, 2022
🎯 Automatically organize your dart imports. Maintainer: @gleich

___ _____ ______ ________ ________ ________ _________ |\ \|\ _ \ _ \|\ __ \|\ __ \|\ __ \|\___ ___\ \ \ \ \ \\\__\ \ \ \ \|

Flutter Community 138 Dec 12, 2022
A pure Dart package for working with RDF (resource description framework).

RDFLib A pure Dart package for working with RDF (resource description framework). Features Create triple instances (with data types) Create a graph to

null 5 Dec 15, 2022
Resource monitor - A flutter plugin for Android and IOS to monitor CPU and RAM usage of device.

resource_monitor A flutter plugin for Android and IOS to monitor CPU and RAM usage of device. TODO Return overall system cpu/memory usage. Implement A

Skandar Munir 1 Nov 11, 2022
A Mobile application developed with Flutter and Dart to do math operations with binary numbers.

Math operations with Binary Numbers Readme PT About this Project Mobile application developed with Flutter and Dart to do math operations as sum, subt

Manoel Ribeiro 3 Nov 3, 2020
Binary Decimal Converter with GetX

Conversor Binario Decimal con GetX En este ejemplo se usa la librerĂ­a GetX para implementar el convertor binario decimal Usamos: Dependecy injection h

null 0 Nov 27, 2021
A library for parsing and encoding IEEE-754 binary floating point numbers.

Dart IEEE754 library This library provides decoding and transforming IEEE754 floating point numbers in binary format, double format, or as exponent an

null 0 Dec 24, 2021
Plist parser - A Plist parser for Flutter supports XML and binary Apple Property list (plist) formats

Plist Parser for Flutter ?? A Flutter Plugin for Plist parser supporting XML and

dirablue ( gaku ) 4 Nov 17, 2022
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

null 8.3k Dec 31, 2022
A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

PengHui Li 112 Nov 11, 2022
Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Flutter Tutorial - Download Files From Firebase Storage Download files from Firebase Storage with Flutter. List all images, videos, or other files fro

Johannes Milke 28 Dec 4, 2022