83 lines
2.6 KiB
Dart
83 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
import 'package:webview_flutter_android/webview_flutter_android.dart';
|
|
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';
|
|
|
|
class WebViewPage extends StatefulWidget {
|
|
const WebViewPage({super.key});
|
|
|
|
@override
|
|
State<WebViewPage> createState() => _WebViewPageState();
|
|
}
|
|
|
|
class _WebViewPageState extends State<WebViewPage> {
|
|
late final WebViewController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
late final PlatformWebViewControllerCreationParams params;
|
|
if (WebViewPlatform.instance is WebKitWebViewPlatform) {
|
|
params = WebKitWebViewControllerCreationParams(
|
|
allowsInlineMediaPlayback: true,
|
|
mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
|
|
);
|
|
} else {
|
|
params = const PlatformWebViewControllerCreationParams();
|
|
}
|
|
|
|
final WebViewController controller =
|
|
WebViewController.fromPlatformCreationParams(params);
|
|
|
|
controller
|
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
|
..setBackgroundColor(const Color(0x00000000))
|
|
..setNavigationDelegate(
|
|
NavigationDelegate(
|
|
onProgress: (int progress) {
|
|
debugPrint('WebView is loading (progress : $progress%)');
|
|
},
|
|
onPageStarted: (String url) {
|
|
debugPrint('Page started loading: $url');
|
|
},
|
|
onPageFinished: (String url) {
|
|
debugPrint('Page finished loading: $url');
|
|
},
|
|
onWebResourceError: (WebResourceError error) {
|
|
debugPrint('''
|
|
Page resource error:
|
|
code: ${error.errorCode}
|
|
description: ${error.description}
|
|
errorType: ${error.errorType}
|
|
isForMainFrame: ${error.isForMainFrame}
|
|
''');
|
|
},
|
|
),
|
|
)
|
|
..loadFlutterAsset(
|
|
'assets/www/index.html',
|
|
); // CHANGED: Load Home directly
|
|
|
|
if (controller.platform is AndroidWebViewController) {
|
|
AndroidWebViewController.enableDebugging(true);
|
|
(controller.platform as AndroidWebViewController)
|
|
.setMediaPlaybackRequiresUserGesture(false);
|
|
}
|
|
|
|
_controller = controller;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// We want the WebView to control the full screen, including status bar usually,
|
|
// but SafeArea might be needed if the Web content doesn't handle padding.
|
|
// Our CSS handles env(safe-area-inset-top), so we can disable SafeArea here
|
|
// or keep top:false.
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
body: WebViewWidget(controller: _controller),
|
|
);
|
|
}
|
|
}
|