All Projects → florent37 → flutter_web_import_js_library

florent37 / flutter_web_import_js_library

Licence: Apache-2.0 license
Import & use javascript libraries in your flutter web projects

Programming Languages

javascript
184084 projects - #8 most used programming language
dart
5743 projects
ruby
36898 projects - #4 most used programming language
swift
15916 projects
kotlin
9241 projects
HTML
75241 projects

Projects that are alternatives of or similar to flutter web import js library

Golibs
general purpose Golang code (to be included in other projects)
Stars: ✭ 114 (+307.14%)
Mutual labels:  package, libraries
LiteOTP
Multi OTP Spam Amp/Paralell threads
Stars: ✭ 50 (+78.57%)
Mutual labels:  package, libraries
golangflow
GolangFlow.io Website
Stars: ✭ 37 (+32.14%)
Mutual labels:  package
eerie
The package manager for Io.
Stars: ✭ 22 (-21.43%)
Mutual labels:  package
KGySoft.Drawing
KGy SOFT Drawing is a library for advanced image, icon and graphics handling.
Stars: ✭ 27 (-3.57%)
Mutual labels:  libraries
elm-generative
Making generative art in Elm
Stars: ✭ 23 (-17.86%)
Mutual labels:  package
devliver
Your private self hosted composer repository with user management
Stars: ✭ 50 (+78.57%)
Mutual labels:  package
FinMesh
A python package that brings together financial and economic data.
Stars: ✭ 20 (-28.57%)
Mutual labels:  package
laravel-repoman
Set a payment deadline for the customer
Stars: ✭ 14 (-50%)
Mutual labels:  package
future.mapreduce
[EXPERIMENTAL] R package: future.mapreduce - Utility Functions for Future Map-Reduce API Packages
Stars: ✭ 12 (-57.14%)
Mutual labels:  package
pfSense-pkg-WireGuard
This is a port of the original WireGuard UI bits as implemented by Netgate in pfSense 2.5.0 to a package suitable for rapid iteration and more frequent updating on future releases of pfSense.
Stars: ✭ 194 (+592.86%)
Mutual labels:  package
inject
A simple Kotlin multi-platform abstraction around the javax.inject annotations.
Stars: ✭ 42 (+50%)
Mutual labels:  inject
emacs-hacker-typer
A customizable implementation of http://hackertyper.com in emacs.
Stars: ✭ 21 (-25%)
Mutual labels:  package
packager
Laravel Package Skeleton Generator - https://youtu.be/kQRQWzDEbGk
Stars: ✭ 20 (-28.57%)
Mutual labels:  package
HiFramework.Unity
Based on component to manage project's core logic and module used in unity3d
Stars: ✭ 22 (-21.43%)
Mutual labels:  inject
inqlude
Command line client for independent Qt library archive
Stars: ✭ 30 (+7.14%)
Mutual labels:  libraries
meteor-graphql
Compiler plugin that supports GraphQL files in Meteor
Stars: ✭ 56 (+100%)
Mutual labels:  package
flutter background
A flutter plugin to keep apps running in the background via foreground services. Currently Android only.
Stars: ✭ 58 (+107.14%)
Mutual labels:  package
toggler
Atom plugin - Toggle words and symbols
Stars: ✭ 21 (-25%)
Mutual labels:  package
macpack
Makes a macOS binary redistributable by searching the dependency tree and copying/patching non-system libraries.
Stars: ✭ 20 (-28.57%)
Mutual labels:  package

Import JS Library

Import & use javascript libraries in your flutter web projects.

flutter:
  assets:
    - assets/howler.js
importJsLibrary(url: "./assets/howler.js", flutterPluginName: "audio_plugin_example");

Why

meme

Audio library compatible with Flutter Web : https://pub.dev/packages/assets_audio_player

meme

Howler.js Audio library for the modern web : https://howlerjs.com/

meme

And after weeks, month, years, eternity later....

meme

How to use it

1. Create your plugin Package

https://flutter.dev/docs/development/packages-and-plugins/developing-packages

flutter create --template=package audio_plugin_example

2. Add the js library in your assets

Downloaded from https://github.com/goldfire/howler.js/tree/master/dist

meme

3. Declare it inside your pubspec.yaml

flutter:
  assets:
    - assets/howler.js

4. Import import_js_plugin

dependencies:
  import_js_library: ^1.0.1

5. In your Flutter plugin project, import your .js lib

For example, on the registerWith()

pluginName: the name of your plugin, based on pubspecs.yaml, here audio_plugin_example

Using the method importJsLibrary(url: PATH_OF_JS, flutterPluginName: NAME_OF_FLUTTER_PLUGIN);

class AudioPlugin {

  static void registerWith(Registrar registrar) {
    final MethodChannel channel = MethodChannel(
      'audio_plugin',
      const StandardMethodCodec(),
      registrar.messenger,
    );

    importJsLibrary(url: "./assets/howler.js", flutterPluginName: "audio_plugin_example");
    
    final AudioPlugin instance = AudioPlugin();
    channel.setMethodCallHandler(instance.handleMethodCall);
  }
   
  ...

6. 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();
}

7. Use your library !

final audio = Howl(src: ["./assets/astronomia.mp3"]);
audio.play();

for example in the plugin

  Howl audio;

  Future<dynamic> handleMethodCall(MethodCall call) async {
    print(call.method);
    switch (call.method) {
      case "play":
        if(audio != null){
          audio.play();
        }
        break;
      case "pause":
        if(audio != null){
          audio.pause();
        }
        break;
      case "open":
        final String path = call.arguments["path"];
        audio = Howl(src: [path]);
        break;
    }
  }

Concrete use-case

`import_js_library" is used to import & wrap Howl.js for the library https://pub.dev/packages/flutter_web_howl

And flutter_web_howl is included inside Assets Audio Player to handle the features on flutter web

https://pub.dev/packages/assets_audio_player

https://github.com/florent37/Flutter-AssetsAudioPlayer/blob/master/lib/assets_audio_player_web.dart

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].