import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
// import 'package:flutter_webview_pro/webview_flutter.dart';
import 'package:flutterappfuyou/code/base/YSNetWorking.dart';

class YSNote extends StatefulWidget {
  @override
  _YSNoteState createState() => _YSNoteState();
}

class _YSNoteState extends State<YSNote> {
  String webStr;
  final GlobalKey webViewKey = GlobalKey();
  InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
    crossPlatform: InAppWebViewOptions(
      useShouldOverrideUrlLoading: true,
      mediaPlaybackRequiresUserGesture: false,
    ),
    /// android 支持HybridComposition
    android: AndroidInAppWebViewOptions(
      useHybridComposition: true,
    ),
    ios: IOSInAppWebViewOptions(
      allowsInlineMediaPlayback: true,
    ),
  );
  @override
  void initState() {
    Future.delayed(Duration(seconds: 0)).then((value){
      _getNoteWebData();
    });
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.light,
      child: CupertinoPageScaffold(
        child: Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          color: Colors.white,
          child: Column(
            children: [
              Container(
                height: MediaQuery.of(context).padding.top,
                color: Color.fromARGB(255, 255, 102, 137),
              ),
              Container(
                height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-50,
                child: webStr==null?Container():InAppWebView(
                  key: webViewKey,
                  initialUrlRequest: URLRequest(url: Uri.parse(webStr)),
                  initialOptions: options,
                  shouldOverrideUrlLoading: (controller, navigationAction) async {
                    var uri = navigationAction.request.url;
                    if (![ "http", "https", "file", "chrome",
                      "data", "javascript", "about"].contains(uri.scheme)) {
                    }
                    return NavigationActionPolicy.ALLOW;
                  },
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  _getNoteWebData() async{
    Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'basic/info', {});
    if(dict!=null){
      setState(() {
        webStr = dict['data']['album']??'';
      });
    }
  }
}