amdjs 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

AMDJS #

JavaScript AMD (Asynchronous Module Definition) Dart interoperability.

When using JS libraries that uses AMD (RequireJS), you need to call the JS function require() to correctly load the library or unpredicted behaviors will happens.

This Dart packages helps to transparently load JS libraries from Dart, using native AMD require(), when present, or just adding a <script src="library.js"></script> into DOM.

Usage #

A simple usage example:

import 'package:amdjs/amdjs.dart';

// Running on browser:
main() async {
 
  // Check if AMD is already loaded in JS context (usually when RequireJS is already loaded in DOM):
  var inNativeMode = AMDJS.isNativeImplementationPresent() ;
 
  // Load JQuery:
  var okJQuery = await AMDJS.require('jquery', '/js/jsquey.js' , globalJSVariableName: 'jquery') ;
 
  // Bootstrap recommends to add script tag inside body. The parameter `addScriptTagInsideBody` will be
  // used only when mimicking AMD, and ignored when running in native mode:
  var okBootstrap = await AMDJS.require('bootstrap', '/js/bootstrap.js', addScriptTagInsideBody: true) ;
  
  if (okJQuery && okBootstrap) {
    print('Bootstrap correctly loaded (JQuery 1st, Bootstrap 2nd).');
  }


}

Common issues loading JS libraries with Dart #

Since Dart, specially in development mode, uses AMD (RequireJS or similar) to load its packages, any other JS library inserted using <script src"library-x.js""></script> won't load correctly. This package (amdjs) helps to identify that and correctly load libraries.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Dart free & open-source license.

1.0.3 #

  • Change SDK minimal requirement to 2.7+

1.0.2 #

  • Fix API documentation.

1.0.1 #

  • Added API documentation.
  • Fix a small bug.

1.0.0 #

  • Initial version, created by Stagehand

example/amdjs_example.dart

import 'package:amdjs/amdjs.dart';

void main() {


}

Use this package as a library

1. Depend on it

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


dependencies:
  amdjs: ^1.0.3

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:amdjs/amdjs.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
62
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]
81
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-native on android

Because:

  • package:amdjs/amdjs.dart that imports:
  • package:amdjs/src/amdjs_base.dart that imports:
  • package:dom_tools/dom_tools.dart that imports:
  • package:dom_tools/src/perspective_filter.dart that imports:
  • package:dom_tools/src/dom_tools_paint.dart that imports:
  • dart:html

Package not compatible with runtime flutter-native on ios

Because:

  • package:amdjs/amdjs.dart that imports:
  • package:amdjs/src/amdjs_base.dart that imports:
  • package:dom_tools/dom_tools.dart that imports:
  • package:dom_tools/src/perspective_filter.dart that imports:
  • package:dom_tools/src/dom_tools_paint.dart that imports:
  • dart:html

Package not compatible with runtime flutter-native on linux

Because:

  • package:amdjs/amdjs.dart that imports:
  • package:amdjs/src/amdjs_base.dart that imports:
  • package:dom_tools/dom_tools.dart that imports:
  • package:dom_tools/src/perspective_filter.dart that imports:
  • package:dom_tools/src/dom_tools_paint.dart that imports:
  • dart:html

Package not compatible with runtime flutter-native on macos

Because:

  • package:amdjs/amdjs.dart that imports:
  • package:amdjs/src/amdjs_base.dart that imports:
  • package:dom_tools/dom_tools.dart that imports:
  • package:dom_tools/src/perspective_filter.dart that imports:
  • package:dom_tools/src/dom_tools_paint.dart that imports:
  • dart:html

Package not compatible with runtime flutter-native on windows

Because:

  • package:amdjs/amdjs.dart that imports:
  • package:amdjs/src/amdjs_base.dart that imports:
  • package:dom_tools/dom_tools.dart that imports:
  • package:dom_tools/src/perspective_filter.dart that imports:
  • package:dom_tools/src/dom_tools_paint.dart that imports:
  • dart:html

Package not compatible with runtime native

Because:

  • package:amdjs/amdjs.dart that imports:
  • package:amdjs/src/amdjs_base.dart that imports:
  • package:dom_tools/dom_tools.dart that imports:
  • package:dom_tools/src/perspective_filter.dart that imports:
  • package:dom_tools/src/dom_tools_paint.dart that imports:
  • dart:html

Package not compatible with runtime native-aot

Because:

  • package:amdjs/amdjs.dart that imports:
  • package:amdjs/src/amdjs_base.dart that imports:
  • package:dom_tools/dom_tools.dart that imports:
  • package:dom_tools/src/perspective_filter.dart that imports:
  • package:dom_tools/src/dom_tools_paint.dart that imports:
  • dart:html

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
dom_tools ^1.2.9 1.3.2
swiss_knife ^2.4.0 2.5.3
Transitive dependencies
args 1.6.0
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
enum_to_string 1.0.9
html_unescape 1.0.1+3
intl 0.16.1
json_object_mapper 1.0.0
markdown 2.1.5
path 1.7.0
resource_portable 2.1.7
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
pedantic ^1.9.0
test ^1.14.4