jsf 0.3.3
jsf: ^0.3.3 copied to clipboard
A high performance JavaScript engine, available out of the box in Flutter.
JavaScript in Flutter #
English 中文
A high performance JavaScript engine, available out of the box in Flutter.
Features #
- Simple and ready to use out of the box
- Up-to-date support for the latest QuickJS
- High-performance compilation strategy enabled by default
- Advanced features such as
big number
support enabled by default
Getting Started #
-
Add
jsf
as a dependency in yourpubspec.yaml
file. -
Just use it:
class Example extends StatefulWidget {
const Example({super.key});
@override
State<Example> createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
String _result = '';
final _js = JsRuntime();
void _runJS() {
final result = _js.eval('44 + 55');
setState(() {
_result = result;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('JavaScript in Flutter')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _runJS,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 40,
vertical: 20,
),
textStyle: const TextStyle(fontSize: 20),
),
child: const Text('Run: 44 + 55'),
),
const SizedBox(height: 20),
Text('Get $_result', style: const TextStyle(fontSize: 20)),
],
),
),
);
}
@override
void dispose() {
_js.dispose();
super.dispose();
}
}
Run flutter run
, then you will see:
[jsf_pic]