web_page.dart 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 WebPage extends StatefulWidget {
  6. final String url;
  7. final String? title;
  8. WebPage({required this.url, this.title});
  9. @override
  10. _WebPageState createState() => _WebPageState();
  11. }
  12. class _WebPageState extends State<WebPage> {
  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:
  28. Text(widget.title ?? '', style: TextStyle(color: Colors.black87)),
  29. leading: IconButton(
  30. onPressed: () => Navigator.maybePop(context),
  31. icon: Icon(Icons.arrow_back_ios, color: Colors.black87),
  32. ),
  33. actions: <Widget>[
  34. GestureDetector(
  35. onTap: () {
  36. Share.share(this.widget.url);
  37. },
  38. child: Image.asset('assets/img/icon_menu_share.png'),
  39. )
  40. ],
  41. ),
  42. body: WebViewWidget(controller: controller!),
  43. );
  44. }
  45. }