import_js_library 0.0.1 import_js_library: ^0.0.1 copied to clipboard
Import & use javascript libraries in your flutter web projects
Import JS Library #
Import & use javascript libraries in your flutter web projects.
Created to make it simpler to build Flutter Plugins compatible with web.
Example #
to include howler.js & use it in a flutter web project :
- Add the js library in your assets
- Declare it inside your pubspec.yaml
flutter:
assets:
- assets/howler.js
- Anywhere in your Flutter project, import this js lib
For example, on the main.dart
void main() {
importJsLibrary("./assets/howler.js");
runApp(MyApp());
}
You can also import it later in a custom class.
- Using package:js, wrap your js methods/classes
@JS()
library howl.js;
import 'package:js/js.dart';
@JS("Howl")
class Howl {
external Howl({List<String> src});
external play();
}
- Use your library !
final audio = Howl(src: ["./assets/astronomia.mp3"]);
audio.play();