YSNote.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_inappwebview/flutter_inappwebview.dart';
  5. // import 'package:flutter_webview_pro/webview_flutter.dart';
  6. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  7. class YSNote extends StatefulWidget {
  8. @override
  9. _YSNoteState createState() => _YSNoteState();
  10. }
  11. class _YSNoteState extends State<YSNote> {
  12. String webStr;
  13. final GlobalKey webViewKey = GlobalKey();
  14. InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
  15. crossPlatform: InAppWebViewOptions(
  16. useShouldOverrideUrlLoading: true,
  17. mediaPlaybackRequiresUserGesture: false,
  18. ),
  19. /// android 支持HybridComposition
  20. android: AndroidInAppWebViewOptions(
  21. useHybridComposition: true,
  22. ),
  23. ios: IOSInAppWebViewOptions(
  24. allowsInlineMediaPlayback: true,
  25. ),
  26. );
  27. @override
  28. void initState() {
  29. Future.delayed(Duration(seconds: 0)).then((value){
  30. _getNoteWebData();
  31. });
  32. super.initState();
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return AnnotatedRegion<SystemUiOverlayStyle>(
  37. value: SystemUiOverlayStyle.light,
  38. child: CupertinoPageScaffold(
  39. child: Container(
  40. height: MediaQuery.of(context).size.height,
  41. width: MediaQuery.of(context).size.width,
  42. color: Colors.white,
  43. child: Column(
  44. children: [
  45. Container(
  46. height: MediaQuery.of(context).padding.top,
  47. color: Color.fromARGB(255, 255, 102, 137),
  48. ),
  49. Container(
  50. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-50,
  51. child: webStr==null?Container():InAppWebView(
  52. key: webViewKey,
  53. initialUrlRequest: URLRequest(url: Uri.parse(webStr)),
  54. initialOptions: options,
  55. shouldOverrideUrlLoading: (controller, navigationAction) async {
  56. var uri = navigationAction.request.url;
  57. if (![ "http", "https", "file", "chrome",
  58. "data", "javascript", "about"].contains(uri.scheme)) {
  59. }
  60. return NavigationActionPolicy.ALLOW;
  61. },
  62. ),
  63. )
  64. ],
  65. ),
  66. ),
  67. ),
  68. );
  69. }
  70. _getNoteWebData() async{
  71. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'basic/info', {});
  72. if(dict!=null){
  73. setState(() {
  74. webStr = dict['data']['album']??'';
  75. });
  76. }
  77. }
  78. }