From dce3b6c14afbccfa87cb01d6b6511eb99a5e562f Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 10 Jul 2021 00:19:11 +1000 Subject: [PATCH] Context fixes --- lib/api.dart | 22 ++++++++++++---------- lib/barcode.dart | 3 +-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index 50db640e..21ffe65c 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -37,13 +37,15 @@ class InvenTreeFileService extends FileService { @override Future get(String url, - {Map headers = const {}}) async { + {Map? headers}) async { final Uri resolved = Uri.base.resolve(url); final HttpClientRequest req = await _client!.getUrl(resolved); - headers.forEach((key, value) { - req.headers.add(key, value); - }); + if (headers != null) { + headers.forEach((key, value) { + req.headers.add(key, value); + }); + } final HttpClientResponse httpResponse = await req.close(); final http.StreamedResponse _response = http.StreamedResponse( @@ -458,7 +460,7 @@ class InvenTreeAPI { error.toString(), ); } else if (error is TimeoutException) { - showTimeoutError(ctx); + showTimeoutError(); } else { showServerError( L10().serverError, @@ -499,7 +501,7 @@ class InvenTreeAPI { error.toString() ); } else if (error is TimeoutException) { - showTimeoutError(ctx); + showTimeoutError(); } else { showServerError( L10().serverError, @@ -587,7 +589,7 @@ class InvenTreeAPI { error.toString() ); } else if (error is TimeoutException) { - showTimeoutError(ctx); + showTimeoutError(); } else { showServerError( L10().serverError, @@ -718,7 +720,7 @@ class InvenTreeAPI { } // Open a connection - HttpClientRequest request = await client.getUrl(uri) + HttpClientRequest? request = await client.getUrl(uri) .timeout(Duration(seconds: 10)) .catchError((error) { print("GET request returned error"); @@ -733,7 +735,7 @@ class InvenTreeAPI { error.toString() ); } else if (error is TimeoutException) { - showTimeoutError(ctx); + showTimeoutError(); } else { showServerError( L10().serverError, @@ -767,7 +769,7 @@ class InvenTreeAPI { error.toString() ); } else if (error is TimeoutException) { - showTimeoutError(ctx); + showTimeoutError(); } else { showServerError( L10().serverError, diff --git a/lib/barcode.dart b/lib/barcode.dart index d5386566..e0dbbf4b 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -248,8 +248,7 @@ class BarcodeScanHandler extends BarcodeHandler { var _ctx = OneContext().context; - showDialog( - context: _ctx, + OneContext().showDialog( builder: (BuildContext context) => SimpleDialog( title: Text(L10().unknownResponse), children: [