Fixes for wyre.

This commit is contained in:
M 2021-03-24 11:50:51 +02:00
parent a9566b2748
commit c1b52ebede
2 changed files with 28 additions and 16 deletions

View file

@ -68,7 +68,7 @@ class WyreService {
} }
Future<Order> findOrderById(String id) async { Future<Order> findOrderById(String id) async {
final orderUrl = baseApiUrl + _ordersSuffix + id; final orderUrl = baseApiUrl + _ordersSuffix + '/$id';
final orderResponse = await get(orderUrl); final orderResponse = await get(orderUrl);
if (orderResponse.statusCode != 200) { if (orderResponse.statusCode != 200) {

View file

@ -9,7 +9,8 @@ import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart'; import 'package:webview_flutter/webview_flutter.dart';
class WyrePage extends BasePage { class WyrePage extends BasePage {
WyrePage(this.wyreViewModel, {@required this.ordersStore, @required this.url}); WyrePage(this.wyreViewModel,
{@required this.ordersStore, @required this.url});
final OrdersStore ordersStore; final OrdersStore ordersStore;
final String url; final String url;
@ -26,7 +27,7 @@ class WyrePage extends BasePage {
@override @override
Widget body(BuildContext context) => Widget body(BuildContext context) =>
WyrePageBody(wyreViewModel, ordersStore: ordersStore,url: url); WyrePageBody(wyreViewModel, ordersStore: ordersStore, url: url);
} }
class WyrePageBody extends StatefulWidget { class WyrePageBody extends StatefulWidget {
@ -45,30 +46,41 @@ class WyrePageBodyState extends State<WyrePageBody> {
WebViewController _webViewController; WebViewController _webViewController;
GlobalKey _webViewkey; GlobalKey _webViewkey;
Timer _timer; Timer _timer;
bool _isSaving;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_webViewkey = GlobalKey(); _webViewkey = GlobalKey();
_isSaving = false;
widget.ordersStore.orderId = ''; widget.ordersStore.orderId = '';
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
_timer = Timer.periodic(Duration(milliseconds: 200), (_) async { _timer?.cancel();
if (_webViewController == null) { _timer = Timer.periodic(Duration(seconds: 1), (timer) async {
return;
}
final url = await _webViewController.currentUrl(); try {
if (_webViewController == null || _isSaving) {
if (url.contains('completed')) { return;
final urlParts = url.split('/');
orderId = urlParts.last;
widget.ordersStore.orderId = orderId;
if (orderId.isNotEmpty) {
await widget.wyreViewModel.saveOrder(orderId);
} }
final url = await _webViewController.currentUrl();
if (url.contains('completed')) {
final urlParts = url.split('/');
orderId = urlParts.last;
widget.ordersStore.orderId = orderId;
if (orderId.isNotEmpty) {
_isSaving = true;
await widget.wyreViewModel.saveOrder(orderId);
timer.cancel();
}
}
} catch (e) {
_isSaving = false;
print(e);
} }
}); });
} }