mirror of
https://github.com/flutter/flutter
synced 2024-08-25 11:07:06 +00:00
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:
parent
39585e66c1
commit
c53a18f4e4
|
@ -91,11 +91,7 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
|
|||
workingText += info.text;
|
||||
workingLabel ??= '';
|
||||
final String? infoSemanticsLabel = info.semanticsLabel;
|
||||
if (infoSemanticsLabel != null) {
|
||||
workingLabel += infoSemanticsLabel;
|
||||
} else {
|
||||
workingLabel += info.text;
|
||||
}
|
||||
workingLabel += infoSemanticsLabel ?? info.text;
|
||||
}
|
||||
}
|
||||
assert(workingLabel != null);
|
||||
|
@ -115,11 +111,7 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa
|
|||
workingText += info.text;
|
||||
workingLabel ??= '';
|
||||
final String? infoSemanticsLabel = info.semanticsLabel;
|
||||
if (infoSemanticsLabel != null) {
|
||||
workingLabel += infoSemanticsLabel;
|
||||
} else {
|
||||
workingLabel += info.text;
|
||||
}
|
||||
workingLabel += infoSemanticsLabel ?? info.text;
|
||||
}
|
||||
}
|
||||
assert(workingLabel != null);
|
||||
|
|
|
@ -16,20 +16,13 @@ class TestSpecs {
|
|||
int startTime;
|
||||
int? _endTime;
|
||||
|
||||
int get milliseconds {
|
||||
return endTime - startTime;
|
||||
}
|
||||
int get milliseconds => endTime - startTime;
|
||||
|
||||
set endTime(int value) {
|
||||
_endTime = value;
|
||||
}
|
||||
|
||||
int get endTime {
|
||||
if (_endTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return _endTime!;
|
||||
}
|
||||
int get endTime => _endTime ?? 0;
|
||||
|
||||
String toJson() {
|
||||
return json.encode(
|
||||
|
|
|
@ -158,13 +158,10 @@ class Version {
|
|||
int nextZ = previousVersion.z;
|
||||
int? nextM = previousVersion.m;
|
||||
int? nextN = previousVersion.n;
|
||||
if (nextVersionType == null) {
|
||||
if (previousVersion.type == VersionType.latest || previousVersion.type == VersionType.gitDescribe) {
|
||||
nextVersionType = VersionType.development;
|
||||
} else {
|
||||
nextVersionType = previousVersion.type;
|
||||
}
|
||||
}
|
||||
nextVersionType ??= switch (previousVersion.type) {
|
||||
VersionType.stable => VersionType.stable,
|
||||
VersionType.latest || VersionType.gitDescribe || VersionType.development => VersionType.development,
|
||||
};
|
||||
|
||||
switch (increment) {
|
||||
case 'x':
|
||||
|
|
|
@ -32,11 +32,7 @@ Future<void> main() async {
|
|||
final TaskResult? firstInstallFailure = testResults
|
||||
.firstWhereOrNull((TaskResult element) => element.failed);
|
||||
|
||||
if (firstInstallFailure != null) {
|
||||
return firstInstallFailure;
|
||||
}
|
||||
|
||||
return TaskResult.success(null);
|
||||
return firstInstallFailure ?? TaskResult.success(null);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -32,11 +32,7 @@ Future<void> main() async {
|
|||
final TaskResult? firstInstallFailure = testResults
|
||||
.firstWhereOrNull((TaskResult element) => element.failed);
|
||||
|
||||
if (firstInstallFailure != null) {
|
||||
return firstInstallFailure;
|
||||
}
|
||||
|
||||
return TaskResult.success(null);
|
||||
return firstInstallFailure ?? TaskResult.success(null);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -572,12 +572,7 @@ class BlinkTraceEvent {
|
|||
/// Returns null if the value is null.
|
||||
int? _readInt(Map<String, dynamic> json, String key) {
|
||||
final num? jsonValue = json[key] as num?;
|
||||
|
||||
if (jsonValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return jsonValue.toInt();
|
||||
return jsonValue?.toInt();
|
||||
}
|
||||
|
||||
/// Used by [Chrome.launch] to detect a glibc bug and retry launching the
|
||||
|
|
|
@ -1290,11 +1290,7 @@ class PerfTest {
|
|||
}) {
|
||||
return inDirectory<TaskResult>(testDirectory, () async {
|
||||
late Device selectedDevice;
|
||||
if (device != null) {
|
||||
selectedDevice = device!;
|
||||
} else {
|
||||
selectedDevice = await devices.workingDevice;
|
||||
}
|
||||
selectedDevice = device ?? await devices.workingDevice;
|
||||
await selectedDevice.unlock();
|
||||
final String deviceId = selectedDevice.deviceId;
|
||||
final String? localEngine = localEngineFromEnv;
|
||||
|
|
|
@ -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 {
|
||||
final int value = _productsInCart[productId] ?? 0;
|
||||
_productsInCart[productId] = value + 1;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
|
|
@ -86,9 +86,7 @@ Future<void> main(List<String> args) async {
|
|||
final Map<String, dynamic> tokenFileTokens = _readTokenFile(tokenFile as File);
|
||||
final String version = tokenFileTokens['version'] as String;
|
||||
tokenFileTokens.remove('version');
|
||||
if (versionMap[version] == null) {
|
||||
versionMap[version] = List<String>.empty(growable: true);
|
||||
}
|
||||
versionMap[version] ??= <String>[];
|
||||
versionMap[version]!.add(tokenFile.uri.pathSegments.last);
|
||||
|
||||
tokens.addAll(tokenFileTokens);
|
||||
|
|
|
@ -953,9 +953,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
|
|||
/// * [resolve], which is similar to this function, but returns a
|
||||
/// non-nullable value, and does not allow a null `resolvable` color.
|
||||
static Color? maybeResolve(Color? resolvable, BuildContext context) {
|
||||
if (resolvable == null) {
|
||||
return null;
|
||||
}
|
||||
return (resolvable is CupertinoDynamicColor)
|
||||
? resolvable.resolveFrom(context)
|
||||
: resolvable;
|
||||
|
|
|
@ -684,10 +684,8 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
|
|||
|
||||
// Lazily calculate the column width of the column being displayed only.
|
||||
double _getEstimatedColumnWidth(_PickerColumnType columnType) {
|
||||
if (estimatedColumnWidths[columnType.index] == null) {
|
||||
estimatedColumnWidths[columnType.index] =
|
||||
estimatedColumnWidths[columnType.index] ??=
|
||||
CupertinoDatePicker._getColumnWidth(columnType, localizations, context, widget.showDayOfWeek);
|
||||
}
|
||||
|
||||
return estimatedColumnWidths[columnType.index]!;
|
||||
}
|
||||
|
|
|
@ -94,10 +94,7 @@ class CupertinoUserInterfaceLevel extends InheritedWidget {
|
|||
/// [CupertinoUserInterfaceLevel] encloses the given context.
|
||||
static CupertinoUserInterfaceLevelData? maybeOf(BuildContext context) {
|
||||
final CupertinoUserInterfaceLevel? query = context.dependOnInheritedWidgetOfExactType<CupertinoUserInterfaceLevel>();
|
||||
if (query != null) {
|
||||
return query._data;
|
||||
}
|
||||
return null;
|
||||
return query?._data;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -2257,10 +2257,7 @@ class EnumProperty<T extends Enum?> extends DiagnosticsProperty<T> {
|
|||
|
||||
@override
|
||||
String valueToString({ TextTreeConfiguration? parentConfiguration }) {
|
||||
if (value == null) {
|
||||
return value.toString();
|
||||
}
|
||||
return value!.name;
|
||||
return value?.name ?? 'null';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,13 +47,9 @@ class PersistentHashMap<K extends Object, V> {
|
|||
/// is not in the map.
|
||||
@pragma('dart2js:as:trust')
|
||||
V? operator[](K key) {
|
||||
if (_root == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Unfortunately can not use unsafeCast<V?>(...) here because it leads
|
||||
// to worse code generation on VM.
|
||||
return _root.get(0, key, key.hashCode) as V?;
|
||||
return _root?.get(0, key, key.hashCode) as V?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -461,10 +461,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
|
|||
}
|
||||
|
||||
GestureArenaEntry _addPointerToArena(int pointer) {
|
||||
if (_team != null) {
|
||||
return _team!.add(pointer, this);
|
||||
}
|
||||
return GestureBinding.instance.gestureArena.add(pointer, this);
|
||||
return _team?.add(pointer, this) ?? GestureBinding.instance.gestureArena.add(pointer, this);
|
||||
}
|
||||
|
||||
/// Causes events related to the given pointer ID to be routed to this recognizer.
|
||||
|
|
|
@ -560,10 +560,8 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
|
|||
|
||||
double get _width {
|
||||
final RenderBox? box = _drawerKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (box != null) {
|
||||
return box.size.width;
|
||||
}
|
||||
return _kWidth; // drawer not being shown currently
|
||||
// return _kWidth if drawer not being shown currently
|
||||
return box?.size.width ?? _kWidth;
|
||||
}
|
||||
|
||||
bool _previouslyOpened = false;
|
||||
|
|
|
@ -154,10 +154,7 @@ class _RenderMenuItem extends RenderShiftedBox {
|
|||
|
||||
@override
|
||||
Size computeDryLayout(BoxConstraints constraints) {
|
||||
if (child == null) {
|
||||
return Size.zero;
|
||||
}
|
||||
return child!.getDryLayout(constraints);
|
||||
return child?.getDryLayout(constraints) ?? Size.zero;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -442,10 +442,8 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
|
|||
if (isActive) MaterialState.selected else MaterialState.disabled,
|
||||
};
|
||||
final Color? resolvedConnectorColor = widget.connectorColor?.resolve(states);
|
||||
if (resolvedConnectorColor != null) {
|
||||
return resolvedConnectorColor;
|
||||
}
|
||||
return isActive ? colorScheme.primary : Colors.grey.shade400;
|
||||
|
||||
return resolvedConnectorColor ?? (isActive ? colorScheme.primary : Colors.grey.shade400);
|
||||
}
|
||||
|
||||
Widget _buildLine(bool visible, bool isActive) {
|
||||
|
|
|
@ -238,13 +238,7 @@ abstract class BorderRadiusGeometry {
|
|||
if (visual != null && logical != null) {
|
||||
return '$visual + $logical';
|
||||
}
|
||||
if (visual != null) {
|
||||
return visual;
|
||||
}
|
||||
if (logical != null) {
|
||||
return logical;
|
||||
}
|
||||
return 'BorderRadius.zero';
|
||||
return visual ?? logical ?? 'BorderRadius.zero';
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -510,13 +510,7 @@ abstract class ShapeBorder {
|
|||
if (identical(a, b)) {
|
||||
return a;
|
||||
}
|
||||
ShapeBorder? result;
|
||||
if (b != null) {
|
||||
result = b.lerpFrom(a, t);
|
||||
}
|
||||
if (result == null && a != null) {
|
||||
result = a.lerpTo(b, t);
|
||||
}
|
||||
final ShapeBorder? result = b?.lerpFrom(a, t) ?? a?.lerpTo(b, t);
|
||||
return result ?? (t < 0.5 ? a : b);
|
||||
}
|
||||
|
||||
|
@ -700,13 +694,7 @@ abstract class OutlinedBorder extends ShapeBorder {
|
|||
if (identical(a, b)) {
|
||||
return a;
|
||||
}
|
||||
ShapeBorder? result;
|
||||
if (b != null) {
|
||||
result = b.lerpFrom(a, t);
|
||||
}
|
||||
if (result == null && a != null) {
|
||||
result = a.lerpTo(b, t);
|
||||
}
|
||||
final ShapeBorder? result = b?.lerpFrom(a, t) ?? a?.lerpTo(b, t);
|
||||
return result as OutlinedBorder? ?? (t < 0.5 ? a : b);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -468,10 +468,7 @@ class RenderAspectRatio extends RenderProxyBox {
|
|||
if (height.isFinite) {
|
||||
return height * _aspectRatio;
|
||||
}
|
||||
if (child != null) {
|
||||
return child!.getMinIntrinsicWidth(height);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMinIntrinsicWidth(height) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -479,10 +476,7 @@ class RenderAspectRatio extends RenderProxyBox {
|
|||
if (height.isFinite) {
|
||||
return height * _aspectRatio;
|
||||
}
|
||||
if (child != null) {
|
||||
return child!.getMaxIntrinsicWidth(height);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMaxIntrinsicWidth(height) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -490,10 +484,7 @@ class RenderAspectRatio extends RenderProxyBox {
|
|||
if (width.isFinite) {
|
||||
return width / _aspectRatio;
|
||||
}
|
||||
if (child != null) {
|
||||
return child!.getMinIntrinsicHeight(width);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMinIntrinsicHeight(width) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -501,10 +492,7 @@ class RenderAspectRatio extends RenderProxyBox {
|
|||
if (width.isFinite) {
|
||||
return width / _aspectRatio;
|
||||
}
|
||||
if (child != null) {
|
||||
return child!.getMaxIntrinsicHeight(width);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMaxIntrinsicHeight(width) ?? 0.0;
|
||||
}
|
||||
|
||||
Size _applyAspectRatio(BoxConstraints constraints) {
|
||||
|
|
|
@ -51,10 +51,7 @@ class DisposableBuildContext<T extends State> {
|
|||
/// Otherwise, asserts the [_state] is still mounted and returns its context.
|
||||
BuildContext? get context {
|
||||
assert(_debugValidate());
|
||||
if (_state == null) {
|
||||
return null;
|
||||
}
|
||||
return _state!.context;
|
||||
return _state?.context;
|
||||
}
|
||||
|
||||
/// Called from asserts or tests to determine whether this object is in a
|
||||
|
|
|
@ -1039,10 +1039,7 @@ class DraggableScrollableActuator extends StatefulWidget {
|
|||
/// otherwise.
|
||||
static bool reset(BuildContext context) {
|
||||
final _InheritedResetNotifier? notifier = context.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>();
|
||||
if (notifier == null) {
|
||||
return false;
|
||||
}
|
||||
return notifier._sendReset();
|
||||
return notifier?._sendReset() ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -578,10 +578,7 @@ abstract class Route<T> {
|
|||
/// rendered. It is even possible for the route to be active but for the stateful
|
||||
/// widgets within the route to not be instantiated. See [ModalRoute.maintainState].
|
||||
bool get isActive {
|
||||
if (_navigator == null) {
|
||||
return false;
|
||||
}
|
||||
return _navigator!._firstRouteEntryWhereOrNull(_RouteEntry.isRoutePredicate(this))?.isPresent ?? false;
|
||||
return _navigator?._firstRouteEntryWhereOrNull(_RouteEntry.isRoutePredicate(this))?.isPresent ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,10 +64,7 @@ class RouteInformation {
|
|||
'This feature was deprecated after v3.8.0-3.0.pre.'
|
||||
)
|
||||
String get location {
|
||||
if (_location != null) {
|
||||
return _location;
|
||||
}
|
||||
return Uri.decodeComponent(
|
||||
return _location ?? Uri.decodeComponent(
|
||||
Uri(
|
||||
path: uri.path.isEmpty ? '/' : uri.path,
|
||||
queryParameters: uri.queryParametersAll.isEmpty ? null : uri.queryParametersAll,
|
||||
|
@ -1562,10 +1559,7 @@ mixin PopNavigatorRouterDelegateMixin<T> on RouterDelegate<T> {
|
|||
@override
|
||||
Future<bool> popRoute() {
|
||||
final NavigatorState? navigator = navigatorKey?.currentState;
|
||||
if (navigator == null) {
|
||||
return SynchronousFuture<bool>(false);
|
||||
}
|
||||
return navigator.maybePop();
|
||||
return navigator?.maybePop() ?? SynchronousFuture<bool>(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,10 +190,7 @@ class ScrollPhysics {
|
|||
/// reference to it to use later, as the values may update, may not update, or
|
||||
/// may update to reflect an entirely unrelated scrollable.
|
||||
double applyPhysicsToUserOffset(ScrollMetrics position, double offset) {
|
||||
if (parent == null) {
|
||||
return offset;
|
||||
}
|
||||
return parent!.applyPhysicsToUserOffset(position, offset);
|
||||
return parent?.applyPhysicsToUserOffset(position, offset) ?? offset;
|
||||
}
|
||||
|
||||
/// Whether the scrollable should let the user adjust the scroll offset, for
|
||||
|
@ -297,10 +294,7 @@ class ScrollPhysics {
|
|||
/// scrolling back from being overscrolled, if for some reason the position
|
||||
/// ends up overscrolled.
|
||||
double applyBoundaryConditions(ScrollMetrics position, double value) {
|
||||
if (parent == null) {
|
||||
return 0.0;
|
||||
}
|
||||
return parent!.applyBoundaryConditions(position, value);
|
||||
return parent?.applyBoundaryConditions(position, value) ?? 0.0;
|
||||
}
|
||||
|
||||
/// Describes what the scroll position should be given new viewport dimensions.
|
||||
|
@ -394,10 +388,7 @@ class ScrollPhysics {
|
|||
// https://github.com/flutter/flutter/issues/120340
|
||||
// https://github.com/flutter/flutter/issues/109675
|
||||
Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) {
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
return parent!.createBallisticSimulation(position, velocity);
|
||||
return parent?.createBallisticSimulation(position, velocity);
|
||||
}
|
||||
|
||||
static final SpringDescription _kDefaultSpring = SpringDescription.withDampingRatio(
|
||||
|
@ -467,10 +458,7 @@ class ScrollPhysics {
|
|||
///
|
||||
/// By default, physics for platforms other than iOS doesn't carry momentum.
|
||||
double carriedMomentum(double existingVelocity) {
|
||||
if (parent == null) {
|
||||
return 0.0;
|
||||
}
|
||||
return parent!.carriedMomentum(existingVelocity);
|
||||
return parent?.carriedMomentum(existingVelocity) ?? 0.0;
|
||||
}
|
||||
|
||||
/// The minimum amount of pixel distance drags must move by to start motion
|
||||
|
|
|
@ -2059,10 +2059,7 @@ abstract class MultiSelectableSelectionContainerDelegate extends SelectionContai
|
|||
final List<Rect> selectionRectsWithinDrawableArea = currSelectableSelectionRects.map((Rect selectionRect) {
|
||||
final Matrix4 transform = getTransformFrom(selectables[index]);
|
||||
final Rect localRect = MatrixUtils.transformRect(transform, selectionRect);
|
||||
if (drawableArea != null) {
|
||||
return drawableArea.intersect(localRect);
|
||||
}
|
||||
return localRect;
|
||||
return drawableArea?.intersect(localRect) ?? localRect;
|
||||
}).where((Rect selectionRect) {
|
||||
return selectionRect.isFinite && !selectionRect.isEmpty;
|
||||
}).toList();
|
||||
|
|
|
@ -435,34 +435,22 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
|
|||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
if (child != null) {
|
||||
return child!.getMinIntrinsicWidth(height);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMinIntrinsicWidth(height) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicWidth(double height) {
|
||||
if (child != null) {
|
||||
return child!.getMaxIntrinsicWidth(height);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMaxIntrinsicWidth(height) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
if (child != null) {
|
||||
return child!.getMinIntrinsicHeight(width);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMinIntrinsicHeight(width) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
if (child != null) {
|
||||
return child!.getMaxIntrinsicHeight(width);
|
||||
}
|
||||
return 0.0;
|
||||
return child?.getMaxIntrinsicHeight(width) ?? 0.0;
|
||||
}
|
||||
|
||||
// We don't override computeDistanceToActualBaseline(), because we
|
||||
|
|
|
@ -732,12 +732,7 @@ class InspectorReferenceData {
|
|||
int count = 1;
|
||||
|
||||
/// The value.
|
||||
Object? get value {
|
||||
if (_ref != null) {
|
||||
return _ref!.target;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
Object? get value => _ref?.target ?? _value;
|
||||
}
|
||||
|
||||
// Production implementation of [WidgetInspectorService].
|
||||
|
|
|
@ -471,12 +471,7 @@ void main() {
|
|||
|
||||
// Theme brightness is preferred, otherwise MediaQuery brightness is
|
||||
// used. If both are null, defaults to light.
|
||||
late final Brightness effectiveBrightness;
|
||||
if (themeBrightness != null) {
|
||||
effectiveBrightness = themeBrightness;
|
||||
} else {
|
||||
effectiveBrightness = mediaBrightness ?? Brightness.light;
|
||||
}
|
||||
final Brightness effectiveBrightness = themeBrightness ?? mediaBrightness ?? Brightness.light;
|
||||
|
||||
expect(
|
||||
text.style!.color!.value,
|
||||
|
|
|
@ -23,10 +23,7 @@ class StateMarkerState extends State<StateMarker> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.child != null) {
|
||||
return widget.child!;
|
||||
}
|
||||
return Container();
|
||||
return widget.child ?? Container();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,10 +44,7 @@ class StateMarkerState extends State<StateMarker> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.child != null) {
|
||||
return widget.child!;
|
||||
}
|
||||
return Container();
|
||||
return widget.child ?? Container();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3128,8 +3128,5 @@ Future<void> _testGestureTap(WidgetTester tester, Finder tooltip) async {
|
|||
}
|
||||
|
||||
SemanticsNode _findDebugSemantics(RenderObject object) {
|
||||
if (object.debugSemantics != null) {
|
||||
return object.debugSemantics!;
|
||||
}
|
||||
return _findDebugSemantics(object.parent!);
|
||||
return object.debugSemantics ?? _findDebugSemantics(object.parent!);
|
||||
}
|
||||
|
|
|
@ -1495,8 +1495,5 @@ void main() {
|
|||
}
|
||||
|
||||
SemanticsNode findDebugSemantics(RenderObject object) {
|
||||
if (object.debugSemantics != null) {
|
||||
return object.debugSemantics!;
|
||||
}
|
||||
return findDebugSemantics(object.parent!);
|
||||
return object.debugSemantics ?? findDebugSemantics(object.parent!);
|
||||
}
|
||||
|
|
|
@ -59,10 +59,7 @@ class MyTestRenderingFlutterBinding extends TestRenderingFlutterBinding {
|
|||
static MyTestRenderingFlutterBinding? _instance;
|
||||
|
||||
static MyTestRenderingFlutterBinding ensureInitialized() {
|
||||
if (_instance != null) {
|
||||
return _instance!;
|
||||
}
|
||||
return MyTestRenderingFlutterBinding();
|
||||
return _instance ?? MyTestRenderingFlutterBinding();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -1055,10 +1055,7 @@ class ConditionalRepaintBoundary extends RenderProxyBox {
|
|||
|
||||
@override
|
||||
OffsetLayer updateCompositedLayer({required covariant OffsetLayer? oldLayer}) {
|
||||
if (offsetLayerFactory != null) {
|
||||
return offsetLayerFactory!.call(oldLayer);
|
||||
}
|
||||
return super.updateCompositedLayer(oldLayer: oldLayer);
|
||||
return offsetLayerFactory?.call(oldLayer) ?? super.updateCompositedLayer(oldLayer: oldLayer);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -88,10 +88,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
|
|||
/// idempotent; calling it a second time will just return the
|
||||
/// previously-created instance.
|
||||
static TestRenderingFlutterBinding ensureInitialized({ VoidCallback? onErrors }) {
|
||||
if (_instance != null) {
|
||||
return _instance!;
|
||||
}
|
||||
return TestRenderingFlutterBinding(onErrors: onErrors);
|
||||
return _instance ?? TestRenderingFlutterBinding(onErrors: onErrors);
|
||||
}
|
||||
|
||||
final List<FlutterErrorDetails> _errors = <FlutterErrorDetails>[];
|
||||
|
|
|
@ -19,10 +19,7 @@ class StateMarkerState extends State<StateMarker> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.child != null) {
|
||||
return widget.child!;
|
||||
}
|
||||
return Container();
|
||||
return widget.child ?? Container();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,10 +50,7 @@ void main() {
|
|||
final SimpleAsyncRouteInformationParser parser = SimpleAsyncRouteInformationParser();
|
||||
final SimpleAsyncRouterDelegate delegate = SimpleAsyncRouterDelegate(
|
||||
builder: (BuildContext context, RouteInformation? information) {
|
||||
if (information == null) {
|
||||
return const Text('waiting');
|
||||
}
|
||||
return Text(information.uri.toString());
|
||||
return Text(information?.uri.toString() ?? 'waiting');
|
||||
},
|
||||
);
|
||||
addTearDown(delegate.dispose);
|
||||
|
@ -97,10 +94,7 @@ void main() {
|
|||
final CompleterRouteInformationParser parser = CompleterRouteInformationParser();
|
||||
final SimpleAsyncRouterDelegate delegate = SimpleAsyncRouterDelegate(
|
||||
builder: (BuildContext context, RouteInformation? information) {
|
||||
if (information == null) {
|
||||
return const Text('waiting');
|
||||
}
|
||||
return Text(information.uri.toString());
|
||||
return Text(information?.uri.toString() ?? 'waiting');
|
||||
},
|
||||
);
|
||||
addTearDown(delegate.dispose);
|
||||
|
|
|
@ -2080,12 +2080,8 @@ class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> {
|
|||
final Color? barrierColor;
|
||||
|
||||
@override
|
||||
Curve get barrierCurve {
|
||||
if (_barrierCurve == null) {
|
||||
return super.barrierCurve;
|
||||
}
|
||||
return _barrierCurve;
|
||||
}
|
||||
Curve get barrierCurve => _barrierCurve ?? super.barrierCurve;
|
||||
|
||||
final Curve? _barrierCurve;
|
||||
|
||||
@override
|
||||
|
|
|
@ -366,10 +366,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
///
|
||||
/// This is called automatically by [testWidgets].
|
||||
static TestWidgetsFlutterBinding ensureInitialized([@visibleForTesting Map<String, String>? environment]) {
|
||||
if (_instance != null) {
|
||||
return _instance!;
|
||||
}
|
||||
return binding.ensureInitialized(environment);
|
||||
return _instance ?? binding.ensureInitialized(environment);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -521,11 +521,7 @@ class AndroidSdk {
|
|||
final String executable = globals.platform.isWindows
|
||||
? 'sdkmanager.bat'
|
||||
: 'sdkmanager';
|
||||
final String? path = getCmdlineToolsPath(executable, skipOldTools: true);
|
||||
if (path != null) {
|
||||
return path;
|
||||
}
|
||||
return null;
|
||||
return getCmdlineToolsPath(executable, skipOldTools: true);
|
||||
}
|
||||
|
||||
/// Returns the version of the Android SDK manager tool or null if not found.
|
||||
|
|
|
@ -163,11 +163,7 @@ class Java {
|
|||
RegExp(r'java\s+(?<version>\d+(\.\d+)?(\.\d+)?)\s+\d\d\d\d-\d\d-\d\d');
|
||||
final RegExpMatch? match = secondJdkVersionRegex.firstMatch(versionLines[0]);
|
||||
if (match != null) {
|
||||
final Version? parsedVersion = Version.parse(match.namedGroup('version'));
|
||||
if (parsedVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return parsedVersion;
|
||||
return Version.parse(match.namedGroup('version'));
|
||||
}
|
||||
_logger.printWarning(_formatJavaVersionWarning(rawVersionOutput));
|
||||
return null;
|
||||
|
|
|
@ -557,11 +557,9 @@ class Cache {
|
|||
|
||||
/// Return the top-level directory in the cache; this is `bin/cache`.
|
||||
Directory getRoot() {
|
||||
if (_rootOverride != null) {
|
||||
return _fileSystem.directory(_fileSystem.path.join(_rootOverride.path, 'bin', 'cache'));
|
||||
} else {
|
||||
return _fileSystem.directory(_fileSystem.path.join(flutterRoot!, 'bin', 'cache'));
|
||||
}
|
||||
return _fileSystem.directory(
|
||||
_fileSystem.path.join(_rootOverride?.path ?? flutterRoot!, 'bin', 'cache'),
|
||||
);
|
||||
}
|
||||
|
||||
String getHostPlatformArchName() {
|
||||
|
|
|
@ -84,10 +84,7 @@ abstract class AnalyzeBase {
|
|||
bool get isFlutterRepo => argResults['flutter-repo'] as bool;
|
||||
String get sdkPath {
|
||||
final String? dartSdk = argResults['dart-sdk'] as String?;
|
||||
if (dartSdk != null) {
|
||||
return dartSdk;
|
||||
}
|
||||
return artifacts.getArtifactPath(Artifact.engineDartSdkPath);
|
||||
return dartSdk ?? artifacts.getArtifactPath(Artifact.engineDartSdkPath);
|
||||
}
|
||||
bool get isBenchmarking => argResults['benchmark'] as bool;
|
||||
String? get protocolTrafficLog => argResults['protocol-traffic-log'] as String?;
|
||||
|
|
|
@ -399,14 +399,7 @@ class PackagesGetCommand extends FlutterCommand {
|
|||
return findPlugins(rootProject, throwOnError: false);
|
||||
})();
|
||||
|
||||
late final String? _androidEmbeddingVersion = (() {
|
||||
final FlutterProject? rootProject = _rootProject;
|
||||
if (rootProject == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return rootProject.android.getEmbeddingVersion().toString().split('.').last;
|
||||
})();
|
||||
late final String? _androidEmbeddingVersion = _rootProject?.android.getEmbeddingVersion().toString().split('.').last;
|
||||
|
||||
/// The pub packages usage values are incorrect since these are calculated/sent
|
||||
/// before pub get completes. This needs to be performed after dependency resolution.
|
||||
|
|
|
@ -224,10 +224,7 @@ ${migrateConfig.getOutputFileString()}''';
|
|||
/// Finds the fallback revision to use when no base revision is found in the migrate config.
|
||||
String getFallbackBaseRevision(Logger logger, FlutterVersion flutterVersion) {
|
||||
// Use the .metadata file if it exists.
|
||||
if (versionRevision != null) {
|
||||
return versionRevision!;
|
||||
}
|
||||
return flutterVersion.frameworkRevision;
|
||||
return versionRevision ?? flutterVersion.frameworkRevision;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1178,12 +1178,7 @@ class IOSDeviceLogReader extends DeviceLogReader {
|
|||
bool isWirelesslyConnected = false,
|
||||
bool isCoreDevice = false,
|
||||
}) {
|
||||
final int sdkVersion;
|
||||
if (majorSdkVersion != null) {
|
||||
sdkVersion = majorSdkVersion;
|
||||
} else {
|
||||
sdkVersion = useSyslog ? 12 : 13;
|
||||
}
|
||||
final int sdkVersion = majorSdkVersion ?? (useSyslog ? 12 : 13);
|
||||
return IOSDeviceLogReader._(
|
||||
iMobileDevice, sdkVersion, '1234', 'test', isWirelesslyConnected, isCoreDevice, 'Runner', usingCISystem);
|
||||
}
|
||||
|
|
|
@ -637,12 +637,7 @@ class IOSDeployDebugger {
|
|||
);
|
||||
}
|
||||
|
||||
if (_stdinWriteFuture != null) {
|
||||
_stdinWriteFuture = _stdinWriteFuture!.then<void>((_) => writeln());
|
||||
} else {
|
||||
_stdinWriteFuture = writeln();
|
||||
}
|
||||
|
||||
_stdinWriteFuture = _stdinWriteFuture?.then<void>((_) => writeln()) ?? writeln();
|
||||
return _stdinWriteFuture;
|
||||
}
|
||||
|
||||
|
|
|
@ -847,12 +847,7 @@ void _parseIssueInStdout(XcodeBuildExecution xcodeBuildExecution, Logger logger,
|
|||
|
||||
String? _parseMissingPlatform(String message) {
|
||||
final RegExp pattern = RegExp(r'error:(.*?) is not installed\. To use with Xcode, first download and install the platform');
|
||||
final RegExpMatch? match = pattern.firstMatch(message);
|
||||
if (match != null) {
|
||||
final String? version = match.group(1);
|
||||
return version;
|
||||
}
|
||||
return null;
|
||||
return pattern.firstMatch(message)?.group(1);
|
||||
}
|
||||
|
||||
// The result of [_handleXCResultIssue].
|
||||
|
|
|
@ -717,11 +717,7 @@ class VersionUpstreamValidator {
|
|||
// URLs without ".git" suffix will remain unaffected.
|
||||
static final RegExp _patternUrlDotGit = RegExp(r'(.*)(\.git)$');
|
||||
static String stripDotGit(String url) {
|
||||
final RegExpMatch? match = _patternUrlDotGit.firstMatch(url);
|
||||
if (match == null) {
|
||||
return url;
|
||||
}
|
||||
return match.group(1)!;
|
||||
return _patternUrlDotGit.firstMatch(url)?.group(1)! ?? url;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -329,10 +329,7 @@ class IosProject extends XcodeBasedProject {
|
|||
|
||||
Future<String?> _getTeamIdentifier(XcodeProjectBuildContext buildContext) async {
|
||||
final Map<String, String>? buildSettings = await _buildSettingsForXcodeProjectBuildContext(buildContext);
|
||||
if (buildSettings != null) {
|
||||
return buildSettings[kTeamIdKey];
|
||||
}
|
||||
return null;
|
||||
return buildSettings?[kTeamIdKey];
|
||||
}
|
||||
|
||||
Future<List<String>> _getAssociatedDomains(XcodeProjectBuildContext buildContext) async {
|
||||
|
|
|
@ -1130,10 +1130,7 @@ class TestDeviceDiscoverySupportFilter extends DeviceDiscoverySupportFilter {
|
|||
|
||||
@override
|
||||
bool isDeviceSupportedForProject(Device device) {
|
||||
if (isAlwaysSupportedForProjectOverride != null) {
|
||||
return isAlwaysSupportedForProjectOverride!;
|
||||
}
|
||||
return super.isDeviceSupportedForProject(device);
|
||||
return isAlwaysSupportedForProjectOverride ?? super.isDeviceSupportedForProject(device);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,90 +24,60 @@ class FlutterIOOverrides extends io.IOOverrides {
|
|||
|
||||
@override
|
||||
io.Directory createDirectory(String path) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.createDirectory(path);
|
||||
}
|
||||
return _fileSystemDelegate.directory(path);
|
||||
return _fileSystemDelegate?.directory(path) ?? super.createDirectory(path);
|
||||
}
|
||||
|
||||
@override
|
||||
io.File createFile(String path) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.createFile(path);
|
||||
}
|
||||
return _fileSystemDelegate.file(path);
|
||||
return _fileSystemDelegate?.file(path) ?? super.createFile(path);
|
||||
}
|
||||
|
||||
@override
|
||||
io.Link createLink(String path) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.createLink(path);
|
||||
}
|
||||
return _fileSystemDelegate.link(path);
|
||||
return _fileSystemDelegate?.link(path) ?? super.createLink(path);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<FileSystemEvent> fsWatch(String path, int events, bool recursive) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.fsWatch(path, events, recursive);
|
||||
}
|
||||
return _fileSystemDelegate.file(path).watch(events: events, recursive: recursive);
|
||||
return _fileSystemDelegate?.file(path).watch(events: events, recursive: recursive)
|
||||
?? super.fsWatch(path, events, recursive);
|
||||
}
|
||||
|
||||
@override
|
||||
bool fsWatchIsSupported() {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.fsWatchIsSupported();
|
||||
}
|
||||
return _fileSystemDelegate.isWatchSupported;
|
||||
return _fileSystemDelegate?.isWatchSupported ?? super.fsWatchIsSupported();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FileSystemEntityType> fseGetType(String path, bool followLinks) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.fseGetType(path, followLinks);
|
||||
}
|
||||
return _fileSystemDelegate.type(path, followLinks: followLinks);
|
||||
return _fileSystemDelegate?.type(path, followLinks: followLinks)
|
||||
?? super.fseGetType(path, followLinks);
|
||||
}
|
||||
|
||||
@override
|
||||
FileSystemEntityType fseGetTypeSync(String path, bool followLinks) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.fseGetTypeSync(path, followLinks);
|
||||
}
|
||||
return _fileSystemDelegate.typeSync(path, followLinks: followLinks);
|
||||
return _fileSystemDelegate?.typeSync(path, followLinks: followLinks)
|
||||
?? super.fseGetTypeSync(path, followLinks);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> fseIdentical(String path1, String path2) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.fseIdentical(path1, path2);
|
||||
}
|
||||
return _fileSystemDelegate.identical(path1, path2);
|
||||
return _fileSystemDelegate?.identical(path1, path2) ?? super.fseIdentical(path1, path2);
|
||||
}
|
||||
|
||||
@override
|
||||
bool fseIdenticalSync(String path1, String path2) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.fseIdenticalSync(path1, path2);
|
||||
}
|
||||
return _fileSystemDelegate.identicalSync(path1, path2);
|
||||
return _fileSystemDelegate?.identicalSync(path1, path2) ?? super.fseIdenticalSync(path1, path2);
|
||||
}
|
||||
|
||||
@override
|
||||
io.Directory getCurrentDirectory() {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.getCurrentDirectory();
|
||||
}
|
||||
return _fileSystemDelegate.currentDirectory;
|
||||
return _fileSystemDelegate?.currentDirectory ?? super.getCurrentDirectory();
|
||||
}
|
||||
|
||||
@override
|
||||
io.Directory getSystemTempDirectory() {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.getSystemTempDirectory();
|
||||
}
|
||||
return _fileSystemDelegate.systemTempDirectory;
|
||||
return _fileSystemDelegate?.systemTempDirectory ?? super.getSystemTempDirectory();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -120,17 +90,11 @@ class FlutterIOOverrides extends io.IOOverrides {
|
|||
|
||||
@override
|
||||
Future<FileStat> stat(String path) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.stat(path);
|
||||
}
|
||||
return _fileSystemDelegate.stat(path);
|
||||
return _fileSystemDelegate?.stat(path) ?? super.stat(path);
|
||||
}
|
||||
|
||||
@override
|
||||
FileStat statSync(String path) {
|
||||
if (_fileSystemDelegate == null) {
|
||||
return super.statSync(path);
|
||||
}
|
||||
return _fileSystemDelegate.statSync(path);
|
||||
return _fileSystemDelegate?.statSync(path) ?? super.statSync(path);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue