YSWebLoad.dart 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'dart:convert';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:url_launcher/url_launcher.dart';
  5. import 'package:webview_flutter/webview_flutter.dart';
  6. import 'package:ysairplane2/base/YSBase.dart';
  7. import 'package:ysairplane2/tools/YSNetWorking.dart';
  8. class YSWebLoad extends StatefulWidget {
  9. final type;
  10. const YSWebLoad({Key key, this.type}) : super(key: key);
  11. @override
  12. _YSWebLoadState createState() => _YSWebLoadState();
  13. }
  14. class _YSWebLoadState extends State<YSWebLoad> {
  15. WebViewController _controller;
  16. @override
  17. Widget build(BuildContext context) {
  18. return YSBase(
  19. ystitle: widget.type==null?'产品简介':widget.type==1?'软件许可及服务协议':widget.type==3?'用户协议':'隐私保护协议',
  20. yschild: Container(
  21. color: Colors.white,
  22. width: MediaQuery.of(context).size.width,
  23. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
  24. child: widget.type==1||widget.type==2?WebView(
  25. javascriptMode: JavascriptMode.unrestricted,
  26. onWebViewCreated: (WebViewController webViewController) {
  27. _controller = webViewController;
  28. _getHtmlData();
  29. },
  30. ):WebView(
  31. initialUrl: widget.type==3?'https://api.s-fly.cn/txt/用户协议.html':'http://www.s-fly.cn',
  32. javascriptMode: JavascriptMode.unrestricted,
  33. navigationDelegate: (NavigationRequest request) {
  34. if(request.url.contains("mailto:")||request.url.contains("tel:")){
  35. launch(request.url);
  36. return NavigationDecision.prevent;
  37. }else if(request.url.contains("qq")){
  38. print('================${request.url}');
  39. return NavigationDecision.prevent;
  40. }
  41. return NavigationDecision.navigate;
  42. },
  43. ),
  44. ),
  45. );
  46. }
  47. _getHtmlData() async{
  48. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/dic/dtDic/${widget.type==1?'getServiceAgreement':'getPrivacyAgreement'}',parameter: {},isLoading: false,isToken: true);
  49. if(dict!=null){
  50. _controller.loadUrl(Uri.dataFromString('${dict['data']['value']}', mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  51. }
  52. }
  53. }