You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
Dart
61 lines
1.9 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
class MyWebView extends StatefulWidget {
|
|
final String title;
|
|
final String selectedUrl;
|
|
|
|
MyWebView({
|
|
required this.title,
|
|
required this.selectedUrl,
|
|
});
|
|
|
|
@override
|
|
State<MyWebView> createState() => _MyWebViewState();
|
|
}
|
|
|
|
class _MyWebViewState extends State<MyWebView> {
|
|
// final Completer<WebViewController> _controller = Completer<WebViewController>();
|
|
late final WebViewController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = WebViewController()
|
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
|
..setNavigationDelegate(
|
|
NavigationDelegate(
|
|
onProgress: (int progress) {
|
|
// Update loading bar.
|
|
},
|
|
onPageStarted: (String url) {},
|
|
onPageFinished: (String url) {},
|
|
onHttpError: (HttpResponseError error) {},
|
|
onWebResourceError: (WebResourceError error) {},
|
|
onNavigationRequest: (NavigationRequest request) {
|
|
if (request.url.startsWith('https://www.youtube.com/')) {
|
|
return NavigationDecision.prevent;
|
|
}
|
|
return NavigationDecision.navigate;
|
|
},
|
|
),
|
|
)
|
|
..loadRequest(Uri.parse(widget.selectedUrl));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AppScaffold(isShowAppBar: true, appBarTitle: widget.title, isShowDecPage: false, showNewAppBar: true, showNewAppBarTitle: true, body: WebViewWidget(controller: _controller)
|
|
// WebView(
|
|
// initialUrl: widget.selectedUrl,
|
|
// javascriptMode: JavascriptMode.unrestricted,
|
|
// onWebViewCreated: (WebViewController webViewController) {
|
|
// _controller.complete(webViewController);
|
|
// },
|
|
);
|
|
}
|
|
}
|