123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:webview_flutter/webview_flutter.dart';
- //公共的WebView页面,需要标题和URL参数
- class CommonWebPage extends StatefulWidget {
- String? title;
- String? url;
- CommonWebPage({Key? key, this.title, this.url}) : super(key: key);
- @override
- State<StatefulWidget> createState() {
- return CommonWebPageState();
- }
- }
- class CommonWebPageState extends State<CommonWebPage> {
- bool loading = true;
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- WebViewController webViewController = WebViewController()
- ..setUserAgent("Android OSC")
- ..setJavaScriptMode(JavaScriptMode.unrestricted)
- ..setBackgroundColor(const Color(0x00000000))
- ..setNavigationDelegate(
- NavigationDelegate(
- onProgress: (int progress) {
- // Update loading bar.
- },
- onPageStarted: (String url) {},
- onPageFinished: (String url) {},
- onWebResourceError: (WebResourceError error) {},
- ),
- )
- ..loadRequest(Uri.parse(widget.url!));
- List<Widget> titleContent = [];
- titleContent.add(Text(
- widget.title!,
- style: TextStyle(color: Colors.white),
- ));
- if (loading) {
- titleContent.add(CupertinoActivityIndicator());
- }
- titleContent.add(Container(width: 50.0));
- return WebViewWidget(
- controller: webViewController,
- );
- }
- }
|