webview_all 1.0.2
webview_all: ^1.0.2 copied to clipboard
A Flutter plugin that provides a WebView widget with full-platform support.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:webview_all/webview_all.dart';
void main() {
runApp(const BilibiliApp());
}
class BilibiliApp extends StatelessWidget {
const BilibiliApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Bilibili Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
),
home: const BilibiliPage(),
);
}
}
class BilibiliPage extends StatefulWidget {
const BilibiliPage({super.key});
@override
State<BilibiliPage> createState() => _BilibiliPageState();
}
class _BilibiliPageState extends State<BilibiliPage> {
late final WebViewController _controller;
int _progress = 0;
@override
void initState() {
super.initState();
_controller = WebViewController();
if (!kIsWeb) {
_controller
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
if (mounted) {
setState(() {
_progress = progress;
});
}
},
onPageStarted: (String url) {
debugPrint('Loading $url');
},
onPageFinished: (String url) {
debugPrint('Finished $url');
if (mounted) {
setState(() {
_progress = 100;
});
}
},
onWebResourceError: (WebResourceError error) {
debugPrint('Error ${error.errorCode}: ${error.description}');
},
),
);
}
_controller.loadRequest(Uri.parse('https://www.bilibili.com'));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Bilibili APP'),
actions: <Widget>[
if (!kIsWeb)
IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () async {
if (await _controller.canGoBack()) {
await _controller.goBack();
}
},
),
if (!kIsWeb)
IconButton(
icon: const Icon(Icons.arrow_forward),
onPressed: () async {
if (await _controller.canGoForward()) {
await _controller.goForward();
}
},
),
if (!kIsWeb)
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
_controller.reload();
},
),
],
bottom: PreferredSize(
preferredSize: const Size.fromHeight(3),
child: !kIsWeb && _progress < 100
? LinearProgressIndicator(value: _progress / 100)
: const SizedBox(height: 3),
),
),
body: WebViewWidget(controller: _controller),
);
}
}