패키지, 저장소 및 앱 카테고리 검색

flutter_jscore 표지
패키지 상세v1.0.0

flutter_jscore

Flutter용 JavaScriptCore. 이 플러그인은 Dart에서 자바스크립트 프로그램을 평가할 수 있는 기능을 제공합니다.

AndroidiOSmacOSWindowsLinux
30일 다운로드
52
좋아요
41
Pub 점수
130

패키지 설치

flutter pub add flutter_jscore

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

flutter_jscore는 Dart가 JavaScriptCore 엔진을 사용하여 JavaScript 코드를 평가할 수 있도록 해주는 Flutter 플러그인입니다. Dart와 JavaScript 간의 원활한 통합을 가능하게 하여 Android, iOS, macOS, Windows, Linux에서 Flutter 애플리케이션 내부에서 JavaScript 프로그램을 직접 실행할 수 있게 합니다. 동적 스크립트를 실행하거나 기존 JavaScript 라이브러리를 활용하거나 JavaScript로 클라이언트 측 계산을 수행하는 데 특히 유용합니다. 이 플러그인은 두 환경 사이에 가벼운 브리지 역할을 하며 최소한의 오버헤드를 제공합니다.

사용 사례

  • Flutter 앱에서 자바스크립트 코드 실행
  • 자바스크립트 라이브러리 통합
  • 동적 스크립트 평가
  • 크로스 플랫폼 스크립팅
  • JS를 사용한 클라이언트 측 계산

주요 기능

  • JavaScriptCore 엔진 통합
  • 크로스 플랫폼 지원
  • Dart-JavaScript 상호 운용성
  • 스크립트 평가를 위한 간단한 API
  • 여러 플랫폼을 지원합니다

적합한 대상

  • Flutter에서 JS 실행이 필요한 개발자
  • 동적 스크립트가 필요한 앱
  • 기존 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.