flutter_js: ^0.0.2+1
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_js/flutter_js.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _jsResult = '';
int _idJsEngine = -1;
@override
void initState() {
super.initState();
initJsEngine();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initJsEngine() async {
try {
_idJsEngine = await FlutterJs.initEngine();
} on PlatformException catch (e) {
print('Failed to init js engine: ${e.details}');
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-ex

本文介绍了一个使用Flutter JS引擎的示例应用,展示了如何在Flutter项目中集成和使用JS引擎进行JavaScript代码的评估。通过创建一个简单的应用,演示了初始化JS引擎、评估JS表达式并获取结果的过程。
最低0.47元/天 解锁文章
788

被折叠的 条评论
为什么被折叠?



