I’m using the webview_flutter plugin from the Flutter Team.
Steps
- Add the dependency to pubspec.yaml:
dependencies:
webview_flutter: ^4.2.1
-
Put an html file in the
assets
folder (see this). I’ll call ithelp.html
. -
Declare it in your pubspec.yaml file:
flutter:
assets:
- assets/help.html
- Use it in your code:
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class HelpScreen extends StatefulWidget {
const HelpScreen({super.key});
@override
State<HelpScreen> createState() => _HelpScreenState();
}
class _HelpScreenState extends State<HelpScreen> {
late final WebViewController _controller;
@override
void initState() {
super.initState();
_controller = WebViewController();
_controller.loadFlutterAsset('assets/help.html');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: WebViewWidget(controller: _controller),
);
}
}
Notes
There are lots of other things you can do with a web view (including running JavaScript). Check out the following links for more:
- Adding WebView to your Flutter app (official codelab)
- Plugin example