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;
@ -45,17 +46,22 @@ 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 {
try {
if (_webViewController == null || _isSaving) {
return; return;
} }
@ -67,9 +73,15 @@ class WyrePageBodyState extends State<WyrePageBody> {
widget.ordersStore.orderId = orderId; widget.ordersStore.orderId = orderId;
if (orderId.isNotEmpty) { if (orderId.isNotEmpty) {
_isSaving = true;
await widget.wyreViewModel.saveOrder(orderId); await widget.wyreViewModel.saveOrder(orderId);
timer.cancel();
} }
} }
} catch (e) {
_isSaving = false;
print(e);
}
}); });
} }