import 'package:chat/generated/i18n.dart';
import 'package:chat/utils/CustomUI.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class WebviewPage extends StatefulWidget {
  final String url;

  WebviewPage(this.url);

  @override
  State<StatefulWidget> createState() {
    return WebviewPageState();
  }
}

class WebviewPageState extends State<WebviewPage> {
  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
//      url: "https://www.sandbox.paypal.com/checkoutnow?token=3WB31189WV294590T",
      url: widget.url,
//      url: 'https://cypayos.yht521.com/api/payment/paypal_return?pay_type=paypal_web&success=true&token=5D224968VR002563M&PayerID=B9PMKYC3EB3B4',
      withJavascript: true,

      javascriptChannels: <JavascriptChannel>[
        ///与后端约定好的， js调用 Methods.postMessage("post")
        JavascriptChannel(
            name: "Methods",
            onMessageReceived: (JavascriptMessage message) {
//                      print("参数： ${message.message}");
              if (message.message == 'close') {
                Navigator.of(context).pop();
              }
            }),
      ].toSet(),
      appBar: AppBar(
        title: Text(
          I18n.of(context).sign_in,
          textScaleFactor: 1.0,
          style: TextStyle(color: Colors.white),
        ),
        leading: CustomUI.buildCustomLeading(context),
        centerTitle: true,
      ),
    );
  }
}
