|
1 | | -import 'package:flutter/material.dart'; |
2 | | -import 'package:flutter/widgets.dart'; |
3 | | -import 'package:flutterwave_standard/core/transaction_status.dart'; |
| 1 | +import 'package:flutter_inappwebview/flutter_inappwebview.dart'; |
| 2 | +import 'package:flutterwave_standard/core/TransactionCallBack.dart'; |
| 3 | +import 'package:flutterwave_standard/view/FlutterwaveWebView.dart'; |
4 | 4 | import 'package:flutterwave_standard/view/flutterwave_style.dart'; |
5 | | -import 'package:flutterwave_standard/view/webview.dart'; |
6 | 5 | import 'package:http/http.dart'; |
7 | 6 |
|
8 | 7 | import '../models/TransactionError.dart'; |
9 | 8 | import '../models/requests/standard_request.dart'; |
10 | | -import '../models/responses/charge_response.dart'; |
11 | 9 | import '../models/responses/standard_response.dart'; |
12 | 10 |
|
13 | 11 | class NavigationController { |
14 | | - BuildContext _buildContext; |
15 | 12 | Client client; |
16 | 13 | final FlutterwaveStyle? style; |
| 14 | + final TransactionCallBack _callBack; |
17 | 15 |
|
18 | | - NavigationController(this._buildContext, this.client, this.style); |
19 | | - |
| 16 | + NavigationController(this.client, this.style, this._callBack); |
20 | 17 |
|
21 | 18 | /// Initiates initial transaction to get web url |
22 | | - Future<ChargeResponse> startTransaction(final StandardRequest request) async { |
| 19 | + startTransaction(final StandardRequest request) async { |
23 | 20 | try { |
24 | 21 | final StandardResponse standardResponse = |
25 | | - await request.execute(this.client); |
| 22 | + await request.execute(this.client); |
26 | 23 | if (standardResponse.status == "error") { |
27 | 24 | throw (TransactionError(standardResponse.message!)); |
28 | 25 | } |
29 | | - final Map response = await openBrowser( |
| 26 | + openBrowser( |
30 | 27 | standardResponse.data?.link ?? "", request.redirectUrl); |
31 | | - return _handleResponse(response); |
32 | 28 | } catch (error) { |
33 | 29 | throw (error); |
34 | 30 | } |
35 | 31 | } |
36 | 32 |
|
37 | | - |
38 | | - ChargeResponse _handleResponse(response) { |
39 | | - final status = response["status"]; |
40 | | - if (TransactionStatus.CANCELLED.toString() == status) { |
41 | | - throw (TransactionError("Transaction cancelled")); |
42 | | - } |
43 | | - return ChargeResponse.fromJson(response); |
44 | | - } |
45 | | - |
46 | | - |
47 | 33 | /// Opens browser with URL returned from startTransaction() |
48 | | - Future<Map<String, dynamic>> openBrowser( |
49 | | - final String url, |
50 | | - final String redirectUrl, |
51 | | - [final bool isTestMode = false] |
52 | | - ) async { |
53 | | - var response = await Navigator.push( |
54 | | - _buildContext, |
55 | | - MaterialPageRoute( |
56 | | - builder: (context) => FlutterwaveWebview(url, redirectUrl, isTestMode)), |
| 34 | + openBrowser( |
| 35 | + final String url, final String redirectUrl, |
| 36 | + [final bool isTestMode = false]) async { |
| 37 | + final FlutterwaveInAppBrowser browser = |
| 38 | + FlutterwaveInAppBrowser(callBack: _callBack); |
| 39 | + |
| 40 | + var options = InAppBrowserClassOptions( |
| 41 | + crossPlatform: InAppBrowserOptions(hideUrlBar: true), |
| 42 | + inAppWebViewGroupOptions: InAppWebViewGroupOptions( |
| 43 | + crossPlatform: InAppWebViewOptions(javaScriptEnabled: true), |
| 44 | + ), |
57 | 45 | ); |
58 | | - if (response == null) { |
59 | | - Map<String, dynamic> errorResponse = { |
60 | | - "status": TransactionStatus.CANCELLED |
61 | | - }; |
62 | | - return errorResponse; |
63 | | - } |
64 | | - return response; |
| 46 | + |
| 47 | + await browser.openUrlRequest( |
| 48 | + urlRequest: URLRequest(url: Uri.parse(url)), options: options); |
65 | 49 | } |
66 | 50 | } |
0 commit comments