Hi, thank you for the assistance. I managed to manipulate the cube using “window.cube” and declaring the cube outside of the createScene method in my html file. At first it did not work, because I had not set up the WebViewController correctly. I used this flutter_webview example as a reference: plugins/main.dart at master · flutter/plugins · GitHub
Also thank you kevmoo for the suggestion, it is good to know a different approach for this. This works for me now so I will go with it for now:)
Here is my code for anyone else having trouble with this. By pressing a button, the sphere moves upwards, one step at a time.
import ‘dart:async’;
import ‘package:flutter/material.dart’;
import ‘package:webview_flutter/webview_flutter.dart’;
void main() => runApp(MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
final Completer _controller =
Completer();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(‘Flutter WebView example’),
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: ‘file:///android_asset/flutter_assets/assets/bjs.html’,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
);
}),
floatingActionButton: someButton(),
);
}
Widget someButton() {
return FutureBuilder(
future: _controller.future,
builder: (BuildContext context,
AsyncSnapshot controller) {
if (controller.hasData) {
return FloatingActionButton(
onPressed: () async {
_onChangePosition(controller.data, context);
},
child: const Icon(Icons.arrow_upward),
);
}
return Container();
});
}
void _onChangePosition(
WebViewController controller, BuildContext context) async {
final String cookies =
await controller.evaluateJavascript(‘window.sphere.position.y += 1;’);
print(cookies);
}
}
Sorry for the poor formatting, I couldn’t figure out how to keep the indents.