Unverified Commit 4fa32df1 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

use null aware operators (#32711)

* use null aware operators

* rollback changes about null-aware operator

* disable lint prefer_is_not_empty
parent 3c16cf6a
...@@ -139,7 +139,7 @@ linter: ...@@ -139,7 +139,7 @@ linter:
# - prefer_int_literals # not yet tested # - prefer_int_literals # not yet tested
# - prefer_interpolation_to_compose_strings # not yet tested # - prefer_interpolation_to_compose_strings # not yet tested
- prefer_is_empty - prefer_is_empty
- prefer_is_not_empty # - prefer_is_not_empty # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
- prefer_iterable_whereType - prefer_iterable_whereType
# - prefer_mixin # https://github.com/dart-lang/language/issues/32 # - prefer_mixin # https://github.com/dart-lang/language/issues/32
- prefer_null_aware_operators - prefer_null_aware_operators
......
...@@ -470,10 +470,7 @@ class IosDevice implements Device { ...@@ -470,10 +470,7 @@ class IosDevice implements Device {
/// Path to the `adb` executable. /// Path to the `adb` executable.
String get adbPath { String get adbPath {
final String androidHome = final String androidHome = Platform.environment['ANDROID_HOME'] ?? Platform.environment['ANDROID_SDK_ROOT'];
Platform.environment['ANDROID_HOME'] != null
? Platform.environment['ANDROID_HOME']
: Platform.environment['ANDROID_SDK_ROOT'];
if (androidHome == null) if (androidHome == null)
throw 'The ANDROID_SDK_ROOT and ANDROID_HOME environment variables are ' throw 'The ANDROID_SDK_ROOT and ANDROID_HOME environment variables are '
......
...@@ -739,7 +739,7 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin { ...@@ -739,7 +739,7 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
void didUpdateWidget(_SortArrow oldWidget) { void didUpdateWidget(_SortArrow oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
bool skipArrow = false; bool skipArrow = false;
final bool newDown = widget.down != null ? widget.down : _down; final bool newDown = widget.down ?? _down;
if (oldWidget.visible != widget.visible) { if (oldWidget.visible != widget.visible) {
if (widget.visible && (_opacityController.status == AnimationStatus.dismissed)) { if (widget.visible && (_opacityController.status == AnimationStatus.dismissed)) {
_orientationController.stop(); _orientationController.stop();
......
...@@ -782,7 +782,7 @@ class ListTile extends StatelessWidget { ...@@ -782,7 +782,7 @@ class ListTile extends StatelessWidget {
} }
bool _isDenseLayout(ListTileTheme tileTheme) { bool _isDenseLayout(ListTileTheme tileTheme) {
return dense != null ? dense : (tileTheme?.dense ?? false); return dense ?? tileTheme?.dense ?? false;
} }
TextStyle _titleTextStyle(ThemeData theme, ListTileTheme tileTheme) { TextStyle _titleTextStyle(ThemeData theme, ListTileTheme tileTheme) {
......
...@@ -202,7 +202,7 @@ class ImageStream extends Diagnosticable { ...@@ -202,7 +202,7 @@ class ImageStream extends Diagnosticable {
/// will go from being different than other [ImageStream]'s keys to /// will go from being different than other [ImageStream]'s keys to
/// potentially being the same as others'. No notification is sent when this /// potentially being the same as others'. No notification is sent when this
/// happens. /// happens.
Object get key => _completer != null ? _completer : this; Object get key => _completer ?? this;
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
......
...@@ -109,10 +109,10 @@ class BoxConstraints extends Constraints { ...@@ -109,10 +109,10 @@ class BoxConstraints extends Constraints {
const BoxConstraints.tightFor({ const BoxConstraints.tightFor({
double width, double width,
double height, double height,
}) : minWidth = width != null ? width : 0.0, }) : minWidth = width ?? 0.0,
maxWidth = width != null ? width : double.infinity, maxWidth = width ?? double.infinity,
minHeight = height != null ? height : 0.0, minHeight = height ?? 0.0,
maxHeight = height != null ? height : double.infinity; maxHeight = height ?? double.infinity;
/// Creates box constraints that require the given width or height, except if /// Creates box constraints that require the given width or height, except if
/// they are infinite. /// they are infinite.
...@@ -143,10 +143,10 @@ class BoxConstraints extends Constraints { ...@@ -143,10 +143,10 @@ class BoxConstraints extends Constraints {
const BoxConstraints.expand({ const BoxConstraints.expand({
double width, double width,
double height, double height,
}) : minWidth = width != null ? width : double.infinity, }) : minWidth = width ?? double.infinity,
maxWidth = width != null ? width : double.infinity, maxWidth = width ?? double.infinity,
minHeight = height != null ? height : double.infinity, minHeight = height ?? double.infinity,
maxHeight = height != null ? height : double.infinity; maxHeight = height ?? double.infinity;
/// The minimum width that satisfies the constraints. /// The minimum width that satisfies the constraints.
final double minWidth; final double minWidth;
......
...@@ -2965,7 +2965,7 @@ class RenderIgnorePointer extends RenderProxyBox { ...@@ -2965,7 +2965,7 @@ class RenderIgnorePointer extends RenderProxyBox {
markNeedsSemanticsUpdate(); markNeedsSemanticsUpdate();
} }
bool get _effectiveIgnoringSemantics => ignoringSemantics == null ? ignoring : ignoringSemantics; bool get _effectiveIgnoringSemantics => ignoringSemantics ?? ignoring;
@override @override
bool hitTest(BoxHitTestResult result, { Offset position }) { bool hitTest(BoxHitTestResult result, { Offset position }) {
...@@ -3171,7 +3171,7 @@ class RenderAbsorbPointer extends RenderProxyBox { ...@@ -3171,7 +3171,7 @@ class RenderAbsorbPointer extends RenderProxyBox {
markNeedsSemanticsUpdate(); markNeedsSemanticsUpdate();
} }
bool get _effectiveIgnoringSemantics => ignoringSemantics == null ? absorbing : ignoringSemantics; bool get _effectiveIgnoringSemantics => ignoringSemantics ?? absorbing;
@override @override
bool hitTest(BoxHitTestResult result, { Offset position }) { bool hitTest(BoxHitTestResult result, { Offset position }) {
......
...@@ -1949,12 +1949,12 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin { ...@@ -1949,12 +1949,12 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
textDirection: data.textDirection, textDirection: data.textDirection,
textSelectionBase: data.textSelection != null ? data.textSelection.baseOffset : -1, textSelectionBase: data.textSelection != null ? data.textSelection.baseOffset : -1,
textSelectionExtent: data.textSelection != null ? data.textSelection.extentOffset : -1, textSelectionExtent: data.textSelection != null ? data.textSelection.extentOffset : -1,
platformViewId: data.platformViewId != null ? data.platformViewId : -1, platformViewId: data.platformViewId ?? -1,
scrollChildren: data.scrollChildCount != null ? data.scrollChildCount : 0, scrollChildren: data.scrollChildCount ?? 0,
scrollIndex: data.scrollIndex != null ? data.scrollIndex : 0 , scrollIndex: data.scrollIndex ?? 0 ,
scrollPosition: data.scrollPosition != null ? data.scrollPosition : double.nan, scrollPosition: data.scrollPosition ?? double.nan,
scrollExtentMax: data.scrollExtentMax != null ? data.scrollExtentMax : double.nan, scrollExtentMax: data.scrollExtentMax ?? double.nan,
scrollExtentMin: data.scrollExtentMin != null ? data.scrollExtentMin : double.nan, scrollExtentMin: data.scrollExtentMin ?? double.nan,
transform: data.transform?.storage ?? _kIdentityTransform, transform: data.transform?.storage ?? _kIdentityTransform,
elevation: data.elevation, elevation: data.elevation,
thickness: data.thickness, thickness: data.thickness,
......
...@@ -558,7 +558,7 @@ class _FadeInImageState extends State<FadeInImage> with TickerProviderStateMixin ...@@ -558,7 +558,7 @@ class _FadeInImageState extends State<FadeInImage> with TickerProviderStateMixin
return Semantics( return Semantics(
container: _semanticLabel != null, container: _semanticLabel != null,
image: true, image: true,
label: _semanticLabel == null ? '' : _semanticLabel, label: _semanticLabel ?? '',
child: image, child: image,
); );
} }
......
...@@ -710,7 +710,7 @@ class _ImageState extends State<Image> { ...@@ -710,7 +710,7 @@ class _ImageState extends State<Image> {
return Semantics( return Semantics(
container: widget.semanticLabel != null, container: widget.semanticLabel != null,
image: true, image: true,
label: widget.semanticLabel == null ? '' : widget.semanticLabel, label: widget.semanticLabel ?? '',
child: image, child: image,
); );
} }
......
...@@ -460,9 +460,7 @@ class _SwitchingChildBuilderTest extends State<SwitchingChildBuilderTest> { ...@@ -460,9 +460,7 @@ class _SwitchingChildBuilderTest extends State<SwitchingChildBuilderTest> {
return children[index]; return children[index];
}, },
childCount: children.length, childCount: children.length,
findChildIndexCallback: (Key key) { findChildIndexCallback: (Key key) => _mapKeyToIndex[key] ?? -1,
return _mapKeyToIndex[key] == null ? -1 : _mapKeyToIndex[key];
}
), ),
) )
], ],
......
...@@ -46,6 +46,5 @@ class Config { ...@@ -46,6 +46,5 @@ class Config {
String _userHomeDir() { String _userHomeDir() {
final String envKey = platform.operatingSystem == 'windows' ? 'APPDATA' : 'HOME'; final String envKey = platform.operatingSystem == 'windows' ? 'APPDATA' : 'HOME';
final String value = platform.environment[envKey]; return platform.environment[envKey] ?? '.';
return value == null ? '.' : value;
} }
...@@ -288,7 +288,7 @@ class IOSSimulator extends Device { ...@@ -288,7 +288,7 @@ class IOSSimulator extends Device {
if (isSupported()) if (isSupported())
return 'Supported'; return 'Supported';
return _supportMessage != null ? _supportMessage : 'Unknown'; return _supportMessage ?? 'Unknown';
} }
@override @override
......
...@@ -8,7 +8,7 @@ import 'watcher.dart'; ...@@ -8,7 +8,7 @@ import 'watcher.dart';
/// Prints JSON events when running a test in --machine mode. /// Prints JSON events when running a test in --machine mode.
class EventPrinter extends TestWatcher { class EventPrinter extends TestWatcher {
EventPrinter({StringSink out}) : _out = out == null ? stdout: out; EventPrinter({StringSink out}) : _out = out ?? stdout;
final StringSink _out; final StringSink _out;
......
...@@ -105,7 +105,7 @@ class FlutterVersion { ...@@ -105,7 +105,7 @@ class FlutterVersion {
@override @override
String toString() { String toString() {
final String versionText = frameworkVersion == 'unknown' ? '' : ' $frameworkVersion'; final String versionText = frameworkVersion == 'unknown' ? '' : ' $frameworkVersion';
final String flutterText = 'Flutter$versionText • channel $channel${repositoryUrl == null ? 'unknown source' : repositoryUrl}'; final String flutterText = 'Flutter$versionText • channel $channel${repositoryUrl ?? 'unknown source'}';
final String frameworkText = 'Framework • revision $frameworkRevisionShort ($frameworkAge) • $frameworkCommitDate'; final String frameworkText = 'Framework • revision $frameworkRevisionShort ($frameworkAge) • $frameworkCommitDate';
final String engineText = 'Engine • revision $engineRevisionShort'; final String engineText = 'Engine • revision $engineRevisionShort';
final String toolsText = 'Tools • Dart $dartSdkVersion'; final String toolsText = 'Tools • Dart $dartSdkVersion';
......
...@@ -718,13 +718,11 @@ class VM extends ServiceObjectOwner { ...@@ -718,13 +718,11 @@ class VM extends ServiceObjectOwner {
/// The number of bytes allocated (e.g. by malloc) in the native heap. /// The number of bytes allocated (e.g. by malloc) in the native heap.
int _heapAllocatedMemoryUsage; int _heapAllocatedMemoryUsage;
int get heapAllocatedMemoryUsage { int get heapAllocatedMemoryUsage => _heapAllocatedMemoryUsage ?? 0;
return _heapAllocatedMemoryUsage == null ? 0 : _heapAllocatedMemoryUsage;
}
/// The peak resident set size for the process. /// The peak resident set size for the process.
int _maxRSS; int _maxRSS;
int get maxRSS => _maxRSS == null ? 0 : _maxRSS; int get maxRSS => _maxRSS ?? 0;
// The embedder's name, Flutter or dart_runner. // The embedder's name, Flutter or dart_runner.
String _embedder; String _embedder;
......
...@@ -121,7 +121,7 @@ void testUsingContext( ...@@ -121,7 +121,7 @@ void testUsingContext(
}, },
); );
}); });
}, timeout: timeout != null ? timeout : const Timeout(Duration(seconds: 60)), }, timeout: timeout ?? const Timeout(Duration(seconds: 60)),
testOn: testOn, skip: skip); testOn: testOn, skip: skip);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment