68 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Dart
		
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Dart
		
	
	
| 
 | |
| import 'package:flutter/material.dart';
 | |
| import 'package:qhd_prevention/pages/my_appbar.dart';
 | |
| import 'package:webview_flutter/webview_flutter.dart';
 | |
| 
 | |
| 
 | |
| class WebViewPage extends StatefulWidget {
 | |
|   final String url;
 | |
|   final String name;
 | |
| 
 | |
|   const WebViewPage({Key? key, required this.url, required this.name,}) : super(key: key);
 | |
| 
 | |
|   @override
 | |
|   State<WebViewPage> createState() => _WebViewPageState(name);
 | |
| 
 | |
| 
 | |
| }
 | |
| 
 | |
| class _WebViewPageState extends State<WebViewPage> {
 | |
|   late final WebViewController _controller;
 | |
|   final String name;
 | |
|   ValueNotifier<double> loadingProgress = ValueNotifier(0.0);
 | |
|   ValueNotifier<bool> isLoading = ValueNotifier(true);
 | |
| 
 | |
|   _WebViewPageState(this.name);
 | |
| 
 | |
|   @override
 | |
|   void initState() {
 | |
|     super.initState();
 | |
|     _controller = WebViewController()
 | |
|       ..setJavaScriptMode(JavaScriptMode.unrestricted)
 | |
|       ..setNavigationDelegate(NavigationDelegate(
 | |
|         onProgress: (progress) {
 | |
|           loadingProgress.value = progress / 100;
 | |
|           if (progress == 100) isLoading.value = false;
 | |
|         },
 | |
|         onPageStarted: (url) => isLoading.value = true,
 | |
|         onPageFinished: (url) => isLoading.value = false,
 | |
|       ))
 | |
|       ..loadRequest(Uri.parse(widget.url));
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     return Column(
 | |
|       children: [
 | |
|         MyAppbar(title: name,onBackPressed: () async {
 | |
|           if (await _controller.canGoBack()) {
 | |
|           _controller.goBack();
 | |
|           } else{
 | |
|             Navigator.of(context).pop();
 | |
|           }
 | |
|         },),
 | |
|         Expanded( child: WebViewWidget(controller: _controller),),
 | |
|         // ValueListenableBuilder<bool>(
 | |
|         //   valueListenable: isLoading,
 | |
|         //   builder: (context, loading, _) {
 | |
|         //     return loading
 | |
|         //         ? const Center(child: CircularProgressIndicator())
 | |
|         //         : const SizedBox();
 | |
|         //   },
 | |
|         // ),
 | |
|       ],
 | |
| 
 | |
|     );
 | |
| 
 | |
|   }
 | |
| } |