I recently started working on an old flutter app. After updating I now have a webview_flutter problem.
My code ran fine on the current version of the app but now I am facing issues and I don't know what to do.
import 'package:hvd/sidebar.dart';
import 'package:webview_flutter/webview_flutter.dart';
// This page shows the Bufkes website (https://bufkes.nl) for ordering online.
class Bufkes extends StatefulWidget {
Bufkes({Key? key}) : super(key: key);
@override
_Bufkes createState() => _Bufkes();
}
class _Bufkes extends State<Bufkes> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: SideBar(),
appBar: AppBar(
centerTitle: true,
title: Text('Bufkes (Tiel)'),
),
body: Container(
child: WebView(
initialUrl: 'https://bufkes.nl',
javascriptMode: JavascriptMode.unrestricted)));
}
}
Can someone please tell what is wrong? In the current code it says that I am not using the webview_flutter plugin...
Tank you all.
The webview_flutter
package had indeed breaking changes a few months ago.
The Widget is now called WebViewWidget
, and is used with a WebViewController.
Update your code to use them, like:
class _Bufkes extends State<Bufkes> {
final WebViewController _webViewController = WebViewController();
@override
void initState() {
super.initState();
_webViewController
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse('https://bufkes.nl'));
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: SideBar(),
appBar: AppBar(
centerTitle: true,
title: const Text('Bufkes (Tiel)'),
),
body: WebViewWidget(
controller: _webViewController,
),
);
}
}