{"id":17679421,"url":"https://github.com/florent37/flutter_web_import_js_library","last_synced_at":"2025-05-07T22:46:37.667Z","repository":{"id":42772307,"uuid":"255928120","full_name":"florent37/flutter_web_import_js_library","owner":"florent37","description":"Import \u0026 use javascript libraries in your flutter web projects","archived":false,"fork":false,"pushed_at":"2020-11-29T05:59:38.000Z","size":13053,"stargazers_count":42,"open_issues_count":3,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T22:46:31.082Z","etag":null,"topics":["audio","dart","flutter","inject","javascript","js","libraries","library","load","package","web"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/import_js_library","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/florent37.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"ko_fi":"FlorentChampigny","github":"florent37"}},"created_at":"2020-04-15T13:39:17.000Z","updated_at":"2024-10-18T15:30:36.000Z","dependencies_parsed_at":"2022-09-08T07:10:33.809Z","dependency_job_id":null,"html_url":"https://github.com/florent37/flutter_web_import_js_library","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florent37%2Fflutter_web_import_js_library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florent37%2Fflutter_web_import_js_library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florent37%2Fflutter_web_import_js_library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florent37%2Fflutter_web_import_js_library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/florent37","download_url":"https://codeload.github.com/florent37/flutter_web_import_js_library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252967982,"owners_count":21833247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","dart","flutter","inject","javascript","js","libraries","library","load","package","web"],"created_at":"2024-10-24T08:41:53.787Z","updated_at":"2025-05-07T22:46:37.638Z","avatar_url":"https://github.com/florent37.png","language":"JavaScript","funding_links":["https://ko-fi.com/FlorentChampigny","https://github.com/sponsors/florent37"],"categories":[],"sub_categories":[],"readme":"# Import JS Library\n\nImport \u0026 use javascript libraries in your flutter web projects.\n\n```dart\nflutter:\n  assets:\n    - assets/howler.js\n```\n\n```dart\nimportJsLibrary(url: \"./assets/howler.js\", flutterPluginName: \"audio_plugin_example\");\n```\n\n# Why\n\n[![meme](./meme/meme_pc_grid.png)]()\n\nAudio library compatible with Flutter Web : https://pub.dev/packages/assets_audio_player\n\n[![meme](./meme/meme_idea_quote.png)]()\n\nHowler.js Audio library for the modern web : https://howlerjs.com/\n\n[![meme](./meme/meme_challenge_accepted.png)]()\n\nAnd after weeks, month, years, eternity later....\n\n[![meme](./meme/eternity_success.png)]()\n\n# How to use it\n\n## 1. Create your plugin Package\n\nhttps://flutter.dev/docs/development/packages-and-plugins/developing-packages\n\n```sh\nflutter create --template=package audio_plugin_example\n```\n\n## 2. Add the js library in your assets\n\nDownloaded from https://github.com/goldfire/howler.js/tree/master/dist\n\n[![meme](./medias/add_into_assets.png)]()\n\n## 3. Declare it inside your pubspec.yaml\n\n```dart\nflutter:\n  assets:\n    - assets/howler.js\n```\n\n## 4. Import import_js_plugin\n\n```\ndependencies:\n  import_js_library: ^1.0.1\n```\n\n## 5. In your Flutter plugin project, import your .js lib\n\nFor example, on the registerWith()\n\npluginName: the name of your plugin, based on pubspecs.yaml, here `audio_plugin_example`\n\nUsing the method `importJsLibrary(url: `PATH_OF_JS`, flutterPluginName: `NAME_OF_FLUTTER_PLUGIN`);`\n\n```dart\nclass AudioPlugin {\n\n  static void registerWith(Registrar registrar) {\n    final MethodChannel channel = MethodChannel(\n      'audio_plugin',\n      const StandardMethodCodec(),\n      registrar.messenger,\n    );\n\n    importJsLibrary(url: \"./assets/howler.js\", flutterPluginName: \"audio_plugin_example\");\n    \n    final AudioPlugin instance = AudioPlugin();\n    channel.setMethodCallHandler(instance.handleMethodCall);\n  }\n   \n  ...\n```\n\n## 6. Using [package:js](https://pub.dev/packages/js), wrap your js methods/classes\n\n```dart\n@JS()\nlibrary howl.js;\n\nimport 'package:js/js.dart';\n\n@JS(\"Howl\")\nclass Howl {\n  external Howl({List\u003cString\u003e src}); \n\n  external play();\n}\n```\n\n## 7. Use your library !\n\n```dart\nfinal audio = Howl(src: [\"./assets/astronomia.mp3\"]);\naudio.play();\n```\n\nfor example in the plugin\n\n```dart\n\n  Howl audio;\n\n  Future\u003cdynamic\u003e handleMethodCall(MethodCall call) async {\n    print(call.method);\n    switch (call.method) {\n      case \"play\":\n        if(audio != null){\n          audio.play();\n        }\n        break;\n      case \"pause\":\n        if(audio != null){\n          audio.pause();\n        }\n        break;\n      case \"open\":\n        final String path = call.arguments[\"path\"];\n        audio = Howl(src: [path]);\n        break;\n    }\n  }\n```\n\n# Concrete use-case\n\n`import_js_library\" is used to import \u0026 wrap Howl.js for the library https://pub.dev/packages/flutter_web_howl\n\nAnd [flutter_web_howl](https://github.com/florent37/flutter_web_howl) is included inside Assets Audio Player to handle the features on flutter web\n\nhttps://pub.dev/packages/assets_audio_player\n\nhttps://github.com/florent37/Flutter-AssetsAudioPlayer/blob/master/lib/assets_audio_player_web.dart\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorent37%2Fflutter_web_import_js_library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflorent37%2Fflutter_web_import_js_library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorent37%2Fflutter_web_import_js_library/lists"}