web_scene.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:webview_flutter/webview_flutter.dart';
  4. import 'package:share/share.dart';
  5. class WebScene extends StatefulWidget {
  6. final String url;
  7. final String? title;
  8. WebScene({required this.url, this.title});
  9. @override
  10. _WebSceneState createState() => _WebSceneState();
  11. }
  12. class _WebSceneState extends State<WebScene> {
  13. WebViewController? controller;
  14. @override
  15. void initState() {
  16. super.initState();
  17. controller = WebViewController()
  18. ..setJavaScriptMode(JavaScriptMode.unrestricted)
  19. ..loadRequest(Uri.parse(widget.url));
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return Scaffold(
  24. appBar: AppBar(
  25. systemOverlayStyle: SystemUiOverlayStyle.dark,
  26. backgroundColor: Colors.white,
  27. title: Text(widget.title ?? '', style: TextStyle(color: Colors.black87)),
  28. leading: IconButton(
  29. onPressed: () => Navigator.maybePop(context),
  30. icon: Icon(Icons.arrow_back_ios, color: Colors.black87),
  31. ),
  32. actions: <Widget>[
  33. GestureDetector(
  34. onTap: () {
  35. Share.share(this.widget.url);
  36. },
  37. child: Image.asset('img/icon_menu_share.png'),
  38. )
  39. ],
  40. ),
  41. body: WebViewWidget(controller: controller!),
  42. );
  43. }
  44. }