Inspired by aspen but specified for using npm modules in flutter_js


  • 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


  1. Create a npm module in web folder or any other folders are whitelisted because by default package:build only allows you to use assets from a pre-defined whitelist of directories.

  2. Installs packages you'd like to use and

  3. Create a index.js and exports modules to global object like this:

module.exports.lib = require('name/of/module');
  1. Generates a bundle.js by using webpack.
  2. Creates a dart file like this:
library example;

import 'package:flutter_js_asset/annotations.dart';

part 'example.g.dart';

const String jsCode = $jsCodeContent;
  1. Generates $jsCodeContent by typing:
flutter pub run build_runner build

see example for more details.