Hi Im new to flutter and this is the only remaining problem I have for my very first app to be finished, for some reason the injected javascript I used is not appearing in the WebView app.
FIXED (sorry for the delayed edit: the code was (await _controller.future).evaluateJavascript("document.getElementsByClassName('footer-container')[0].style.display='none';")
Note: Im using the webview_flutter by the flutter dev team and I want to have BOTH refresh FAB and injected code working at the same time
my code is below:
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
WebViewController _myController;
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: WebView(
initialUrl: 'https://syncshop.online/en/',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_controller.complete(controller);
},
onPageFinished: (controller) {
_myController.evaluateJavascript("document.getElementsByClassName('footer-container')[0].style.display='none';");
},
),
floatingActionButton: FutureBuilder<WebViewController>(
future: _controller.future,
builder: (BuildContext context, AsyncSnapshot<WebViewController> controller) {
if (controller.hasData) {
return FloatingActionButton(
onPressed: () {
controller.data.reload();
},
child: Icon(Icons.refresh),
);
}
return Container();
}),
),
);
}
}
I think, _myController is not assigned anything.
So, Instead try using the _controller for evaluateJavascript(). Like this:
(await _controller.future).evaluateJavascript("document.getElementsByClassName('footer-container')[0].style.display='none';");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With