flutter_jscore 1.0.0 copy "flutter_jscore: ^1.0.0" to clipboard
flutter_jscore: ^1.0.0 copied to clipboard

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

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> {
  late TextEditingController _jsInputController;
  late 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 ?? 'No result';
  }

  @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),
      ),
    );
  }
}
39
likes
140
pub points
60%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

ffi, flutter

More

Packages that depend on flutter_jscore