flutter_jscore 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

flutter_jscore #

License Awesome Flutter Pub

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

Demo

Screen recordingApk
CodeDownload

Getting Started #

Add dependency

// 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

Super simple to use

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 (coming soon)
  • Linux (coming soon)

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.

0.1.1 #

Fix: Some callback functions have no return value type.
Add: JavaScript context group create constructor.
Update: Transfer JavaScript context group retain and release functions to JSContextGroup.

0.1.0 #

Add: flutter_jscore example.
Update: documentation.

0.0.1 #

Add: JavaScript for Flutter.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter_jscore/flutter_jscore.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'flutter_jscore',
      home: _JSCorePage(),
    );
  }
}

class _JSCorePage extends StatefulWidget {
  @override
  _JSCorePageState createState() => _JSCorePageState();
}

class _JSCorePageState extends State<_JSCorePage> {
  TextEditingController _jsInputController;
  JSContext _jsContext;

  @override
  void initState() {
    super.initState();
    _jsContext = JSContext.createInGroup();
    _jsInputController = TextEditingController(text: '1 + 1');
  }

  @override
  void dispose() {
    _jsContext.release();
    _jsInputController.dispose();
    super.dispose();
  }

  String _runJs(String script) {
    var jsValue = _jsContext.evaluate(script);
    return jsValue.string;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('JavaScriptCore for Flutter'),
      ),
      body: TextField(
        maxLines: 50,
        decoration: InputDecoration(
          border: InputBorder.none,
        ),
        controller: _jsInputController,
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          showDialog(
            context: context,
            builder: (context) {
              return AlertDialog(
                title: Text('Result'),
                content: Text(_runJs(_jsInputController.text ?? '')),
              );
            },
          );
        },
        child: Icon(Icons.autorenew),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_jscore: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_jscore/flutter_jscore.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
ffi ^0.1.3 0.1.3
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test