flutter_quickjs 1.0.3
flutter_quickjs: ^1.0.3 copied to clipboard

Flutter Android iOS

Flutter bindings with dart:ffi for QuickJS,a small Javascript engine supports ES2020.

flutter_quickjs #

Flutter bindings with dart:ffi for QuickJS : A small Javascript engine supports ES2020.

This is a plugin help execute javascript on flutter app, which is convenient to use with simple apis, and it supports iOS, Android now.

Install #

To use this plugin, add flutter_quickjs as a dependency in your pubspec.yaml file.

Usage #

Basic Example #

import 'package:flutter/material.dart';
import 'package:flutter_quickjs/flutter_quickjs.dart';

void main() {
  var evalResult = runJs();
  runApp(
    MaterialApp(
      home: Material(
        child: Center(
          child: Text(evalResult),
        ),
      ),
    ),
  );
}

runJs() {
  var qjs = FlutterQuickjs();
  var res = qjs.eval('Math.PI');
  qjs.close();
  return res.toString();
}

Global Object #

qjs.eval('var a = 666;');
print(qjs.global()['a']);
// 666

Set Value #

qjs.setValue('globalThis.console.log', (msg) {
  print(msg);
});
qjs.eval('console.log("hello world!")');
// hello world!

JS Function Call #

var func = qjs.eval('function func(a, b){return [a, b, a + b];}func');
print(func(2,3));
// [2, 3, 5]

For more usages please see example

Datatype Mapping #

dartjs
nullUndefined / Null
BoolBoolean
IntNumber
DoubleNumber
StringString
ListArray
MapObject
FunctionFunction
ExceptionError

Todo #

  • bytecode support
  • support more platforms like macos,linux

Reference #

Lincense #

MIT © ZhangPingFan

3
likes
80
pub points
7%
popularity

Publisher

neverlose.com.cn

Flutter bindings with dart:ffi for QuickJS,a small Javascript engine supports ES2020.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

ffi, flutter

More

Packages that depend on flutter_quickjs