Skip to content

Commit 8372001

Browse files
authored
Remove unnecessary null checks in flutter_test (#118865)
1 parent c0ad6ad commit 8372001

14 files changed

+10
-44
lines changed

packages/flutter_test/lib/src/accessibility.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class LabeledTapTargetGuideline extends AccessibilityGuideline {
229229
!data.hasAction(ui.SemanticsAction.tap)) {
230230
return result;
231231
}
232-
if ((data.label == null || data.label.isEmpty) && (data.tooltip == null || data.tooltip.isEmpty)) {
232+
if ((data.label.isEmpty) && (data.tooltip.isEmpty)) {
233233
result += Evaluation.fail(
234234
'$node: expected tappable node to have semantic label, '
235235
'but none was found.\n',

packages/flutter_test/lib/src/all_elements.dart

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class _DepthFirstChildIterator implements Iterator<Element> {
7373
}
7474

7575
void _fillChildren(Element element) {
76-
assert(element != null);
7776
// If we did not have to follow LTR order and could instead use RTL,
7877
// we could avoid reversing this and the operation would be measurably
7978
// faster. Unfortunately, a lot of tests depend on LTR order.

packages/flutter_test/lib/src/animation_sheet.dart

+2-5
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ class AnimationSheetBuilder {
8989
AnimationSheetBuilder({
9090
required this.frameSize,
9191
this.allLayers = false,
92-
}) : assert(!kIsWeb), // Does not support Web. See [AnimationSheetBuilder].
93-
assert(frameSize != null);
92+
}) : assert(!kIsWeb);
9493

9594
/// The size of the child to be recorded.
9695
///
@@ -150,7 +149,6 @@ class AnimationSheetBuilder {
150149
Key? key,
151150
bool recording = true,
152151
}) {
153-
assert(child != null);
154152
return _AnimationSheetRecorder(
155153
key: key,
156154
size: frameSize,
@@ -454,8 +452,7 @@ class _CellSheet extends StatelessWidget {
454452
super.key,
455453
required this.cellSize,
456454
required this.children,
457-
}) : assert(cellSize != null),
458-
assert(children != null && children.isNotEmpty);
455+
}) : assert(children.isNotEmpty);
459456

460457
final Size cellSize;
461458
final List<Widget> children;

packages/flutter_test/lib/src/binding.dart

+1-7
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
772772
VoidCallback invariantTester,
773773
String description,
774774
) {
775-
assert(description != null);
776775
assert(inTest);
777776

778777
// Set the handler only if there is currently none.
@@ -1194,7 +1193,6 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
11941193
Future<T> Function() callback, {
11951194
Duration additionalTime = const Duration(milliseconds: 1000),
11961195
}) {
1197-
assert(additionalTime != null);
11981196
assert(() {
11991197
if (_pendingAsyncTasks == null) {
12001198
return true;
@@ -1335,7 +1333,6 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
13351333
debugBuildingDirtyElements = true;
13361334
buildOwner!.buildScope(renderViewElement!);
13371335
if (_phase != EnginePhase.build) {
1338-
assert(renderView != null);
13391336
pipelineOwner.flushLayout();
13401337
if (_phase != EnginePhase.layout) {
13411338
pipelineOwner.flushCompositingBits();
@@ -1383,7 +1380,6 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
13831380
)
13841381
Duration? timeout,
13851382
}) {
1386-
assert(description != null);
13871383
assert(!inTest);
13881384
assert(_currentFakeAsync == null);
13891385
assert(_clock == null);
@@ -1885,7 +1881,6 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
18851881
)
18861882
Duration? timeout,
18871883
}) {
1888-
assert(description != null);
18891884
assert(!inTest);
18901885
_inTest = true;
18911886
_liveTestRenderView._setDescription(description);
@@ -2038,7 +2033,6 @@ class _LiveTestRenderView extends RenderView {
20382033
fontSize: 10.0,
20392034
);
20402035
void _setDescription(String value) {
2041-
assert(value != null);
20422036
if (value.isEmpty) {
20432037
_label = null;
20442038
return;
@@ -2081,7 +2075,7 @@ class _LiveTestRenderView extends RenderView {
20812075
.where((int pointer) => _pointers[pointer]!.decay == 0)
20822076
.toList()
20832077
.forEach(_pointers.remove);
2084-
if (dirty && onNeedPaint != null) {
2078+
if (dirty) {
20852079
scheduleMicrotask(onNeedPaint);
20862080
}
20872081
}

packages/flutter_test/lib/src/controller.dart

+1-11
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,6 @@ abstract class WidgetController {
890890
assert(kDragSlopDefault > kTouchSlop);
891891
return TestAsyncUtils.guard<void>(() async {
892892
final TestGesture gesture = await startGesture(startLocation, pointer: pointer, buttons: buttons, kind: kind);
893-
assert(gesture != null);
894893

895894
final double xSign = offset.dx.sign;
896895
final double ySign = offset.dy.sign;
@@ -1120,7 +1119,6 @@ abstract class WidgetController {
11201119
PointerDeviceKind kind = PointerDeviceKind.touch,
11211120
int buttons = kPrimaryButton,
11221121
}) async {
1123-
assert(downLocation != null);
11241122
final TestGesture result = await createGesture(
11251123
pointer: pointer,
11261124
kind: kind,
@@ -1268,9 +1266,7 @@ abstract class WidgetController {
12681266
}
12691267
if (!found) {
12701268
bool outOfBounds = false;
1271-
if (binding.renderView != null && binding.renderView.size != null) {
1272-
outOfBounds = !(Offset.zero & binding.renderView.size).contains(location);
1273-
}
1269+
outOfBounds = !(Offset.zero & binding.renderView.size).contains(location);
12741270
if (hitTestWarningShouldBeFatal) {
12751271
throw FlutterError.fromParts(<DiagnosticsNode>[
12761272
ErrorSummary('Finder specifies a widget that would not receive pointer events.'),
@@ -1349,7 +1345,6 @@ abstract class WidgetController {
13491345
String? character,
13501346
PhysicalKeyboardKey? physicalKey
13511347
}) async {
1352-
assert(platform != null);
13531348
final bool handled = await simulateKeyDownEvent(key, platform: platform, character: character, physicalKey: physicalKey);
13541349
// Internally wrapped in async guard.
13551350
await simulateKeyUpEvent(key, platform: platform, physicalKey: physicalKey);
@@ -1393,7 +1388,6 @@ abstract class WidgetController {
13931388
String? character,
13941389
PhysicalKeyboardKey? physicalKey
13951390
}) async {
1396-
assert(platform != null);
13971391
// Internally wrapped in async guard.
13981392
return simulateKeyDownEvent(key, platform: platform, character: character, physicalKey: physicalKey);
13991393
}
@@ -1427,7 +1421,6 @@ abstract class WidgetController {
14271421
String platform = _defaultPlatform,
14281422
PhysicalKeyboardKey? physicalKey
14291423
}) async {
1430-
assert(platform != null);
14311424
// Internally wrapped in async guard.
14321425
return simulateKeyUpEvent(key, platform: platform, physicalKey: physicalKey);
14331426
}
@@ -1469,7 +1462,6 @@ abstract class WidgetController {
14691462
String? character,
14701463
PhysicalKeyboardKey? physicalKey
14711464
}) async {
1472-
assert(platform != null);
14731465
// Internally wrapped in async guard.
14741466
return simulateKeyRepeatEvent(key, platform: platform, character: character, physicalKey: physicalKey);
14751467
}
@@ -1627,7 +1619,6 @@ class LiveWidgetController extends WidgetController {
16271619
Future<int> pumpAndSettle([
16281620
Duration duration = const Duration(milliseconds: 100),
16291621
]) {
1630-
assert(duration != null);
16311622
assert(duration > Duration.zero);
16321623
return TestAsyncUtils.guard<int>(() async {
16331624
int count = 0;
@@ -1641,7 +1632,6 @@ class LiveWidgetController extends WidgetController {
16411632

16421633
@override
16431634
Future<List<Duration>> handlePointerEventRecord(List<PointerEventRecord> records) {
1644-
assert(records != null);
16451635
assert(records.isNotEmpty);
16461636
return TestAsyncUtils.guard<List<Duration>>(() async {
16471637
final List<Duration> handleTimeStampDiff = <Duration>[];

packages/flutter_test/lib/src/finders.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ abstract class Finder {
567567
/// Applies additional filtering against a [parent] [Finder].
568568
abstract class ChainedFinder extends Finder {
569569
/// Create a Finder chained against the candidates of another [Finder].
570-
ChainedFinder(this.parent) : assert(parent != null);
570+
ChainedFinder(this.parent);
571571

572572
/// Another [Finder] that will run first.
573573
final Finder parent;

packages/flutter_test/lib/src/frame_timing_summarizer.dart

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class FrameTimingSummarizer {
2222
int? newGenGCCount,
2323
int? oldGenGCCount,
2424
}) {
25-
assert(data != null);
2625
assert(data.isNotEmpty);
2726
final List<Duration> frameBuildTime = List<Duration>.unmodifiable(
2827
data.map<Duration>((FrameTiming datum) => datum.buildDuration),

packages/flutter_test/lib/src/image.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ Future<ui.Image> createTestImage({
2929
int height = 1,
3030
bool cache = true,
3131
}) => TestAsyncUtils.guard(() async {
32-
assert(width != null && width > 0);
33-
assert(height != null && height > 0);
34-
assert(cache != null);
32+
assert(width > 0);
33+
assert(height > 0);
3534

3635
final int cacheKey = Object.hash(width, height);
3736
if (cache && _cache.containsKey(cacheKey)) {

packages/flutter_test/lib/src/matchers.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ class _CoversSameAreaAs extends Matcher {
19811981
class _ColorMatcher extends Matcher {
19821982
const _ColorMatcher({
19831983
required this.targetColor,
1984-
}) : assert(targetColor != null);
1984+
});
19851985

19861986
final Color targetColor;
19871987

packages/flutter_test/lib/src/stack_manipulation.dart

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ int reportExpectCall(StackTrace stack, List<DiagnosticsNode> information) {
2626
line2.firstMatch(stackLines[2]) != null &&
2727
line3.firstMatch(stackLines[3]) != null) {
2828
final Match expectMatch = line4.firstMatch(stackLines[4])!;
29-
assert(expectMatch != null);
3029
assert(expectMatch.groupCount == 2);
3130
information.add(DiagnosticsStackTrace.singleFrame(
3231
'This was caught by the test expectation on the following line',

packages/flutter_test/lib/src/test_async_utils.dart

-3
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,7 @@ class TestAsyncUtils {
187187
return;
188188
}
189189
candidateScope = _scopeStack[_scopeStack.length - skipCount - 1];
190-
assert(candidateScope != null);
191-
assert(candidateScope.zone != null);
192190
} while (candidateScope.zone != zone);
193-
assert(scope != null);
194191
final List<DiagnosticsNode> information = <DiagnosticsNode>[
195192
ErrorSummary('Guarded function conflict.'),
196193
ErrorHint('You must use "await" with all Future-returning test APIs.'),

packages/flutter_test/lib/src/test_default_binary_messenger.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TestDefaultBinaryMessenger extends BinaryMessenger {
4646
/// Creates a [TestDefaultBinaryMessenger] instance.
4747
///
4848
/// The [delegate] instance must not be null.
49-
TestDefaultBinaryMessenger(this.delegate): assert(delegate != null);
49+
TestDefaultBinaryMessenger(this.delegate);
5050

5151
/// The delegate [BinaryMessenger].
5252
final BinaryMessenger delegate;

packages/flutter_test/lib/src/test_exception_reporter.dart

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ typedef TestExceptionReporter = void Function(FlutterErrorDetails details, Strin
2424
TestExceptionReporter get reportTestException => _reportTestException;
2525
TestExceptionReporter _reportTestException = _defaultTestExceptionReporter;
2626
set reportTestException(TestExceptionReporter handler) {
27-
assert(handler != null);
2827
_reportTestException = handler;
2928
}
3029

packages/flutter_test/lib/src/widget_tester.dart

-7
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ void testWidgets(
138138
TestVariant<Object?> variant = const DefaultTestVariant(),
139139
dynamic tags,
140140
}) {
141-
assert(variant != null);
142141
assert(variant.values.isNotEmpty, 'There must be at least one value to test in the testing variant.');
143142
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
144143
final WidgetTester tester = WidgetTester._(binding);
@@ -573,7 +572,6 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
573572

574573
@override
575574
Future<List<Duration>> handlePointerEventRecord(Iterable<PointerEventRecord> records) {
576-
assert(records != null);
577575
assert(records.isNotEmpty);
578576
return TestAsyncUtils.guard<List<Duration>>(() async {
579577
final List<Duration> handleTimeStampDiff = <Duration>[];
@@ -664,9 +662,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
664662
EnginePhase phase = EnginePhase.sendSemanticsUpdate,
665663
Duration timeout = const Duration(minutes: 10),
666664
]) {
667-
assert(duration != null);
668665
assert(duration > Duration.zero);
669-
assert(timeout != null);
670666
assert(timeout > Duration.zero);
671667
assert(() {
672668
final WidgetsBinding binding = this.binding;
@@ -705,7 +701,6 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
705701
Duration maxDuration, [
706702
Duration interval = const Duration(milliseconds: 16, microseconds: 683),
707703
]) {
708-
assert(maxDuration != null);
709704
// The interval following the last frame doesn't have to be within the fullDuration.
710705
Duration elapsed = Duration.zero;
711706
return TestAsyncUtils.guard<void>(() async {
@@ -822,7 +817,6 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
822817

823818
@override
824819
HitTestResult hitTestOnBinding(Offset location) {
825-
assert(location != null);
826820
location = binding.localToGlobal(location);
827821
return super.hitTestOnBinding(location);
828822
}
@@ -1003,7 +997,6 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
1003997
/// error message. It should be an adverbial phrase describing the current
1004998
/// situation, such as "at the end of the test".
1005999
void verifyTickersWereDisposed([ String when = 'when none should have been' ]) {
1006-
assert(when != null);
10071000
if (_tickers != null) {
10081001
for (final Ticker ticker in _tickers!) {
10091002
if (ticker.isActive) {

0 commit comments

Comments
 (0)