Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/flutter_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export 'quickjs-sync-server/quickjs_oasis_jsbridge.dart';
JavascriptRuntime getJavascriptRuntime({
bool forceJavascriptCoreOnAndroid = false,
bool xhr = true,
bool useFlutterTerminal = true,
Map<String, dynamic>? extraArgs = const {},
}) {
JavascriptRuntime runtime;
JavascriptRuntime.useFlutterTerminal = useFlutterTerminal;
if ((Platform.isAndroid && !forceJavascriptCoreOnAndroid)) {
int stackSize = extraArgs?['stackSize'] ?? 1024 * 1024;
runtime = QuickJsRuntime2(stackSize: stackSize);
Expand Down Expand Up @@ -168,6 +170,7 @@ class FlutterJs {
"convertTo": convertTo
};
final rs = await _methodChannel.invokeMethod("evaluate", arguments);

final String? jsResult = rs is Map || rs is List ? json.encode(rs) : rs;
if (DEBUG) {
print("${DateTime.now().toIso8601String()} - JS RESULT : $jsResult");
Expand Down
13 changes: 8 additions & 5 deletions lib/javascript_runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class FlutterJsPlatformEmpty extends JavascriptRuntime {

abstract class JavascriptRuntime {
static bool debugEnabled = false;
static bool useFlutterTerminal = true;

@protected
JavascriptRuntime init() {
Expand Down Expand Up @@ -112,11 +113,13 @@ abstract class JavascriptRuntime {
sendMessage('ConsoleLog', JSON.stringify(['error', ...arguments]));
}
}""");
onMessage('ConsoleLog', (dynamic args) {
args..removeAt(0);
String output = args.join(' ');
print(output);
});
if (useFlutterTerminal) {
onMessage('ConsoleLog', (dynamic args) {
args..removeAt(0);
String output = args.join(' ');
print(output);
});
}
}

void _setupSetTimeout() {
Expand Down