web_page.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:flutter/material.dart';
  2. import 'package:sport/services/app_subscription_state.dart';
  3. import 'package:sport/widgets/appbar.dart';
  4. import 'package:webview_flutter/webview_flutter.dart';
  5. class WebPage extends StatefulWidget {
  6. final String url;
  7. const WebPage({Key? key, required this.url}) : super(key: key);
  8. @override
  9. State<StatefulWidget> createState() => _PageState();
  10. }
  11. class _PageState extends State<WebPage> with SubscriptionState {
  12. WebViewController? _controller;
  13. int _onPageProgress = 0;
  14. @override
  15. void initState() {
  16. super.initState();
  17. }
  18. @override
  19. void dispose() {
  20. _controller = null;
  21. super.dispose();
  22. }
  23. _js(String call) {
  24. _controller?.evaluateJavascript("javascript:if(window.SHOES_SDK != undefined && window.SHOES_SDK != null) window.SHOES_SDK.$call");
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. String url = widget.url;
  29. return Scaffold(
  30. appBar: buildAppBar(context),
  31. body: Stack(
  32. fit: StackFit.expand,
  33. children: [
  34. WebView(
  35. initialUrl: url,
  36. javascriptMode: JavascriptMode.unrestricted,
  37. onWebViewCreated: (WebViewController webViewController) {
  38. _controller = webViewController;
  39. },
  40. onProgress: (progress) {
  41. setState(() {
  42. _onPageProgress = progress;
  43. });
  44. },
  45. onPageFinished: (r) {},
  46. ),
  47. if (_onPageProgress < 100.0)
  48. Positioned(
  49. top: 0,
  50. right: 0,
  51. left: 0,
  52. child: SizedBox(
  53. height: 5,
  54. child: LinearProgressIndicator(
  55. value: _onPageProgress / 100.0,
  56. ))),
  57. ],
  58. ),
  59. );
  60. }
  61. }