We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PS E:\flutter\js_demo> flutter --version Flutter 3.22.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 761747bfc5 (6 weeks ago) • 2024-06-05 22:15:13 +0200 Engine • revision edd8546116 Tools • Dart 3.4.3 • DevTools 2.34.3
flutter_js version: flutter_js: ^0.8.1
flutter_js: ^0.8.1
environment
Click the test async button to print:
test async
I/flutter (15640): test async: Instance of 'Future<dynamic>' false
This is wrong. jsEvalResult.isPromise is wrong.
Click the test async2 button to print the content correctly
test async2
Demo
import 'package:flutter/material.dart'; import 'package:flutter_js/flutter_js.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { late JavascriptRuntime javascriptRuntime; @override void initState() { super.initState(); javascriptRuntime = getJavascriptRuntime(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ FilledButton( onPressed: () { JsEvalResult jsEvalResult = javascriptRuntime.evaluate("2 + 3"); debugPrint('test: ${jsEvalResult.stringResult} ${jsEvalResult.isError}'); }, child: const Text("test")), FilledButton( onPressed: () async { JsEvalResult jsEvalResult = javascriptRuntime.evaluate(""" (async function() { const promise = new Promise((resolve, reject) => { setTimeout(() => { try { resolve("async ok"); } catch (error) { reject(error); } }, 2000); }); const result = await promise; console.log("result", typeof result, result); return result; })(); """); if (jsEvalResult.isPromise) { jsEvalResult = await javascriptRuntime.handlePromise(jsEvalResult); } debugPrint('test async: ${jsEvalResult.stringResult} ${jsEvalResult.isError}'); }, child: const Text("test async")), FilledButton( onPressed: () async { JsEvalResult jsEvalResult = javascriptRuntime.evaluate(""" (async function() { const promise = new Promise((resolve, reject) => { setTimeout(() => { try { resolve("async ok"); } catch (error) { reject(error); } }, 2000); }); const result = await promise; console.log("result", typeof result, result); return result; })(); """); if (jsEvalResult.isPromise || jsEvalResult.stringResult == "Instance of 'Future<dynamic>'") { jsEvalResult = await javascriptRuntime.handlePromise(jsEvalResult); } debugPrint('test async: ${jsEvalResult.stringResult} ${jsEvalResult.isError}'); }, child: const Text("test async2")) ], ), ), ); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
flutter_js version:
flutter_js: ^0.8.1
environment
Click the
test async
button to print:This is wrong. jsEvalResult.isPromise is wrong.
Click the
test async2
button to print the content correctlyDemo
The text was updated successfully, but these errors were encountered: