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