12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
- class NewsDetailPage extends StatefulWidget {
- String? id;
- NewsDetailPage({Key? key, this.id}):super(key: key);
- @override
- State<StatefulWidget> createState() => NewsDetailPageState(id: this.id);
- }
- class NewsDetailPageState extends State<NewsDetailPage> {
- String? id;
- bool loaded = false;
- String? detailDataStr;
- final flutterWebViewPlugin = FlutterWebviewPlugin();
- NewsDetailPageState({Key? key, this.id});
- @override
- void initState() {
- super.initState();
- // 监听WebView的加载事件
- flutterWebViewPlugin.onStateChanged.listen((state) {
- print("state: ${state.type}");
- if (state.type == WebViewState.finishLoad) {
- // 加载完成
- setState(() {
- loaded = true;
- });
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- List<Widget> titleContent = [];
- titleContent.add(Text("资讯详情", style: TextStyle(color: Colors.white),));
- if (!loaded) {
- titleContent.add(CupertinoActivityIndicator());
- }
- titleContent.add(Container(width: 50.0));
- return WebviewScaffold(
- url: this.id!,
- appBar: AppBar(
- title: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: titleContent,
- ),
- iconTheme: IconThemeData(color: Colors.white),
- ),
- withZoom: false,
- withLocalStorage: true,
- withJavascript: true,
- );
- }
- }
|