Skip to content

Commit 288a773

Browse files
authored
Remove unnecessary null checks in flutter_driver (#118864)
1 parent 8372001 commit 288a773

File tree

11 files changed

+14
-52
lines changed

11 files changed

+14
-52
lines changed

packages/flutter_driver/lib/src/common/diagnostics_tree.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class GetDiagnosticsTree extends CommandWithTarget {
2828
this.subtreeDepth = 0,
2929
this.includeProperties = true,
3030
super.timeout,
31-
}) : assert(subtreeDepth != null),
32-
assert(includeProperties != null);
31+
});
3332

3433
/// Deserializes this command from the value generated by [serialize].
3534
GetDiagnosticsTree.deserialize(super.json, super.finderFactory)

packages/flutter_driver/lib/src/common/find.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ DriverError _createInvalidKeyValueTypeError(String invalidType) {
2323
/// and add more keys to the returned map.
2424
abstract class CommandWithTarget extends Command {
2525
/// Constructs this command given a [finder].
26-
CommandWithTarget(this.finder, {super.timeout}) {
27-
assert(finder != null, '$runtimeType target cannot be null');
28-
}
26+
CommandWithTarget(this.finder, {super.timeout});
2927

3028
/// Deserializes this command from the value generated by [serialize].
3129
CommandWithTarget.deserialize(super.json, DeserializeFinderFactory finderFactory)

packages/flutter_driver/lib/src/common/handler_factory.dart

-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ mixin CommandHandlerFactory {
260260
}
261261

262262
Future<Result> _waitForCondition(Command command) async {
263-
assert(command != null);
264263
final WaitForCondition waitForConditionCommand = command as WaitForCondition;
265264
final WaitCondition condition = deserializeCondition(waitForConditionCommand.condition);
266265
await condition.wait();

packages/flutter_driver/lib/src/common/health.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ final EnumIndex<HealthStatus> _healthStatusIndex =
3636
/// [FlutterDriver.checkHealth] test.
3737
class Health extends Result {
3838
/// Creates a [Health] object with the given [status].
39-
const Health(this.status)
40-
: assert(status != null);
39+
const Health(this.status);
4140

4241
/// The status represented by this object.
4342
///

packages/flutter_driver/lib/src/common/wait.dart

+3-13
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ class WaitForCondition extends Command {
1111
/// Creates a command that waits for the given [condition] is met.
1212
///
1313
/// The [condition] argument must not be null.
14-
const WaitForCondition(this.condition, {super.timeout})
15-
: assert(condition != null);
14+
const WaitForCondition(this.condition, {super.timeout});
1615

1716
/// Deserializes this command from the value generated by [serialize].
1817
///
1918
/// The [json] argument cannot be null.
2019
WaitForCondition.deserialize(super.json)
21-
: assert(json != null),
22-
condition = _deserialize(json),
20+
: condition = _deserialize(json),
2321
super.deserialize();
2422

2523
/// The condition that this command shall wait for.
@@ -94,7 +92,6 @@ class NoTransientCallbacks extends SerializableWaitCondition {
9492
///
9593
/// The [json] argument must not be null.
9694
factory NoTransientCallbacks.deserialize(Map<String, String> json) {
97-
assert(json != null);
9895
if (json['conditionName'] != 'NoTransientCallbacksCondition') {
9996
throw SerializationException('Error occurred during deserializing the NoTransientCallbacksCondition JSON string: $json');
10097
}
@@ -115,7 +112,6 @@ class NoPendingFrame extends SerializableWaitCondition {
115112
///
116113
/// The [json] argument must not be null.
117114
factory NoPendingFrame.deserialize(Map<String, String> json) {
118-
assert(json != null);
119115
if (json['conditionName'] != 'NoPendingFrameCondition') {
120116
throw SerializationException('Error occurred during deserializing the NoPendingFrameCondition JSON string: $json');
121117
}
@@ -136,7 +132,6 @@ class FirstFrameRasterized extends SerializableWaitCondition {
136132
///
137133
/// The [json] argument must not be null.
138134
factory FirstFrameRasterized.deserialize(Map<String, String> json) {
139-
assert(json != null);
140135
if (json['conditionName'] != 'FirstFrameRasterizedCondition') {
141136
throw SerializationException('Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: $json');
142137
}
@@ -160,7 +155,6 @@ class NoPendingPlatformMessages extends SerializableWaitCondition {
160155
///
161156
/// The [json] argument must not be null.
162157
factory NoPendingPlatformMessages.deserialize(Map<String, String> json) {
163-
assert(json != null);
164158
if (json['conditionName'] != 'NoPendingPlatformMessagesCondition') {
165159
throw SerializationException('Error occurred during deserializing the NoPendingPlatformMessagesCondition JSON string: $json');
166160
}
@@ -176,15 +170,13 @@ class CombinedCondition extends SerializableWaitCondition {
176170
/// Creates a [CombinedCondition] condition.
177171
///
178172
/// The [conditions] argument must not be null.
179-
const CombinedCondition(this.conditions)
180-
: assert(conditions != null);
173+
const CombinedCondition(this.conditions);
181174

182175
/// Factory constructor to parse a [CombinedCondition] instance from the
183176
/// given JSON map.
184177
///
185178
/// The [jsonMap] argument must not be null.
186179
factory CombinedCondition.deserialize(Map<String, String> jsonMap) {
187-
assert(jsonMap != null);
188180
if (jsonMap['conditionName'] != 'CombinedCondition') {
189181
throw SerializationException('Error occurred during deserializing the CombinedCondition JSON string: $jsonMap');
190182
}
@@ -210,7 +202,6 @@ class CombinedCondition extends SerializableWaitCondition {
210202
final Map<String, String> jsonMap = super.serialize();
211203
final List<Map<String, String>> jsonConditions = conditions.map(
212204
(SerializableWaitCondition condition) {
213-
assert(condition != null);
214205
return condition.serialize();
215206
}).toList();
216207
jsonMap['conditions'] = json.encode(jsonConditions);
@@ -222,7 +213,6 @@ class CombinedCondition extends SerializableWaitCondition {
222213
///
223214
/// The [json] argument must not be null.
224215
SerializableWaitCondition _deserialize(Map<String, String> json) {
225-
assert(json != null);
226216
final String conditionName = json['conditionName']!;
227217
switch (conditionName) {
228218
case 'NoTransientCallbacksCondition':

packages/flutter_driver/lib/src/driver/driver.dart

-7
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,6 @@ abstract class FlutterDriver {
432432
double dyScroll = 0.0,
433433
Duration? timeout,
434434
}) async {
435-
assert(scrollable != null);
436-
assert(item != null);
437-
assert(alignment != null);
438-
assert(dxScroll != null);
439-
assert(dyScroll != null);
440435
assert(dxScroll != 0.0 || dyScroll != 0.0);
441436

442437
// Kick off an (unawaited) waitFor that will complete when the item we're
@@ -509,7 +504,6 @@ abstract class FlutterDriver {
509504
/// invoked when the widget is focused, as the [SystemChannels.textInput]
510505
/// channel will be mocked out.
511506
Future<void> setTextEntryEmulation({ required bool enabled, Duration? timeout }) async {
512-
assert(enabled != null);
513507
await sendCommand(SetTextEntryEmulation(enabled, timeout: timeout));
514508
}
515509

@@ -537,7 +531,6 @@ abstract class FlutterDriver {
537531
///
538532
Future<void> sendTextInputAction(TextInputAction action,
539533
{Duration? timeout}) async {
540-
assert(action != null);
541534
await sendCommand(SendTextInputAction(action, timeout: timeout));
542535
}
543536

packages/flutter_driver/lib/src/driver/vmservice_driver.dart

+2-9
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
144144
// Let subsequent isolates start automatically.
145145
try {
146146
final vms.Response result = await client.setFlag('pause_isolates_on_start', 'false');
147-
if (result == null || result.type != 'Success') {
147+
if (result.type != 'Success') {
148148
_log('setFlag failure: $result');
149149
}
150150
} catch (e) {
@@ -348,7 +348,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
348348
_log(message);
349349
}
350350
if (_logCommunicationToFile) {
351-
assert(_logFilePathName != null);
352351
final f.File file = fs.file(_logFilePathName);
353352
file.createSync(recursive: true); // no-op if file exists
354353
file.writeAsStringSync('${DateTime.now()} $message\n', mode: f.FileMode.append, flush: true);
@@ -380,8 +379,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
380379
List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all],
381380
Duration timeout = kUnusuallyLongTimeout,
382381
}) async {
383-
assert(streams != null && streams.isNotEmpty);
384-
assert(timeout != null);
382+
assert(streams.isNotEmpty);
385383
try {
386384
await _warnIfSlow<vms.Success>(
387385
future: _serviceClient.setVMTimelineFlags(
@@ -405,7 +403,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
405403
int? startTime,
406404
int? endTime,
407405
}) async {
408-
assert(timeout != null);
409406
assert((startTime == null && endTime == null) ||
410407
(startTime != null && endTime != null));
411408

@@ -497,7 +494,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
497494
Future<void> clearTimeline({
498495
Duration timeout = kUnusuallyLongTimeout,
499496
}) async {
500-
assert(timeout != null);
501497
try {
502498
await _warnIfSlow<vms.Success>(
503499
future: _serviceClient.clearVMTimeline(),
@@ -630,9 +626,6 @@ Future<T> _warnIfSlow<T>({
630626
required Duration timeout,
631627
required String message,
632628
}) async {
633-
assert(future != null);
634-
assert(timeout != null);
635-
assert(message != null);
636629
final Completer<void> completer = Completer<void>();
637630
completer.future.timeout(timeout, onTimeout: () {
638631
_log(message);

packages/flutter_driver/lib/src/driver/web_driver.dart

-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ class WebFlutterDriver extends FlutterDriver {
174174
driverLog('WebFlutterDriver', message);
175175
}
176176
if (_logCommunicationToFile) {
177-
assert(_logFilePathName != null);
178177
final File file = fs.file(_logFilePathName);
179178
file.createSync(recursive: true); // no-op if file exists
180179
file.writeAsStringSync('${DateTime.now()} $message\n', mode: FileMode.append, flush: true);

packages/flutter_driver/lib/src/extension/extension.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class FlutterDriverExtension with DeserializeFinderFactory, CreateFinderFactory,
319319
this._enableTextEntryEmulation, {
320320
List<FinderExtension> finders = const <FinderExtension>[],
321321
List<CommandExtension> commands = const <CommandExtension>[],
322-
}) : assert(finders != null) {
322+
}) {
323323
if (_enableTextEntryEmulation) {
324324
registerTextInput();
325325
}

packages/flutter_driver/lib/src/extension/wait_conditions.dart

+1-9
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class _InternalNoTransientCallbacksCondition implements WaitCondition {
4242
///
4343
/// The [condition] argument must not be null.
4444
factory _InternalNoTransientCallbacksCondition.deserialize(SerializableWaitCondition condition) {
45-
assert(condition != null);
4645
if (condition.conditionName != 'NoTransientCallbacksCondition') {
4746
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
4847
}
@@ -71,7 +70,6 @@ class _InternalNoPendingFrameCondition implements WaitCondition {
7170
///
7271
/// The [condition] argument must not be null.
7372
factory _InternalNoPendingFrameCondition.deserialize(SerializableWaitCondition condition) {
74-
assert(condition != null);
7573
if (condition.conditionName != 'NoPendingFrameCondition') {
7674
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
7775
}
@@ -100,7 +98,6 @@ class _InternalFirstFrameRasterizedCondition implements WaitCondition {
10098
///
10199
/// The [condition] argument must not be null.
102100
factory _InternalFirstFrameRasterizedCondition.deserialize(SerializableWaitCondition condition) {
103-
assert(condition != null);
104101
if (condition.conditionName != 'FirstFrameRasterizedCondition') {
105102
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
106103
}
@@ -127,7 +124,6 @@ class _InternalNoPendingPlatformMessagesCondition implements WaitCondition {
127124
///
128125
/// The [condition] argument must not be null.
129126
factory _InternalNoPendingPlatformMessagesCondition.deserialize(SerializableWaitCondition condition) {
130-
assert(condition != null);
131127
if (condition.conditionName != 'NoPendingPlatformMessagesCondition') {
132128
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
133129
}
@@ -156,15 +152,13 @@ class _InternalCombinedCondition implements WaitCondition {
156152
/// [conditions].
157153
///
158154
/// The [conditions] argument must not be null.
159-
const _InternalCombinedCondition(this.conditions)
160-
: assert(conditions != null);
155+
const _InternalCombinedCondition(this.conditions);
161156

162157
/// Factory constructor to parse an [_InternalCombinedCondition] instance from
163158
/// the given [SerializableWaitCondition] instance.
164159
///
165160
/// The [condition] argument must not be null.
166161
factory _InternalCombinedCondition.deserialize(SerializableWaitCondition condition) {
167-
assert(condition != null);
168162
if (condition.conditionName != 'CombinedCondition') {
169163
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
170164
}
@@ -185,7 +179,6 @@ class _InternalCombinedCondition implements WaitCondition {
185179
Future<void> wait() async {
186180
while (!condition) {
187181
for (final WaitCondition condition in conditions) {
188-
assert (condition != null);
189182
await condition.wait();
190183
}
191184
}
@@ -197,7 +190,6 @@ class _InternalCombinedCondition implements WaitCondition {
197190
///
198191
/// The [waitCondition] argument must not be null.
199192
WaitCondition deserializeCondition(SerializableWaitCondition waitCondition) {
200-
assert(waitCondition != null);
201193
final String conditionName = waitCondition.conditionName;
202194
switch (conditionName) {
203195
case 'NoTransientCallbacksCondition':

packages/flutter_driver/test/src/real_tests/flutter_driver_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -1193,9 +1193,9 @@ class FakeVmService extends Fake implements vms.VmService {
11931193
commandLog.add('$method $args');
11941194
await artificialExtensionDelay;
11951195

1196-
final vms.Response response = responses[args!['command']]!;
1196+
final vms.Response? response = responses[args!['command']];
11971197
assert(response != null, 'Failed to create a response for ${args['command']}');
1198-
return response;
1198+
return response!;
11991199
}
12001200

12011201
@override
@@ -1243,9 +1243,9 @@ class FakeVmService extends Fake implements vms.VmService {
12431243
@override
12441244
Future<vms.Timeline> getVMTimeline({int? timeOriginMicros, int? timeExtentMicros}) async {
12451245
connectionLog.add('getVMTimeline $timeOriginMicros $timeExtentMicros');
1246-
final vms.Timeline timeline = timelineResponses[timeOriginMicros ?? 1]!;
1246+
final vms.Timeline? timeline = timelineResponses[timeOriginMicros ?? 1];
12471247
assert(timeline != null, 'Missing entry in timelineResponses[$timeOriginMicros]');
1248-
return timeline;
1248+
return timeline!;
12491249
}
12501250

12511251
@override

0 commit comments

Comments
 (0)