|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
|
|
|
|
|
|
|
|
class PaymentView extends StatefulWidget {
|
|
|
|
final String? selectedUrl;
|
|
|
|
|
|
|
|
PaymentView({this.selectedUrl});
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PaymentViewState createState() => _PaymentViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PaymentViewState extends State<PaymentView> {
|
|
|
|
final flutterWebviewPlugin = new FlutterWebviewPlugin();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
// ignore: unnecessary_cast
|
|
|
|
flutterWebviewPlugin.onBack.listen((event) {
|
|
|
|
Navigator.pop(context);
|
|
|
|
} as void Function(Null)?);
|
|
|
|
flutterWebviewPlugin.onUrlChanged.listen((String url) {
|
|
|
|
print(url);
|
|
|
|
if (url.contains("#access_token")) {
|
|
|
|
succeed(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url.contains(
|
|
|
|
"https://www.facebook.com/connect/login_success.html?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied")) {
|
|
|
|
denied();
|
|
|
|
}
|
|
|
|
if (url.contains("https://expresspaygh.com/retry_later.php")) {
|
|
|
|
denied();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
denied() {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
succeed(String url) {
|
|
|
|
var params = url.split("access_token=");
|
|
|
|
|
|
|
|
var endparam = params[1].split("&");
|
|
|
|
flutterWebviewPlugin.clearCache();
|
|
|
|
flutterWebviewPlugin.cleanCookies();
|
|
|
|
flutterWebviewPlugin.dispose();
|
|
|
|
Navigator.pop(context, endparam[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Container(
|
|
|
|
height: MediaQuery.of(context).size.height,
|
|
|
|
margin: EdgeInsets.only(top: 10),
|
|
|
|
child: WebviewScaffold(
|
|
|
|
url: widget.selectedUrl!,
|
|
|
|
scrollBar: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|