-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/4549
- Loading branch information
Showing
157 changed files
with
475 additions
and
314 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
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, | ||
this.failedPingedHost, | ||
}); | ||
|
||
// 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, | ||
final String? failedPingedHost, | ||
}) : this._( | ||
status: FetchedProductStatus.internetError, | ||
connectivityResult: connectivityResult, | ||
exceptionString: exceptionString, | ||
failedPingedHost: failedPingedHost, | ||
); | ||
|
||
final Product? product; | ||
final FetchedProductStatus status; | ||
|
||
/// When relevant, result of the connectivity check. | ||
final ConnectivityResult? connectivityResult; | ||
|
||
/// When relevant, string of the exception. | ||
final String? exceptionString; | ||
|
||
/// When relevant, host of the query that we couldn't even ping. | ||
final String? failedPingedHost; | ||
} |
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
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
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
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.