-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 4423 - specific "Not connected to internet" displayed error
Impacted files: * `barcode_product_query.dart`: removed useless `try` as already `catch`'ed * `continuous_scan_model.dart`: removed the `codeInvalid` case that could never happen * `fetched_product.dart`: refactored with explicit constructors and additional exception and connectivity fields; removed the `codeInvalid` case that could never happen * `new_product_page.dart`: minor refactoring * `product_dialog_helper.dart`: removed the `codeInvalid` case that could never happen; minor refactoting * `product_list_item_simple.dart`: removed the `codeInvalid` case that could never happen * `product_loader_page.dart`: removed useless `try` as already `catch`'ed * `product_refresher.dart`: added a specific "You're not connected to the internet" error message; refactored using more `FetchedProduct`; removed useless method * `pubspec.lock`: wtf * `pubspec.yaml`: added package `connectivity_plus` * `question_card.dart`: refactored using `FetchedProduct`
- Loading branch information
1 parent
292939b
commit 2bdc0cd
Showing
11 changed files
with
154 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
|
||
/// Status of a "fetch [Product]" operation | ||
enum FetchedProductStatus { | ||
// found locally or from internet | ||
ok, | ||
internetNotFound, | ||
internetError, | ||
userCancelled, | ||
codeInvalid, | ||
// TODO(monsieurtanuki): time-out | ||
} | ||
|
||
/// A [Product] that we tried to fetch, but was it successful?.. | ||
class FetchedProduct { | ||
const FetchedProduct._({ | ||
required this.status, | ||
this.product, | ||
this.connectivityResult, | ||
this.exceptionString, | ||
}); | ||
|
||
// The reason behind the "ignore": I want to force "product" to be not null | ||
FetchedProduct(final Product product) | ||
const FetchedProduct.found(final Product product) | ||
// ignore: prefer_initializing_formals | ||
: product = product, | ||
status = FetchedProductStatus.ok; | ||
: this._( | ||
status: FetchedProductStatus.ok, | ||
product: product, | ||
); | ||
|
||
/// The internet Product search said it couldn't find the product. | ||
const FetchedProduct.internetNotFound() | ||
: this._(status: FetchedProductStatus.internetNotFound); | ||
|
||
/// The user cancelled the operation. | ||
const FetchedProduct.userCancelled() | ||
: this._(status: FetchedProductStatus.userCancelled); | ||
|
||
/// When the "fetch product" operation didn't go well (no status "ok" here) | ||
FetchedProduct.error(this.status) | ||
: product = null, | ||
assert(status != FetchedProductStatus.ok); | ||
/// When the "fetch product" operation had an internet error. | ||
const FetchedProduct.error({ | ||
required final String exceptionString, | ||
required final ConnectivityResult connectivityResult, | ||
}) : this._( | ||
status: FetchedProductStatus.internetError, | ||
connectivityResult: connectivityResult, | ||
exceptionString: exceptionString, | ||
); | ||
|
||
final Product? product; | ||
final FetchedProductStatus status; | ||
final ConnectivityResult? connectivityResult; | ||
final String? exceptionString; | ||
// TODO(monsieurtanuki): add a "ping" action in order to check if the server is alive? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.