GithubHelp home page GithubHelp logo

florent37 / flutter_web_import_js_library Goto Github PK

View Code? Open in Web Editor NEW
38.0 4.0 19.0 12.75 MB

Import & use javascript libraries in your flutter web projects

Home Page: https://pub.dev/packages/import_js_library

License: Apache License 2.0

Kotlin 1.99% JavaScript 75.69% Objective-C 0.52% Swift 2.07% Ruby 6.73% Dart 11.77% Shell 0.37% HTML 0.85%
flutter web dart js javascript library audio package libraries load

flutter_web_import_js_library's Introduction

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

flutter_web_import_js_library's People

Contributors

creativecreatorormaybenot avatar florent37 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flutter_web_import_js_library's Issues

Potential copyright issue with distribution of the example assets

I was looking through my disk for audio files, and noticed that one of the examples you are sharing is Stephan F's remix of Astronomia, titled "Astronomia 2K19".

I can't seem to find anything specifying that this song has free distribution rights, unless you have authorization from the publisher, you should probably remove it from your example's assets.

Missing support for null safety

The package needs to be migrated to null safety (with a pre-release version), so that dependencies can migrate to null safety.

I will make a PR for this.

How to pass Dart Function to a Web plugin ?

May be I am asking the wrong question, but can you throw some light on my query.

Basically I am trying to integrate a payment gateway provider js for web project.
I am successful till the point where I am able to execute the payment flow.
But I am unable to get the response back to the main dart code.

Can help me out on this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.