Android 如何在Flatter WebView中处理多个选项卡?

Android 如何在Flatter WebView中处理多个选项卡?,android,flutter,flutter-dependencies,instamojo,Android,Flutter,Flutter Dependencies,Instamojo,我正在尝试使用本文在我的颤振应用程序中实现支付: 我正在用它。现在的问题是在付款过程中,Instamojo会打开另一个选项卡进行OTP验证。 但此新选项卡不会显示在应用程序中 如何处理颤振中的多个标签?我找不到任何支持多个浏览器选项卡的WebView插件 代码如下: import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_webview_plugin/flutter_webvi

我正在尝试使用本文在我的颤振应用程序中实现支付:

我正在用它。现在的问题是在付款过程中,Instamojo会打开另一个选项卡进行OTP验证。 但此新选项卡不会显示在应用程序中

如何处理颤振中的多个标签?我找不到任何支持多个浏览器选项卡的WebView插件

代码如下:

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:http/http.dart' as http;

class Insta extends StatefulWidget {
  @override
  _InstaState createState() => _InstaState();
}

class _InstaState extends State<Insta> {
  FlutterWebviewPlugin flutterWebviewPlugin = FlutterWebviewPlugin();

  @override
  void initState() {
    super.initState();
    createRequest(); //creating the HTTP request
// Add a listener on url changed
    flutterWebviewPlugin.onUrlChanged.listen((String url) {
      if (mounted) {
        if (url.contains('http://www.example.com/redirect')) {
          Uri uri = Uri.parse(url);
//Take the payment_id parameter of the url.
          String paymentRequestId = uri.queryParameters['payment_id'];
//calling this method to check payment status
          _checkPaymentStatus(paymentRequestId);
        }
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text('data'),
    );
  }

  _checkPaymentStatus(String id) async {
    var response = await http.get(
        Uri.encodeFull("https://t7+st.instamojo.com/api/1.1/payments/$id/"),
        headers: {
          "Accept": "application/json",
          "Content-Type": "application/x-www-form-urlencoded",
          "X-Api-Key": "**Hidden for security reasons**",
          "X-Auth-Token": "**Hidden for security reasons**"
        });
    var realResponse = json.decode(response.body);
    print(realResponse);
    if (realResponse['success'] == true) {
      if (realResponse["payment"]['status'] == 'Credit') {
        print('sucesssssssssssful');
//payment is successful.
      } else {
        print('failed');
//payment failed or pending.
      }
    } else {
      print("PAYMENT STATUS FAILED");
    }
  }

  static const kAndroidUserAgent =
      "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36";
  Future createRequest() async {
    Map<String, String> body = {
      "amount": "9", //amount to be paid
      "purpose": "Advertising",
      "buyer_name": '',
      "email": '',
      "phone": '',
      "allow_repeated_payments": "true",
      "send_email": "false",
      "send_sms": "false",
      "redirect_url": "http://www.example.com/redirect/",
      //Where to redirect after a successful payment.
      "webhook": "http://www.example.com/webhook/",
    };
//First we have to create a Payment_Request.
//then we'll take the response of our request.
    var resp = await http.post(
        Uri.encodeFull("https://www.instamojo.com/api/1.1/payment-requests/"),
        headers: {
          "Accept": "application/json",
          "Content-Type": "application/x-www-form-urlencoded",
          "X-Api-Key": "**Hidden for security reasons**",
          "X-Auth-Token": "**Hidden for security reasons**"
        },
        body: body);
    if (json.decode(resp.body)['success'] == true) {
//If request is successful take the longurl.
      String selectedUrl =
          json.decode(resp.body)["payment_request"]['longurl'].toString() +
              "?embed=form";
      flutterWebviewPlugin.close();
//Let's open the url in webview.
      flutterWebviewPlugin.launch(selectedUrl,
          rect: new Rect.fromLTRB(
              5.0,
              MediaQuery.of(context).size.height / 7,
              MediaQuery.of(context).size.width - 5.0,
              7 * MediaQuery.of(context).size.height / 7),
          userAgent: kAndroidUserAgent);
    } else {
      print(json.decode(resp.body)['message'].toString());
//If something is wrong with the data we provided to
//create the Payment_Request. For Example, the email is in incorrect format, the payment_Request creation will fail.
    }
  }
}
导入'dart:convert';
进口“包装:颤振/材料.省道”;
导入“包:flatter_webview_plugin/flatter_webview_plugin.dart”;
将“package:http/http.dart”导入为http;
Insta类扩展了StatefulWidget{
@凌驾
_InstaState createState();
}
类_InstaState扩展了State{
FlatterWebViewPlugin FlatterWebViewPlugin=FlatterWebViewPlugin();
@凌驾
void initState(){
super.initState();
createRequest();//创建HTTP请求
//在更改的url上添加侦听器
FlightWebViewPlugin.onUrlChanged.listen((字符串url){
如果(已安装){
if(url.contains('http://www.example.com/redirect')) {
Uri=Uri.parse(url);
//获取url的payment_id参数。
字符串paymentRequestId=uri.queryParameters['payment_id'];
//调用此方法检查付款状态
_checkPaymentStatus(paymentRequestId);
}
}
});
}
@凌驾
小部件构建(构建上下文){
返回容器(
子项:文本(“数据”),
);
}
_checkPaymentStatus(字符串id)异步{
var response=wait http.get(
Uri.encodeFull(“https://t7+st.instamojo.com/api/1.1/payments/$id/”,
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/x-www-form-urlencoded”,
“X-Api-Key”:“**出于安全原因隐藏**”,
“X-Auth-Token”:“**出于安全原因而隐藏**”
});
var realResponse=json.decode(response.body);
打印(realResponse);
if(realResponse['success']==true){
如果(realResponse[“付款”][“状态”]=“信用证”){
打印(“成功”);
//付款成功。
}否则{
打印(“失败”);
//付款失败或挂起。
}
}否则{
打印(“付款状态失败”);
}
}
静态常数kAndroidUserAgent=
“Mozilla/5.0(Linux;Android 6.0;Nexus 5 Build/MRA58N)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/62.0.3202.94 Mobile Safari/537.36”;
Future createRequest()异步{
地图正文={
“金额”:“9”,//应支付的金额
“目的”:“广告”,
“买方名称”:“,
“电子邮件”:“”,
“电话”:“”,
“允许重复付款”:“真”,
“发送电子邮件”:“错误”,
“发送短信”:“假”,
“重定向url”:http://www.example.com/redirect/",
//成功付款后重定向到何处。
“webhook”:http://www.example.com/webhook/",
};
//首先,我们必须创建一个付款请求。
//然后我们将对我们的请求作出回应。
var resp=wait http.post(
Uri.encodeFull(“https://www.instamojo.com/api/1.1/payment-requests/"),
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/x-www-form-urlencoded”,
“X-Api-Key”:“**出于安全原因隐藏**”,
“X-Auth-Token”:“**出于安全原因而隐藏**”
},
身体:身体),;
if(json.decode(resp.body)['success']==true){
//如果请求成功,则使用longurl。
字符串selectedUrl=
json.decode(resp.body)[“付款请求”][longurl'].toString()+
“?嵌入=形式”;
webviewplugin.close();
//让我们在webview中打开url。
flatterwebviewplugin.launch(selectedUrl,
rect:new rect.fromLTRB(
5.0,
MediaQuery.of(context).size.height/7,
MediaQuery.of(context).size.width-5.0,
7*MediaQuery.of(context.size.height/7),
用户代理:kAndroidUserAgent);
}否则{
打印(json.decode(resp.body)['message'].toString());
//如果我们提供给你的数据有问题
//创建付款请求。例如,电子邮件格式不正确,付款请求创建将失败。
}
}
}

该插件存在一个未决问题是的,我知道!但至少现在我正在寻找一个解决办法。