news_detail_page.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
  4. class NewsDetailPage extends StatefulWidget {
  5. String? id;
  6. NewsDetailPage({Key? key, this.id}):super(key: key);
  7. @override
  8. State<StatefulWidget> createState() => NewsDetailPageState(id: this.id);
  9. }
  10. class NewsDetailPageState extends State<NewsDetailPage> {
  11. String? id;
  12. bool loaded = false;
  13. String? detailDataStr;
  14. final flutterWebViewPlugin = FlutterWebviewPlugin();
  15. NewsDetailPageState({Key? key, this.id});
  16. @override
  17. void initState() {
  18. super.initState();
  19. // 监听WebView的加载事件
  20. flutterWebViewPlugin.onStateChanged.listen((state) {
  21. print("state: ${state.type}");
  22. if (state.type == WebViewState.finishLoad) {
  23. // 加载完成
  24. setState(() {
  25. loaded = true;
  26. });
  27. }
  28. });
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. List<Widget> titleContent = [];
  33. titleContent.add(Text("资讯详情", style: TextStyle(color: Colors.white),));
  34. if (!loaded) {
  35. titleContent.add(CupertinoActivityIndicator());
  36. }
  37. titleContent.add(Container(width: 50.0));
  38. return WebviewScaffold(
  39. url: this.id!,
  40. appBar: AppBar(
  41. title: Row(
  42. mainAxisAlignment: MainAxisAlignment.center,
  43. children: titleContent,
  44. ),
  45. iconTheme: IconThemeData(color: Colors.white),
  46. ),
  47. withZoom: false,
  48. withLocalStorage: true,
  49. withJavascript: true,
  50. );
  51. }
  52. }