Implementing null-aware operators throughout the repository (#143804)
This pull request fixes #143803 by taking advantage of Dart's null-aware operators. And unlike `switch` expressions ([9 PRs](https://github.com/flutter/flutter/pull/143634) and counting), the Flutter codebase is already fantastic when it comes to null-aware coding. After refactoring the entire repo, all the changes involving `?.` and `??` can fit into a single pull request.
This commit is contained in:
@@ -223,10 +223,7 @@ class _AndroidSemanticsMatcher extends Matcher {
|
||||
Description describeMismatch(dynamic item, Description mismatchDescription,
|
||||
Map<dynamic, dynamic> matchState, bool verbose) {
|
||||
final String? failure = matchState['failure'] as String?;
|
||||
if (failure == null) {
|
||||
return mismatchDescription.add('hasAndroidSemantics matcher does not complete successfully');
|
||||
}
|
||||
return mismatchDescription.add(failure);
|
||||
return mismatchDescription.add(failure ?? 'hasAndroidSemantics matcher does not complete successfully');
|
||||
}
|
||||
|
||||
bool _failWithMessage(String value, Map<dynamic, dynamic> matchState) {
|
||||
|
||||
@@ -62,12 +62,8 @@ class AppStateModel extends Model {
|
||||
|
||||
// Adds a product to the cart.
|
||||
void addProductToCart(int productId) {
|
||||
final int? value = _productsInCart[productId];
|
||||
if (value == null) {
|
||||
_productsInCart[productId] = 1;
|
||||
} else {
|
||||
_productsInCart[productId] = value+1;
|
||||
}
|
||||
final int value = _productsInCart[productId] ?? 0;
|
||||
_productsInCart[productId] = value + 1;
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user