flutter_js_asset 0.1.0
flutter_js_asset: ^0.1.0 copied to clipboard
Creates a .dart file containing constants that included javascript code read from specified files by using @TextAsset annotation.
Inspired by aspen but specified for using npm modules in flutter_js
Features #
- Creates a .dart file containing constants that included javascript code read from specified files
by using
@TextAsset
annotation.
Getting started #
flutter pub add -d build_runner
flutter pub add flutter_js_asset
To build, type
flutter pub run build_runner build
To test, type
flutter pub run build_runner test
Usage #
-
Create a npm module in
web
folder or any other folders are whitelisted because by defaultpackage:build
only allows you to use assets from a pre-defined whitelist of directories. -
Installs packages you'd like to use and
-
Create a
index.js
and exports modules to global object like this:
module.exports.lib = require('name/of/module');
- Generates a
bundle.js
by using webpack. - Creates a dart file like this:
library example;
import 'package:flutter_js_asset/annotations.dart';
part 'example.g.dart';
@TextAsset('asset:example/web/dist/bundle.js')
const String jsCode = $jsCodeContent;
- Generates $jsCodeContent by typing:
flutter pub run build_runner build
see example
for more details.