搜尋套件、儲存庫與 APP 分類

flutter_jscore 封面
套件詳情v1.0.0

flutter_jscore

用於 Flutter 的 JavaScriptCore。此外掛程式可提供從 dart 中評估 JavaScript 程式的能力。

AndroidiOSmacOSWindowsLinux
近 30 天下載
52
喜歡數
41
Pub 分數
130

安裝套件

flutter pub add flutter_jscore

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

flutter_jscore 是一個 Flutter 插件,可使用 JavaScriptCore 引擎讓 Dart 評估 JavaScript 程式碼。它實現了 Dart 和 JavaScript 之間的無縫整合,使您能在 Android、iOS、macOS、Windows 和 Linux 上的 Flutter 應用中直接執行 JavaScript 程式。這對於執行動態腳本、利用現有的 JavaScript 庫或在 JavaScript 中進行客戶端計算特別有用。該插件在兩個環境之間提供了一個輕量級的橋樑,開銷極小。

適用情境

  • 在Flutter應用中執行JavaScript代碼
  • 整合 JavaScript 庫
  • 動態腳本評估
  • 跨平台腳本
  • 使用 JS 的客戶端計算

主要特色

  • JavaScriptCore 引擎整合
  • 跨平台支援
  • Dart-JavaScript 互操作性
  • 用於腳本評估的簡單 API
  • 支援多個平台

適合對象

  • 需要在 Flutter 中執行 JS 的開發者
  • 需要動態腳本的 App
  • 使用現有 JS 庫的專案
  • 混合應用程式開發
  • 效能關鍵的 JS 任務

使用建議

  • 僅限 JavaScriptCore(非完整瀏覽器環境)
  • 無可用的 DOM 操作
  • 不受信任的腳本的安全風險
  • 某些功能需要平台特定的設定
  • 長時間執行腳本的記憶體管理注意事項

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_jscore

License Awesome Flutter Pub

JavaScriptCore for Flutter. The plugin provides the ability to evaluate JavaScript programs from within dart.

Demo
Screen recording Apk
Code Download

Getting Started

Add plugin
// pub
dependencies:
  flutter_jscore: ^last_version

// import
dependencies:
  flutter_jscore:
    path: Your local path

// git
dependencies:
  flutter_jscore:
    git:
      url: git://github.com/xuelongqy/flutter_jscore.git
Add dynamic library

Due to the size limitation of pub on package upload, you need to add JavaScriptCore dynamic library to the project by yourself.
You can refer to the example. of course you can refer to webkit to compile it.
Set JscFfi.lib to use the JavaScriptCore dynamic library.

JscFfi.lib = Platform.isIOS || Platform.isMacOS
  ? DynamicLibrary.open('JavaScriptCore.framework/JavaScriptCore')
  : Platform.isWindows
  ? DynamicLibrary.open('JavaScriptCore.dll')
  : Platform.isLinux
  ? DynamicLibrary.open('libjavascriptcoregtk-4.0.so.18')
  : DynamicLibrary.open('libjsc.so');
Android

You can get the aar file containing libjsc.so in jsc-android, and add to your project.
Take the libs folder as an example, add it to the build.gradle of the module.

android {
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}
dependencies {
    implementation(name:'**', ext:'aar')
}

You also need to add libc++_shared.so, because this is a dependency of libjsc.so.
Take the jniLibs folder as an example, add it to the build.gradle of the module.

android {
    sourceSets {
        main {
            jniLibs.srcDirs = ['jniLibs']
        }
    }
}

If your project uses C++, then you can add the code in the module’s build.gradle.

android {
    defaultConfig {
        externalNativeBuild {
            make {
                arguments "-DANDROID_STL=c++_shared"
            }
        }
    }
}
iOS and macOS

You don’t need to do anything, because JavaScriptCore comes with iOS and macOS.

Windows

You can use the dynamic library in the example, or compile it yourself. And configure in CMakeLists.txt.

# Add JavaScriptCore libs
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/JavaScriptCore/"
  DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  COMPONENT Runtime)
Linux

You can use libjavascriptcoregtk as a dependency, or compile webkitgtk yourself.
The names of dynamic libraries in different Linux distributions may be different. So you need to set JscFfi.lib.

ubuntn or Debian

apt-get install libjavascriptcoregtk-4.0-18
JscFfi.lib = DynamicLibrary.open('libjavascriptcoregtk-4.0.so.18');

Archlinux

pacman -S webkit2gtk
JscFfi.lib = DynamicLibrary.open('libjavascriptcoregtk-4.0.so');
Usage
import 'package:flutter_jscore/flutter_jscore.dart';

void runJS() {
    JSContext jsContext = JSContext.createInGroup();
    // Replace '1 + 1' with your JavaScript code
    JSValue jsValue = jsContext.evaluate('1 + 1');
    print(jsValue.string);
    jsContext.release();
}

JavaScriptCore

Evaluate JavaScript programs from within an app, and support JavaScript scripting of your app.

Documentation

dart:ffi

Foreign Function Interface for interoperability with the C programming language. flutter_jscore uses dart:ffi so you don't have to worry about performance loss across programming languages.

dart:ffi

Supported platforms

  • iOS (7.0+)
  • macOS (10.5+)
  • Android (arm32, arm64, x86, x86_64)
  • Windows (x86_64)
  • Linux (x86_64)

Linux dependencies

If you use it on Linux, you must make sure to have the following dependencies.

  • libglib-2.0.so.0
  • libicui18n.so.66
  • libicuuc.so.66
  • libdl.so.2
  • libgio-2.0.so.0
  • libgobject-2.0.so.0
  • libpthread.so.0
  • libstdc++.so.6
  • libm.so.6
  • libgcc_s.so.1
  • libc.so.6
  • ld-linux-x86-64.so.2

APIs

I don't think there is much to describe, flutter_jscore just makes a simple package. You can refer to the documentation of JavaScriptCore and the documentation on pub.

JavaScriptCore

flutter_jscore

Donation

If you like my project, please in the upper right corner of the project "Star". Your support is my biggest encouragement! ^_^ You can also scan the qr code below or Donate to this project using Paypal, donation to Author.

If in donation message note name, will be record to the list if you are making open source authors, donation can leave when making project address or personal home page, a link will be added to the list have the effect of promoting each other

Donation list

QQ Group - 554981921
Into the group of instructions

The group is not only solve the problem of EasyreFresh, any Flutter related issues can be discussed. Just as its name, craigslist, as long as there is time, group of Lord will help you solve problems together.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。