mirror of
https://github.com/flutter/flutter
synced 2024-08-27 12:00:58 +00:00
Use curly_braces_in_flow_control_structures
for non-flutter
packages (#104629)
* Use `curly_braces_in_flow_control_structures` for `packages/flutter_driver` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_goldens` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_goldens_client` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_localizations` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_test` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_web_plugins` * fix comments * Use `curly_braces_in_flow_control_structures` for `packages/integration_test` * fix indentation
This commit is contained in:
parent
a0248ebdf2
commit
74cfc3db67
|
@ -21,8 +21,9 @@ class DriverError extends Error {
|
|||
|
||||
@override
|
||||
String toString() {
|
||||
if (originalError == null)
|
||||
if (originalError == null) {
|
||||
return 'DriverError: $message\n';
|
||||
}
|
||||
return '''
|
||||
DriverError: $message
|
||||
Original error: $originalError
|
||||
|
|
|
@ -205,8 +205,9 @@ class ByValueKey extends SerializableFinder {
|
|||
ByValueKey(this.keyValue)
|
||||
: keyValueString = '$keyValue',
|
||||
keyValueType = '${keyValue.runtimeType}' {
|
||||
if (!_supportedKeyValueTypes.contains(keyValue.runtimeType))
|
||||
if (!_supportedKeyValueTypes.contains(keyValue.runtimeType)) {
|
||||
throw _createInvalidKeyValueTypeError('$keyValue.runtimeType');
|
||||
}
|
||||
}
|
||||
|
||||
/// The true value of the key.
|
||||
|
|
|
@ -260,8 +260,9 @@ mixin CommandHandlerFactory {
|
|||
'This feature was deprecated after v1.9.3.'
|
||||
)
|
||||
Future<Result> _waitUntilNoTransientCallbacks(Command command) async {
|
||||
if (SchedulerBinding.instance.transientCallbackCount != 0)
|
||||
if (SchedulerBinding.instance.transientCallbackCount != 0) {
|
||||
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
|
||||
}
|
||||
return Result.empty;
|
||||
}
|
||||
|
||||
|
@ -310,8 +311,9 @@ mixin CommandHandlerFactory {
|
|||
node = renderObject.debugSemantics;
|
||||
renderObject = renderObject.parent as RenderObject?;
|
||||
}
|
||||
if (node == null)
|
||||
if (node == null) {
|
||||
throw StateError('No semantics data found');
|
||||
}
|
||||
return GetSemanticsIdResult(node.id);
|
||||
}
|
||||
|
||||
|
@ -464,26 +466,30 @@ mixin CommandHandlerFactory {
|
|||
|
||||
/// Runs `finder` repeatedly until it finds one or more [Element]s.
|
||||
Future<Finder> waitForElement(Finder finder) async {
|
||||
if (_frameSync)
|
||||
if (_frameSync) {
|
||||
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
|
||||
}
|
||||
|
||||
await _waitUntilFrame(() => finder.evaluate().isNotEmpty);
|
||||
|
||||
if (_frameSync)
|
||||
if (_frameSync) {
|
||||
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
|
||||
}
|
||||
|
||||
return finder;
|
||||
}
|
||||
|
||||
/// Runs `finder` repeatedly until it finds zero [Element]s.
|
||||
Future<Finder> waitForAbsentElement(Finder finder) async {
|
||||
if (_frameSync)
|
||||
if (_frameSync) {
|
||||
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
|
||||
}
|
||||
|
||||
await _waitUntilFrame(() => finder.evaluate().isEmpty);
|
||||
|
||||
if (_frameSync)
|
||||
if (_frameSync) {
|
||||
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
|
||||
}
|
||||
|
||||
return finder;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@ abstract class Command {
|
|||
|
||||
static Duration? _parseTimeout(Map<String, String> json) {
|
||||
final String? timeout = json['timeout'];
|
||||
if (timeout == null)
|
||||
if (timeout == null) {
|
||||
return null;
|
||||
}
|
||||
return Duration(milliseconds: int.parse(timeout));
|
||||
}
|
||||
|
||||
|
@ -52,8 +53,9 @@ abstract class Command {
|
|||
final Map<String, String> result = <String, String>{
|
||||
'command': kind,
|
||||
};
|
||||
if (timeout != null)
|
||||
if (timeout != null) {
|
||||
result['timeout'] = '${timeout!.inMilliseconds}';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,8 +95,9 @@ class NoTransientCallbacks extends SerializableWaitCondition {
|
|||
/// The [json] argument must not be null.
|
||||
factory NoTransientCallbacks.deserialize(Map<String, String> json) {
|
||||
assert(json != null);
|
||||
if (json['conditionName'] != 'NoTransientCallbacksCondition')
|
||||
if (json['conditionName'] != 'NoTransientCallbacksCondition') {
|
||||
throw SerializationException('Error occurred during deserializing the NoTransientCallbacksCondition JSON string: $json');
|
||||
}
|
||||
return const NoTransientCallbacks();
|
||||
}
|
||||
|
||||
|
@ -115,8 +116,9 @@ class NoPendingFrame extends SerializableWaitCondition {
|
|||
/// The [json] argument must not be null.
|
||||
factory NoPendingFrame.deserialize(Map<String, String> json) {
|
||||
assert(json != null);
|
||||
if (json['conditionName'] != 'NoPendingFrameCondition')
|
||||
if (json['conditionName'] != 'NoPendingFrameCondition') {
|
||||
throw SerializationException('Error occurred during deserializing the NoPendingFrameCondition JSON string: $json');
|
||||
}
|
||||
return const NoPendingFrame();
|
||||
}
|
||||
|
||||
|
@ -135,8 +137,9 @@ class FirstFrameRasterized extends SerializableWaitCondition {
|
|||
/// The [json] argument must not be null.
|
||||
factory FirstFrameRasterized.deserialize(Map<String, String> json) {
|
||||
assert(json != null);
|
||||
if (json['conditionName'] != 'FirstFrameRasterizedCondition')
|
||||
if (json['conditionName'] != 'FirstFrameRasterizedCondition') {
|
||||
throw SerializationException('Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: $json');
|
||||
}
|
||||
return const FirstFrameRasterized();
|
||||
}
|
||||
|
||||
|
@ -158,8 +161,9 @@ class NoPendingPlatformMessages extends SerializableWaitCondition {
|
|||
/// The [json] argument must not be null.
|
||||
factory NoPendingPlatformMessages.deserialize(Map<String, String> json) {
|
||||
assert(json != null);
|
||||
if (json['conditionName'] != 'NoPendingPlatformMessagesCondition')
|
||||
if (json['conditionName'] != 'NoPendingPlatformMessagesCondition') {
|
||||
throw SerializationException('Error occurred during deserializing the NoPendingPlatformMessagesCondition JSON string: $json');
|
||||
}
|
||||
return const NoPendingPlatformMessages();
|
||||
}
|
||||
|
||||
|
@ -181,8 +185,9 @@ class CombinedCondition extends SerializableWaitCondition {
|
|||
/// The [jsonMap] argument must not be null.
|
||||
factory CombinedCondition.deserialize(Map<String, String> jsonMap) {
|
||||
assert(jsonMap != null);
|
||||
if (jsonMap['conditionName'] != 'CombinedCondition')
|
||||
if (jsonMap['conditionName'] != 'CombinedCondition') {
|
||||
throw SerializationException('Error occurred during deserializing the CombinedCondition JSON string: $jsonMap');
|
||||
}
|
||||
if (jsonMap['conditions'] == null) {
|
||||
return const CombinedCondition(<SerializableWaitCondition>[]);
|
||||
}
|
||||
|
|
|
@ -410,23 +410,26 @@ class TimelineSummary {
|
|||
}
|
||||
|
||||
double _averageInMillis(Iterable<Duration> durations) {
|
||||
if (durations.isEmpty)
|
||||
if (durations.isEmpty) {
|
||||
throw ArgumentError('durations is empty!');
|
||||
}
|
||||
final double total = durations.fold<double>(0.0, (double t, Duration duration) => t + duration.inMicroseconds.toDouble() / 1000.0);
|
||||
return total / durations.length;
|
||||
}
|
||||
|
||||
double _percentileInMillis(Iterable<Duration> durations, double percentile) {
|
||||
if (durations.isEmpty)
|
||||
if (durations.isEmpty) {
|
||||
throw ArgumentError('durations is empty!');
|
||||
}
|
||||
assert(percentile >= 0.0 && percentile <= 100.0);
|
||||
final List<double> doubles = durations.map<double>((Duration duration) => duration.inMicroseconds.toDouble() / 1000.0).toList();
|
||||
return findPercentile(doubles, percentile);
|
||||
}
|
||||
|
||||
double _maxInMillis(Iterable<Duration> durations) {
|
||||
if (durations.isEmpty)
|
||||
if (durations.isEmpty) {
|
||||
throw ArgumentError('durations is empty!');
|
||||
}
|
||||
return durations
|
||||
.map<double>((Duration duration) => duration.inMicroseconds.toDouble() / 1000.0)
|
||||
.reduce(math.max);
|
||||
|
|
|
@ -321,14 +321,16 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
|||
stackTrace,
|
||||
);
|
||||
}
|
||||
if ((response['isError'] as bool?) ?? false)
|
||||
if ((response['isError'] as bool?) ?? false) {
|
||||
throw DriverError('Error in Flutter application: ${response['response']}');
|
||||
}
|
||||
return response['response'] as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
void _logCommunication(String message) {
|
||||
if (_printCommunication)
|
||||
if (_printCommunication) {
|
||||
_log(message);
|
||||
}
|
||||
if (_logCommunicationToFile) {
|
||||
assert(_logFilePathName != null);
|
||||
final f.File file = fs.file(_logFilePathName);
|
||||
|
@ -533,8 +535,9 @@ String _getWebSocketUrl(String url) {
|
|||
if (uri.pathSegments.isNotEmpty) uri.pathSegments.first,
|
||||
'ws',
|
||||
];
|
||||
if (uri.scheme == 'http')
|
||||
if (uri.scheme == 'http') {
|
||||
uri = uri.replace(scheme: 'ws', pathSegments: pathSegments);
|
||||
}
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -377,8 +377,9 @@ class FlutterDriverExtension with DeserializeFinderFactory, CreateFinderFactory,
|
|||
return _makeResponse(message, isError: true);
|
||||
} catch (error, stackTrace) {
|
||||
final String message = 'Uncaught extension error while executing $commandKind: $error\n$stackTrace';
|
||||
if (!_silenceErrors)
|
||||
if (!_silenceErrors) {
|
||||
_log(message);
|
||||
}
|
||||
return _makeResponse(message, isError: true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,9 @@ class _InternalNoTransientCallbacksCondition implements WaitCondition {
|
|||
/// The [condition] argument must not be null.
|
||||
factory _InternalNoTransientCallbacksCondition.deserialize(SerializableWaitCondition condition) {
|
||||
assert(condition != null);
|
||||
if (condition.conditionName != 'NoTransientCallbacksCondition')
|
||||
if (condition.conditionName != 'NoTransientCallbacksCondition') {
|
||||
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
|
||||
}
|
||||
return const _InternalNoTransientCallbacksCondition();
|
||||
}
|
||||
|
||||
|
@ -71,8 +72,9 @@ class _InternalNoPendingFrameCondition implements WaitCondition {
|
|||
/// The [condition] argument must not be null.
|
||||
factory _InternalNoPendingFrameCondition.deserialize(SerializableWaitCondition condition) {
|
||||
assert(condition != null);
|
||||
if (condition.conditionName != 'NoPendingFrameCondition')
|
||||
if (condition.conditionName != 'NoPendingFrameCondition') {
|
||||
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
|
||||
}
|
||||
return const _InternalNoPendingFrameCondition();
|
||||
}
|
||||
|
||||
|
@ -99,8 +101,9 @@ class _InternalFirstFrameRasterizedCondition implements WaitCondition {
|
|||
/// The [condition] argument must not be null.
|
||||
factory _InternalFirstFrameRasterizedCondition.deserialize(SerializableWaitCondition condition) {
|
||||
assert(condition != null);
|
||||
if (condition.conditionName != 'FirstFrameRasterizedCondition')
|
||||
if (condition.conditionName != 'FirstFrameRasterizedCondition') {
|
||||
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
|
||||
}
|
||||
return const _InternalFirstFrameRasterizedCondition();
|
||||
}
|
||||
|
||||
|
@ -125,8 +128,9 @@ class _InternalNoPendingPlatformMessagesCondition implements WaitCondition {
|
|||
/// The [condition] argument must not be null.
|
||||
factory _InternalNoPendingPlatformMessagesCondition.deserialize(SerializableWaitCondition condition) {
|
||||
assert(condition != null);
|
||||
if (condition.conditionName != 'NoPendingPlatformMessagesCondition')
|
||||
if (condition.conditionName != 'NoPendingPlatformMessagesCondition') {
|
||||
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
|
||||
}
|
||||
return const _InternalNoPendingPlatformMessagesCondition();
|
||||
}
|
||||
|
||||
|
@ -161,8 +165,9 @@ class _InternalCombinedCondition implements WaitCondition {
|
|||
/// The [condition] argument must not be null.
|
||||
factory _InternalCombinedCondition.deserialize(SerializableWaitCondition condition) {
|
||||
assert(condition != null);
|
||||
if (condition.conditionName != 'CombinedCondition')
|
||||
if (condition.conditionName != 'CombinedCondition') {
|
||||
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
|
||||
}
|
||||
final CombinedCondition combinedCondition = condition as CombinedCondition;
|
||||
final List<WaitCondition> conditions = combinedCondition.conditions.map(deserializeCondition).toList();
|
||||
return _InternalCombinedCondition(conditions);
|
||||
|
|
|
@ -314,8 +314,9 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
|
|||
suffix: 'flutter_goldens_presubmit.',
|
||||
);
|
||||
|
||||
if (!baseDirectory.existsSync())
|
||||
if (!baseDirectory.existsSync()) {
|
||||
baseDirectory.createSync(recursive: true);
|
||||
}
|
||||
|
||||
goldens ??= SkiaGoldClient(baseDirectory);
|
||||
|
||||
|
@ -535,8 +536,9 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
|
|||
goldenBytes,
|
||||
);
|
||||
|
||||
if (result.passed)
|
||||
if (result.passed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final String error = await generateFailureOutput(result, golden, basedir);
|
||||
throw FlutterError(error);
|
||||
|
|
|
@ -83,8 +83,9 @@ class SkiaGoldClient {
|
|||
/// Used by the [FlutterPostSubmitFileComparator] and the
|
||||
/// [FlutterPreSubmitFileComparator].
|
||||
Future<void> auth() async {
|
||||
if (await clientIsAuthorized())
|
||||
if (await clientIsAuthorized()) {
|
||||
return;
|
||||
}
|
||||
final List<String> authCommand = <String>[
|
||||
_goldctl,
|
||||
'auth',
|
||||
|
@ -124,8 +125,9 @@ class SkiaGoldClient {
|
|||
/// [FlutterPostSubmitFileComparator].
|
||||
Future<void> imgtestInit() async {
|
||||
// This client has already been intialized
|
||||
if (_initialized)
|
||||
if (_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
final File keys = workDirectory.childFile('keys.json');
|
||||
final File failures = workDirectory.childFile('failures.json');
|
||||
|
@ -234,8 +236,9 @@ class SkiaGoldClient {
|
|||
/// [FlutterPreSubmitFileComparator].
|
||||
Future<void> tryjobInit() async {
|
||||
// This client has already been initialized
|
||||
if (_tryjobInitialized)
|
||||
if (_tryjobInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
final File keys = workDirectory.childFile('keys.json');
|
||||
final File failures = workDirectory.childFile('failures.json');
|
||||
|
@ -385,8 +388,9 @@ class SkiaGoldClient {
|
|||
final io.HttpClientResponse response = await request.close();
|
||||
rawResponse = await utf8.decodeStream(response);
|
||||
final dynamic jsonResponse = json.decode(rawResponse);
|
||||
if (jsonResponse is! Map<String, dynamic>)
|
||||
if (jsonResponse is! Map<String, dynamic>) {
|
||||
throw const FormatException('Skia gold expectations do not match expected format.');
|
||||
}
|
||||
expectation = jsonResponse['digest'] as String?;
|
||||
} on FormatException catch (error) {
|
||||
// Ideally we'd use something like package:test's printOnError, but best reliabilty
|
||||
|
|
|
@ -436,8 +436,9 @@ abstract class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|||
@override
|
||||
TimeOfDayFormat timeOfDayFormat({ bool alwaysUse24HourFormat = false }) {
|
||||
assert(alwaysUse24HourFormat != null);
|
||||
if (alwaysUse24HourFormat)
|
||||
if (alwaysUse24HourFormat) {
|
||||
return _get24HourVersionOf(timeOfDayFormatRaw);
|
||||
}
|
||||
return timeOfDayFormatRaw;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,9 @@ void encodeBundleTranslations(Map<String, dynamic> bundle) {
|
|||
for (final String key in bundle.keys) {
|
||||
// The ARB file resource "attributes" for foo are called @foo. Don't need
|
||||
// to encode them.
|
||||
if (key.startsWith('@'))
|
||||
if (key.startsWith('@')) {
|
||||
continue;
|
||||
}
|
||||
final String translation = bundle[key] as String;
|
||||
// Rewrite the string as a series of unicode characters in JSON format.
|
||||
// Like "\u0012\u0123\u1234".
|
||||
|
|
|
@ -1428,8 +1428,9 @@ void main() {
|
|||
Locale('de', 'DE'),
|
||||
],
|
||||
localeResolutionCallback: (Locale? locale, Iterable<Locale> supportedLocales) {
|
||||
if (locale == null)
|
||||
if (locale == null) {
|
||||
return const Locale('und', 'US');
|
||||
}
|
||||
return const Locale('en', 'US');
|
||||
},
|
||||
buildContent: (BuildContext context) {
|
||||
|
|
|
@ -173,11 +173,12 @@ mixin LocalComparisonOutput {
|
|||
/// Returns a [ComparisonResult] to describe the pixel differential of the
|
||||
/// [test] and [master] image bytes provided.
|
||||
Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async {
|
||||
if (identical(test, master))
|
||||
if (identical(test, master)) {
|
||||
return ComparisonResult(
|
||||
passed: true,
|
||||
diffPercent: 0.0,
|
||||
);
|
||||
}
|
||||
|
||||
if (test == null || master == null || test.isEmpty || master.isEmpty) {
|
||||
return ComparisonResult(
|
||||
|
|
|
@ -91,8 +91,9 @@ class MatchesGoldenFile extends AsyncMatcher {
|
|||
throw AssertionError('Future<Image> completed to null');
|
||||
}
|
||||
final ByteData? bytes = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
if (bytes == null)
|
||||
if (bytes == null) {
|
||||
return 'could not encode screenshot.';
|
||||
}
|
||||
if (autoUpdateGoldenFiles) {
|
||||
await goldenFileComparator.update(testNameUri, bytes.buffer.asUint8List());
|
||||
return null;
|
||||
|
|
|
@ -62,8 +62,9 @@ class _DepthFirstChildIterator implements Iterator<Element> {
|
|||
|
||||
@override
|
||||
bool moveNext() {
|
||||
if (_stack.isEmpty)
|
||||
if (_stack.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_current = _stack.removeLast();
|
||||
_fillChildren(_current);
|
||||
|
|
|
@ -500,8 +500,9 @@ class _RenderRootableRepaintBoundary extends RenderRepaintBoundary {
|
|||
|
||||
TransformLayer _rootLayer() {
|
||||
Layer layer = this.layer!;
|
||||
while (layer.parent != null)
|
||||
while (layer.parent != null) {
|
||||
layer = layer.parent!;
|
||||
}
|
||||
return layer as TransformLayer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,8 +179,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
_restorationManager = null;
|
||||
resetGestureBinding();
|
||||
testTextInput.reset();
|
||||
if (registerTestTextInput)
|
||||
if (registerTestTextInput) {
|
||||
_testTextInput.register();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -306,8 +307,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
///
|
||||
/// This is called automatically by [testWidgets].
|
||||
static TestWidgetsFlutterBinding ensureInitialized([@visibleForTesting Map<String, String>? environment]) {
|
||||
if (_instance != null)
|
||||
if (_instance != null) {
|
||||
return _instance!;
|
||||
}
|
||||
return binding.ensureInitialized(environment);
|
||||
}
|
||||
|
||||
|
@ -435,8 +437,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
Future<void> setSurfaceSize(Size? size) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
assert(inTest);
|
||||
if (_surfaceSize == size)
|
||||
if (_surfaceSize == size) {
|
||||
return;
|
||||
}
|
||||
_surfaceSize = size;
|
||||
handleMetricsChanged();
|
||||
});
|
||||
|
@ -663,8 +666,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
reportTestException(_pendingExceptionDetails!, testDescription);
|
||||
_pendingExceptionDetails = null;
|
||||
}
|
||||
if (!completer.isCompleted)
|
||||
if (!completer.isCompleted) {
|
||||
completer.complete();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -714,10 +718,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
// information to stack traces, in this case the Trace and Chain classes
|
||||
// can be present. Because these StackTrace implementations do not follow
|
||||
// the format the framework expects, we covert them to a vm trace here.
|
||||
if (stack is stack_trace.Trace)
|
||||
if (stack is stack_trace.Trace) {
|
||||
return stack.vmTrace;
|
||||
if (stack is stack_trace.Chain)
|
||||
}
|
||||
if (stack is stack_trace.Chain) {
|
||||
return stack.toTrace().vmTrace;
|
||||
}
|
||||
return stack;
|
||||
};
|
||||
final Completer<void> testCompleter = Completer<void>();
|
||||
|
@ -789,13 +795,15 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
return FlutterError.defaultStackFilter(frames.skip(stackLinesToOmit));
|
||||
},
|
||||
informationCollector: () sync* {
|
||||
if (stackLinesToOmit > 0)
|
||||
if (stackLinesToOmit > 0) {
|
||||
yield* omittedFrames;
|
||||
}
|
||||
if (showAppDumpInErrors) {
|
||||
yield DiagnosticsProperty<DiagnosticsNode>('At the time of the failure, the widget tree looked as follows', treeDump, linePrefix: '# ', style: DiagnosticsTreeStyle.flat);
|
||||
}
|
||||
if (description.isNotEmpty)
|
||||
if (description.isNotEmpty) {
|
||||
yield DiagnosticsProperty<String>('The test description was', description, style: DiagnosticsTreeStyle.errorProperty);
|
||||
}
|
||||
},
|
||||
));
|
||||
assert(_parentZone != null);
|
||||
|
@ -839,8 +847,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
// alone so that we don't cause more spurious errors.
|
||||
runApp(Container(key: UniqueKey(), child: _postTestMessage)); // Unmount any remaining widgets.
|
||||
await pump();
|
||||
if (registerTestTextInput)
|
||||
if (registerTestTextInput) {
|
||||
_testTextInput.unregister();
|
||||
}
|
||||
invariantTester();
|
||||
_verifyAutoUpdateGoldensUnset(autoUpdateGoldensBeforeTest && !isBrowser);
|
||||
_verifyReportTestExceptionUnset(reportTestExceptionBeforeTest);
|
||||
|
@ -995,8 +1004,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
/// will select the correct test binding implementation
|
||||
/// automatically.
|
||||
static AutomatedTestWidgetsFlutterBinding ensureInitialized() {
|
||||
if (AutomatedTestWidgetsFlutterBinding._instance == null)
|
||||
if (AutomatedTestWidgetsFlutterBinding._instance == null) {
|
||||
AutomatedTestWidgetsFlutterBinding();
|
||||
}
|
||||
return AutomatedTestWidgetsFlutterBinding.instance;
|
||||
}
|
||||
|
||||
|
@ -1033,8 +1043,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
return TestAsyncUtils.guard<void>(() {
|
||||
assert(inTest);
|
||||
assert(_clock != null);
|
||||
if (duration != null)
|
||||
if (duration != null) {
|
||||
_currentFakeAsync!.elapse(duration);
|
||||
}
|
||||
_phase = newPhase;
|
||||
if (hasScheduledFrame) {
|
||||
addTime(const Duration(milliseconds: 500));
|
||||
|
@ -1057,8 +1068,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
}) {
|
||||
assert(additionalTime != null);
|
||||
assert(() {
|
||||
if (_pendingAsyncTasks == null)
|
||||
if (_pendingAsyncTasks == null) {
|
||||
return true;
|
||||
}
|
||||
fail(
|
||||
'Reentrant call to runAsync() denied.\n'
|
||||
'runAsync() was called, then before its future completed, it '
|
||||
|
@ -1451,8 +1463,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
/// will select the correct test binding implementation
|
||||
/// automatically.
|
||||
static LiveTestWidgetsFlutterBinding ensureInitialized() {
|
||||
if (LiveTestWidgetsFlutterBinding._instance == null)
|
||||
if (LiveTestWidgetsFlutterBinding._instance == null) {
|
||||
LiveTestWidgetsFlutterBinding();
|
||||
}
|
||||
return LiveTestWidgetsFlutterBinding.instance;
|
||||
}
|
||||
|
||||
|
@ -1499,15 +1512,19 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
|
||||
@override
|
||||
void scheduleFrame() {
|
||||
if (framePolicy == LiveTestWidgetsFlutterBindingFramePolicy.benchmark)
|
||||
return; // In benchmark mode, don't actually schedule any engine frames.
|
||||
if (framePolicy == LiveTestWidgetsFlutterBindingFramePolicy.benchmark) {
|
||||
// In benchmark mode, don't actually schedule any engine frames.
|
||||
return;
|
||||
}
|
||||
super.scheduleFrame();
|
||||
}
|
||||
|
||||
@override
|
||||
void scheduleForcedFrame() {
|
||||
if (framePolicy == LiveTestWidgetsFlutterBindingFramePolicy.benchmark)
|
||||
return; // In benchmark mode, don't actually schedule any engine frames.
|
||||
if (framePolicy == LiveTestWidgetsFlutterBindingFramePolicy.benchmark) {
|
||||
// In benchmark mode, don't actually schedule any engine frames.
|
||||
return;
|
||||
}
|
||||
super.scheduleForcedFrame();
|
||||
}
|
||||
|
||||
|
@ -1538,8 +1555,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
@override
|
||||
void handleDrawFrame() {
|
||||
assert(_doDrawThisFrame != null);
|
||||
if (_doDrawThisFrame!)
|
||||
if (_doDrawThisFrame!) {
|
||||
super.handleDrawFrame();
|
||||
}
|
||||
_doDrawThisFrame = null;
|
||||
_viewNeedsPaint = false;
|
||||
_expectingFrameToReassemble = false;
|
||||
|
@ -1595,8 +1613,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
final _LiveTestPointerRecord? record = _liveTestRenderView._pointers[event.pointer];
|
||||
if (record != null) {
|
||||
record.position = event.position;
|
||||
if (!event.down)
|
||||
if (!event.down) {
|
||||
record.decay = _kPointerDecay;
|
||||
}
|
||||
_handleViewNeedsPaint();
|
||||
} else if (event.down) {
|
||||
_liveTestRenderView._pointers[event.pointer] = _LiveTestPointerRecord(
|
||||
|
@ -1630,8 +1649,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
case TestBindingEventSource.device:
|
||||
assert(hitTestResult != null || event is PointerAddedEvent || event is PointerRemovedEvent);
|
||||
assert(deviceEventDispatcher != null);
|
||||
if (hitTestResult != null)
|
||||
if (hitTestResult != null) {
|
||||
deviceEventDispatcher!.dispatchEvent(event, hitTestResult);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1667,8 +1687,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||
Duration additionalTime = const Duration(milliseconds: 1000),
|
||||
}) async {
|
||||
assert(() {
|
||||
if (!_runningAsyncTasks)
|
||||
if (!_runningAsyncTasks) {
|
||||
return true;
|
||||
}
|
||||
fail(
|
||||
'Reentrant call to runAsync() denied.\n'
|
||||
'runAsync() was called, then before its future completed, it '
|
||||
|
@ -1890,8 +1911,9 @@ class _LiveTestRenderView extends RenderView {
|
|||
final _LiveTestPointerRecord record = _pointers[pointer]!;
|
||||
paint.color = record.color.withOpacity(record.decay < 0 ? (record.decay / (_kPointerDecay - 1)) : 1.0);
|
||||
canvas.drawPath(path.shift(record.position), paint);
|
||||
if (record.decay < 0)
|
||||
if (record.decay < 0) {
|
||||
dirty = true;
|
||||
}
|
||||
record.decay += 1;
|
||||
}
|
||||
_pointers
|
||||
|
@ -1899,8 +1921,9 @@ class _LiveTestRenderView extends RenderView {
|
|||
.where((int pointer) => _pointers[pointer]!.decay == 0)
|
||||
.toList()
|
||||
.forEach(_pointers.remove);
|
||||
if (dirty && onNeedPaint != null)
|
||||
if (dirty && onNeedPaint != null) {
|
||||
scheduleMicrotask(onNeedPaint);
|
||||
}
|
||||
}
|
||||
_label?.paint(context.canvas, offset - const Offset(0.0, 10.0));
|
||||
}
|
||||
|
|
|
@ -182,8 +182,9 @@ abstract class WidgetController {
|
|||
|
||||
T _stateOf<T extends State>(Element element, Finder finder) {
|
||||
TestAsyncUtils.guardSync();
|
||||
if (element is StatefulElement)
|
||||
if (element is StatefulElement) {
|
||||
return element.state as T;
|
||||
}
|
||||
throw StateError('Widget of type ${element.widget.runtimeType}, with ${finder.description}, is not a StatefulWidget.');
|
||||
}
|
||||
|
||||
|
@ -1155,8 +1156,9 @@ abstract class WidgetController {
|
|||
/// Will throw a [StateError] if the finder returns more than one element or
|
||||
/// if no semantics are found or are not enabled.
|
||||
SemanticsNode getSemantics(Finder finder) {
|
||||
if (binding.pipelineOwner.semanticsOwner == null)
|
||||
if (binding.pipelineOwner.semanticsOwner == null) {
|
||||
throw StateError('Semantics are not enabled.');
|
||||
}
|
||||
final Iterable<Element> candidates = finder.evaluate();
|
||||
if (candidates.isEmpty) {
|
||||
throw StateError('Finder returned no matching elements.');
|
||||
|
@ -1171,8 +1173,9 @@ abstract class WidgetController {
|
|||
renderObject = renderObject.parent as RenderObject?;
|
||||
result = renderObject?.debugSemantics;
|
||||
}
|
||||
if (result == null)
|
||||
if (result == null) {
|
||||
throw StateError('No Semantics data found.');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1297,8 +1300,9 @@ class LiveWidgetController extends WidgetController {
|
|||
|
||||
@override
|
||||
Future<void> pump([Duration? duration]) async {
|
||||
if (duration != null)
|
||||
if (duration != null) {
|
||||
await Future<void>.delayed(duration);
|
||||
}
|
||||
binding.scheduleFrame();
|
||||
await binding.endOfFrame;
|
||||
}
|
||||
|
|
|
@ -30,8 +30,9 @@ class _WebKeyLocationPair {
|
|||
|
||||
String? _keyLabel(LogicalKeyboardKey key) {
|
||||
final String keyLabel = key.keyLabel;
|
||||
if (keyLabel.length == 1)
|
||||
if (keyLabel.length == 1) {
|
||||
return keyLabel.toLowerCase();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -700,8 +701,9 @@ class KeyEventSimulator {
|
|||
final Map<String, PhysicalKeyboardKey> result = <String, PhysicalKeyboardKey>{};
|
||||
for (final PhysicalKeyboardKey key in PhysicalKeyboardKey.knownPhysicalKeys) {
|
||||
final String? debugName = key.debugName;
|
||||
if (debugName != null)
|
||||
if (debugName != null) {
|
||||
result[debugName] = key;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
|
|
|
@ -435,10 +435,11 @@ class CommonFinders {
|
|||
/// If the `skipOffstage` argument is true (the default), then this skips
|
||||
/// nodes that are [Offstage] or that are from inactive [Route]s.
|
||||
Finder bySemanticsLabel(Pattern label, { bool skipOffstage = true }) {
|
||||
if (WidgetsBinding.instance.pipelineOwner.semanticsOwner == null)
|
||||
if (WidgetsBinding.instance.pipelineOwner.semanticsOwner == null) {
|
||||
throw StateError('Semantics are not enabled. '
|
||||
'Make sure to call tester.ensureSemantics() before using '
|
||||
'this finder, and call dispose on its return value after.');
|
||||
}
|
||||
return byElementPredicate(
|
||||
(Element element) {
|
||||
// Multiple elements can have the same renderObject - we want the "owner"
|
||||
|
@ -550,12 +551,15 @@ abstract class Finder {
|
|||
final String additional = skipOffstage ? ' (ignoring offstage widgets)' : '';
|
||||
final List<Element> widgets = evaluate().toList();
|
||||
final int count = widgets.length;
|
||||
if (count == 0)
|
||||
if (count == 0) {
|
||||
return 'zero widgets with $description$additional';
|
||||
if (count == 1)
|
||||
}
|
||||
if (count == 1) {
|
||||
return 'exactly one widget with $description$additional: ${widgets.single}';
|
||||
if (count < 4)
|
||||
}
|
||||
if (count < 4) {
|
||||
return '$count widgets with $description$additional: $widgets';
|
||||
}
|
||||
return '$count widgets with $description$additional: ${widgets[0]}, ${widgets[1]}, ${widgets[2]}, ...';
|
||||
}
|
||||
}
|
||||
|
@ -911,8 +915,9 @@ class _DescendantFinder extends Finder {
|
|||
|
||||
@override
|
||||
String get description {
|
||||
if (matchRoot)
|
||||
if (matchRoot) {
|
||||
return '${descendant.description} in the subtree(s) beginning with ${ancestor.description}';
|
||||
}
|
||||
return '${descendant.description} that has ancestor(s) with ${ancestor.description}';
|
||||
}
|
||||
|
||||
|
@ -927,8 +932,9 @@ class _DescendantFinder extends Finder {
|
|||
final List<Element> candidates = ancestorElements.expand<Element>(
|
||||
(Element element) => collectAllElementsFrom(element, skipOffstage: skipOffstage)
|
||||
).toSet().toList();
|
||||
if (matchRoot)
|
||||
if (matchRoot) {
|
||||
candidates.insertAll(0, ancestorElements);
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
}
|
||||
|
@ -942,8 +948,9 @@ class _AncestorFinder extends Finder {
|
|||
|
||||
@override
|
||||
String get description {
|
||||
if (matchRoot)
|
||||
if (matchRoot) {
|
||||
return 'ancestor ${ancestor.description} beginning with ${descendant.description}';
|
||||
}
|
||||
return '${ancestor.description} which is an ancestor of ${descendant.description}';
|
||||
}
|
||||
|
||||
|
@ -957,8 +964,9 @@ class _AncestorFinder extends Finder {
|
|||
final List<Element> candidates = <Element>[];
|
||||
for (final Element root in descendant.evaluate()) {
|
||||
final List<Element> ancestors = <Element>[];
|
||||
if (matchRoot)
|
||||
if (matchRoot) {
|
||||
ancestors.add(root);
|
||||
}
|
||||
root.visitAncestorElements((Element element) {
|
||||
ancestors.add(element);
|
||||
return true;
|
||||
|
|
|
@ -86,8 +86,9 @@ abstract class GoldenFileComparator {
|
|||
/// Version numbers are used in golden file tests for package:flutter. You can
|
||||
/// learn more about these tests [here](https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter).
|
||||
Uri getTestUri(Uri key, int? version) {
|
||||
if (version == null)
|
||||
if (version == null) {
|
||||
return key;
|
||||
}
|
||||
final String keyString = key.toString();
|
||||
final String extension = path.extension(keyString);
|
||||
return Uri.parse('${keyString.split(extension).join()}.$version$extension');
|
||||
|
@ -193,8 +194,9 @@ abstract class WebGoldenComparator {
|
|||
/// Version numbers are used in golden file tests for package:flutter. You can
|
||||
/// learn more about these tests [here](https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter).
|
||||
Uri getTestUri(Uri key, int? version) {
|
||||
if (version == null)
|
||||
if (version == null) {
|
||||
return key;
|
||||
}
|
||||
final String keyString = key.toString();
|
||||
final String extension = path.extension(keyString);
|
||||
return Uri.parse('${keyString.split(extension).join()}.$version$extension');
|
||||
|
|
|
@ -632,11 +632,12 @@ Matcher matchesSemantics({
|
|||
if (hasSetTextAction) SemanticsAction.setText,
|
||||
];
|
||||
SemanticsHintOverrides? hintOverrides;
|
||||
if (onTapHint != null || onLongPressHint != null)
|
||||
if (onTapHint != null || onLongPressHint != null) {
|
||||
hintOverrides = SemanticsHintOverrides(
|
||||
onTapHint: onTapHint,
|
||||
onLongPressHint: onLongPressHint,
|
||||
);
|
||||
}
|
||||
|
||||
return _MatchesSemanticsData(
|
||||
label: label,
|
||||
|
@ -712,16 +713,20 @@ class _FindsWidgetMatcher extends Matcher {
|
|||
int count = 0;
|
||||
final Iterator<Element> iterator = finder.evaluate().iterator;
|
||||
if (min != null) {
|
||||
while (count < min! && iterator.moveNext())
|
||||
while (count < min! && iterator.moveNext()) {
|
||||
count += 1;
|
||||
if (count < min!)
|
||||
}
|
||||
if (count < min!) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (max != null) {
|
||||
while (count <= max! && iterator.moveNext())
|
||||
while (count <= max! && iterator.moveNext()) {
|
||||
count += 1;
|
||||
if (count > max!)
|
||||
}
|
||||
if (count > max!) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -730,20 +735,24 @@ class _FindsWidgetMatcher extends Matcher {
|
|||
Description describe(Description description) {
|
||||
assert(min != null || max != null);
|
||||
if (min == max) {
|
||||
if (min == 1)
|
||||
if (min == 1) {
|
||||
return description.add('exactly one matching node in the widget tree');
|
||||
}
|
||||
return description.add('exactly $min matching nodes in the widget tree');
|
||||
}
|
||||
if (min == null) {
|
||||
if (max == 0)
|
||||
if (max == 0) {
|
||||
return description.add('no matching nodes in the widget tree');
|
||||
if (max == 1)
|
||||
}
|
||||
if (max == 1) {
|
||||
return description.add('at most one matching node in the widget tree');
|
||||
}
|
||||
return description.add('at most $max matching nodes in the widget tree');
|
||||
}
|
||||
if (max == null) {
|
||||
if (min == 1)
|
||||
if (min == 1) {
|
||||
return description.add('at least one matching node in the widget tree');
|
||||
}
|
||||
return description.add('at least $min matching nodes in the widget tree');
|
||||
}
|
||||
return description.add('between $min and $max matching nodes in the widget tree (inclusive)');
|
||||
|
@ -760,17 +769,20 @@ class _FindsWidgetMatcher extends Matcher {
|
|||
final int count = finder.evaluate().length;
|
||||
if (count == 0) {
|
||||
assert(min != null && min! > 0);
|
||||
if (min == 1 && max == 1)
|
||||
if (min == 1 && max == 1) {
|
||||
return mismatchDescription.add('means none were found but one was expected');
|
||||
}
|
||||
return mismatchDescription.add('means none were found but some were expected');
|
||||
}
|
||||
if (max == 0) {
|
||||
if (count == 1)
|
||||
if (count == 1) {
|
||||
return mismatchDescription.add('means one was found but none were expected');
|
||||
}
|
||||
return mismatchDescription.add('means some were found but none were expected');
|
||||
}
|
||||
if (min != null && count < min!)
|
||||
if (min != null && count < min!) {
|
||||
return mismatchDescription.add('is not enough');
|
||||
}
|
||||
assert(max != null && count > min!);
|
||||
return mismatchDescription.add('is too many');
|
||||
}
|
||||
|
@ -778,8 +790,9 @@ class _FindsWidgetMatcher extends Matcher {
|
|||
|
||||
bool _hasAncestorMatching(Finder finder, bool Function(Widget widget) predicate) {
|
||||
final Iterable<Element> nodes = finder.evaluate();
|
||||
if (nodes.length != 1)
|
||||
if (nodes.length != 1) {
|
||||
return false;
|
||||
}
|
||||
bool result = false;
|
||||
nodes.single.visitAncestorElements((Element ancestor) {
|
||||
if (predicate(ancestor.widget)) {
|
||||
|
@ -801,8 +814,9 @@ class _IsOffstage extends Matcher {
|
|||
@override
|
||||
bool matches(covariant Finder finder, Map<dynamic, dynamic> matchState) {
|
||||
return _hasAncestorMatching(finder, (Widget widget) {
|
||||
if (widget is Offstage)
|
||||
if (widget is Offstage) {
|
||||
return widget.offstage;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
@ -817,8 +831,9 @@ class _IsOnstage extends Matcher {
|
|||
@override
|
||||
bool matches(covariant Finder finder, Map<dynamic, dynamic> matchState) {
|
||||
final Iterable<Element> nodes = finder.evaluate();
|
||||
if (nodes.length != 1)
|
||||
if (nodes.length != 1) {
|
||||
return false;
|
||||
}
|
||||
bool result = true;
|
||||
nodes.single.visitAncestorElements((Element ancestor) {
|
||||
final Widget widget = ancestor.widget;
|
||||
|
@ -940,8 +955,9 @@ bool _isVerticalLine(int c) {
|
|||
bool _isAllTreeConnectorCharacters(String line) {
|
||||
for (int i = 0; i < line.length; ++i) {
|
||||
final int c = line.codeUnitAt(i);
|
||||
if (!_isWhitespace(c) && !_isVerticalLine(c))
|
||||
if (!_isWhitespace(c) && !_isVerticalLine(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -963,27 +979,33 @@ class _HasGoodToStringDeep extends Matcher {
|
|||
issues.add('Not terminated with a line break.');
|
||||
}
|
||||
|
||||
if (description.trim() != description)
|
||||
if (description.trim() != description) {
|
||||
issues.add('Has trailing whitespace.');
|
||||
}
|
||||
|
||||
final List<String> lines = description.split('\n');
|
||||
if (lines.length < 2)
|
||||
if (lines.length < 2) {
|
||||
issues.add('Does not have multiple lines.');
|
||||
}
|
||||
|
||||
if (description.contains('Instance of '))
|
||||
if (description.contains('Instance of ')) {
|
||||
issues.add('Contains text "Instance of ".');
|
||||
}
|
||||
|
||||
for (int i = 0; i < lines.length; ++i) {
|
||||
final String line = lines[i];
|
||||
if (line.isEmpty)
|
||||
if (line.isEmpty) {
|
||||
issues.add('Line ${i+1} is empty.');
|
||||
}
|
||||
|
||||
if (line.trimRight() != line)
|
||||
if (line.trimRight() != line) {
|
||||
issues.add('Line ${i+1} has trailing whitespace.');
|
||||
}
|
||||
}
|
||||
|
||||
if (_isAllTreeConnectorCharacters(lines.last))
|
||||
if (_isAllTreeConnectorCharacters(lines.last)) {
|
||||
issues.add('Last line is all tree connector characters.');
|
||||
}
|
||||
|
||||
// If a toStringDeep method doesn't properly handle nested values that
|
||||
// contain line breaks it can fail to add the required prefixes to all
|
||||
|
@ -1000,12 +1022,14 @@ class _HasGoodToStringDeep extends Matcher {
|
|||
0, descriptionWithPrefixes.length - 1);
|
||||
}
|
||||
final List<String> linesWithPrefixes = descriptionWithPrefixes.split('\n');
|
||||
if (!linesWithPrefixes.first.startsWith(prefixLineOne))
|
||||
if (!linesWithPrefixes.first.startsWith(prefixLineOne)) {
|
||||
prefixIssues.add('First line does not contain expected prefix.');
|
||||
}
|
||||
|
||||
for (int i = 1; i < linesWithPrefixes.length; ++i) {
|
||||
if (!linesWithPrefixes[i].startsWith(prefixOtherLines))
|
||||
if (!linesWithPrefixes[i].startsWith(prefixOtherLines)) {
|
||||
prefixIssues.add('Line ${i+1} does not contain the expected prefix.');
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuffer errorDescription = StringBuffer();
|
||||
|
@ -1180,10 +1204,12 @@ class _IsWithinDistance<T> extends Matcher {
|
|||
|
||||
@override
|
||||
bool matches(dynamic object, Map<dynamic, dynamic> matchState) {
|
||||
if (object is! T)
|
||||
if (object is! T) {
|
||||
return false;
|
||||
if (object == value)
|
||||
}
|
||||
if (object == value) {
|
||||
return true;
|
||||
}
|
||||
final num distance = distanceFunction(object, value);
|
||||
if (distance < 0) {
|
||||
throw ArgumentError(
|
||||
|
@ -1220,10 +1246,12 @@ class _MoreOrLessEquals extends Matcher {
|
|||
|
||||
@override
|
||||
bool matches(dynamic object, Map<dynamic, dynamic> matchState) {
|
||||
if (object is! double)
|
||||
if (object is! double) {
|
||||
return false;
|
||||
if (object == value)
|
||||
}
|
||||
if (object == value) {
|
||||
return true;
|
||||
}
|
||||
return (object - value).abs() <= epsilon;
|
||||
}
|
||||
|
||||
|
@ -1245,39 +1273,48 @@ class _IsMethodCall extends Matcher {
|
|||
|
||||
@override
|
||||
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
|
||||
if (item is! MethodCall)
|
||||
if (item is! MethodCall) {
|
||||
return false;
|
||||
if (item.method != name)
|
||||
}
|
||||
if (item.method != name) {
|
||||
return false;
|
||||
}
|
||||
return _deepEquals(item.arguments, arguments);
|
||||
}
|
||||
|
||||
bool _deepEquals(dynamic a, dynamic b) {
|
||||
if (a == b)
|
||||
if (a == b) {
|
||||
return true;
|
||||
if (a is List)
|
||||
}
|
||||
if (a is List) {
|
||||
return b is List && _deepEqualsList(a, b);
|
||||
if (a is Map)
|
||||
}
|
||||
if (a is Map) {
|
||||
return b is Map && _deepEqualsMap(a, b);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _deepEqualsList(List<dynamic> a, List<dynamic> b) {
|
||||
if (a.length != b.length)
|
||||
if (a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (!_deepEquals(a[i], b[i]))
|
||||
if (!_deepEquals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _deepEqualsMap(Map<dynamic, dynamic> a, Map<dynamic, dynamic> b) {
|
||||
if (a.length != b.length)
|
||||
if (a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for (final dynamic key in a.keys) {
|
||||
if (!b.containsKey(key) || !_deepEquals(a[key], b[key]))
|
||||
if (!b.containsKey(key) || !_deepEquals(a[key], b[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1383,8 +1420,9 @@ class _MatchAnythingExceptClip extends _FailWithDescriptionMatcher {
|
|||
@override
|
||||
bool matches(covariant Finder finder, Map<dynamic, dynamic> matchState) {
|
||||
final Iterable<Element> nodes = finder.evaluate();
|
||||
if (nodes.length != 1)
|
||||
if (nodes.length != 1) {
|
||||
return failWithDescription(matchState, 'did not have a exactly one child element');
|
||||
}
|
||||
final RenderObject renderObject = nodes.single.renderObject!;
|
||||
|
||||
switch (renderObject.runtimeType) {
|
||||
|
@ -1413,15 +1451,18 @@ abstract class _MatchRenderObject<M extends RenderObject, T extends RenderObject
|
|||
@override
|
||||
bool matches(covariant Finder finder, Map<dynamic, dynamic> matchState) {
|
||||
final Iterable<Element> nodes = finder.evaluate();
|
||||
if (nodes.length != 1)
|
||||
if (nodes.length != 1) {
|
||||
return failWithDescription(matchState, 'did not have a exactly one child element');
|
||||
}
|
||||
final RenderObject renderObject = nodes.single.renderObject!;
|
||||
|
||||
if (renderObject.runtimeType == T)
|
||||
if (renderObject.runtimeType == T) {
|
||||
return renderObjectMatchesT(matchState, renderObject as T);
|
||||
}
|
||||
|
||||
if (renderObject.runtimeType == M)
|
||||
if (renderObject.runtimeType == M) {
|
||||
return renderObjectMatchesM(matchState, renderObject as M);
|
||||
}
|
||||
|
||||
return failWithDescription(matchState, 'had a root render object of type: ${renderObject.runtimeType}');
|
||||
}
|
||||
|
@ -1440,26 +1481,31 @@ class _RendersOnPhysicalModel extends _MatchRenderObject<RenderPhysicalShape, Re
|
|||
|
||||
@override
|
||||
bool renderObjectMatchesT(Map<dynamic, dynamic> matchState, RenderPhysicalModel renderObject) {
|
||||
if (shape != null && renderObject.shape != shape)
|
||||
if (shape != null && renderObject.shape != shape) {
|
||||
return failWithDescription(matchState, 'had shape: ${renderObject.shape}');
|
||||
}
|
||||
|
||||
if (borderRadius != null && renderObject.borderRadius != borderRadius)
|
||||
if (borderRadius != null && renderObject.borderRadius != borderRadius) {
|
||||
return failWithDescription(matchState, 'had borderRadius: ${renderObject.borderRadius}');
|
||||
}
|
||||
|
||||
if (elevation != null && renderObject.elevation != elevation)
|
||||
if (elevation != null && renderObject.elevation != elevation) {
|
||||
return failWithDescription(matchState, 'had elevation: ${renderObject.elevation}');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderPhysicalShape renderObject) {
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper) {
|
||||
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
|
||||
}
|
||||
final ShapeBorderClipper shapeClipper = renderObject.clipper! as ShapeBorderClipper;
|
||||
|
||||
if (borderRadius != null && !assertRoundedRectangle(shapeClipper, borderRadius!, matchState))
|
||||
if (borderRadius != null && !assertRoundedRectangle(shapeClipper, borderRadius!, matchState)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
borderRadius == null &&
|
||||
|
@ -1477,36 +1523,43 @@ class _RendersOnPhysicalModel extends _MatchRenderObject<RenderPhysicalShape, Re
|
|||
return false;
|
||||
}
|
||||
|
||||
if (elevation != null && renderObject.elevation != elevation)
|
||||
if (elevation != null && renderObject.elevation != elevation) {
|
||||
return failWithDescription(matchState, 'had elevation: ${renderObject.elevation}');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool assertRoundedRectangle(ShapeBorderClipper shapeClipper, BorderRadius borderRadius, Map<dynamic, dynamic> matchState) {
|
||||
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder)
|
||||
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder) {
|
||||
return failWithDescription(matchState, 'had shape border: ${shapeClipper.shape}');
|
||||
}
|
||||
final RoundedRectangleBorder border = shapeClipper.shape as RoundedRectangleBorder;
|
||||
if (border.borderRadius != borderRadius)
|
||||
if (border.borderRadius != borderRadius) {
|
||||
return failWithDescription(matchState, 'had borderRadius: ${border.borderRadius}');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool assertCircle(ShapeBorderClipper shapeClipper, Map<dynamic, dynamic> matchState) {
|
||||
if (shapeClipper.shape.runtimeType != CircleBorder)
|
||||
if (shapeClipper.shape.runtimeType != CircleBorder) {
|
||||
return failWithDescription(matchState, 'had shape border: ${shapeClipper.shape}');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Description describe(Description description) {
|
||||
description.add('renders on a physical model');
|
||||
if (shape != null)
|
||||
if (shape != null) {
|
||||
description.add(' with shape $shape');
|
||||
if (borderRadius != null)
|
||||
}
|
||||
if (borderRadius != null) {
|
||||
description.add(' with borderRadius $borderRadius');
|
||||
if (elevation != null)
|
||||
}
|
||||
if (elevation != null) {
|
||||
description.add(' with elevation $elevation');
|
||||
}
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
@ -1522,15 +1575,18 @@ class _RendersOnPhysicalShape extends _MatchRenderObject<RenderPhysicalShape, Re
|
|||
|
||||
@override
|
||||
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderPhysicalShape renderObject) {
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper) {
|
||||
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
|
||||
}
|
||||
final ShapeBorderClipper shapeClipper = renderObject.clipper! as ShapeBorderClipper;
|
||||
|
||||
if (shapeClipper.shape != shape)
|
||||
if (shapeClipper.shape != shape) {
|
||||
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
|
||||
}
|
||||
|
||||
if (elevation != null && renderObject.elevation != elevation)
|
||||
if (elevation != null && renderObject.elevation != elevation) {
|
||||
return failWithDescription(matchState, 'had elevation: ${renderObject.elevation}');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1543,8 +1599,9 @@ class _RendersOnPhysicalShape extends _MatchRenderObject<RenderPhysicalShape, Re
|
|||
@override
|
||||
Description describe(Description description) {
|
||||
description.add('renders on a physical model with shape $shape');
|
||||
if (elevation != null)
|
||||
if (elevation != null) {
|
||||
description.add(' with elevation $elevation');
|
||||
}
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
@ -1554,21 +1611,25 @@ class _ClipsWithBoundingRect extends _MatchRenderObject<RenderClipPath, RenderCl
|
|||
|
||||
@override
|
||||
bool renderObjectMatchesT(Map<dynamic, dynamic> matchState, RenderClipRect renderObject) {
|
||||
if (renderObject.clipper != null)
|
||||
if (renderObject.clipper != null) {
|
||||
return failWithDescription(matchState, 'had a non null clipper ${renderObject.clipper}');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderClipPath renderObject) {
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper) {
|
||||
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
|
||||
}
|
||||
final ShapeBorderClipper shapeClipper = renderObject.clipper! as ShapeBorderClipper;
|
||||
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder)
|
||||
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder) {
|
||||
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
|
||||
}
|
||||
final RoundedRectangleBorder border = shapeClipper.shape as RoundedRectangleBorder;
|
||||
if (border.borderRadius != BorderRadius.zero)
|
||||
if (border.borderRadius != BorderRadius.zero) {
|
||||
return failWithDescription(matchState, 'borderRadius was: ${border.borderRadius}');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1585,25 +1646,30 @@ class _ClipsWithBoundingRRect extends _MatchRenderObject<RenderClipPath, RenderC
|
|||
|
||||
@override
|
||||
bool renderObjectMatchesT(Map<dynamic, dynamic> matchState, RenderClipRRect renderObject) {
|
||||
if (renderObject.clipper != null)
|
||||
if (renderObject.clipper != null) {
|
||||
return failWithDescription(matchState, 'had a non null clipper ${renderObject.clipper}');
|
||||
}
|
||||
|
||||
if (renderObject.borderRadius != borderRadius)
|
||||
if (renderObject.borderRadius != borderRadius) {
|
||||
return failWithDescription(matchState, 'had borderRadius: ${renderObject.borderRadius}');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderClipPath renderObject) {
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper) {
|
||||
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
|
||||
}
|
||||
final ShapeBorderClipper shapeClipper = renderObject.clipper! as ShapeBorderClipper;
|
||||
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder)
|
||||
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder) {
|
||||
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
|
||||
}
|
||||
final RoundedRectangleBorder border = shapeClipper.shape as RoundedRectangleBorder;
|
||||
if (border.borderRadius != borderRadius)
|
||||
if (border.borderRadius != borderRadius) {
|
||||
return failWithDescription(matchState, 'had borderRadius: ${border.borderRadius}');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1619,11 +1685,13 @@ class _ClipsWithShapeBorder extends _MatchRenderObject<RenderClipPath, RenderCli
|
|||
|
||||
@override
|
||||
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderClipPath renderObject) {
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
|
||||
if (renderObject.clipper.runtimeType != ShapeBorderClipper) {
|
||||
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
|
||||
}
|
||||
final ShapeBorderClipper shapeClipper = renderObject.clipper! as ShapeBorderClipper;
|
||||
if (shapeClipper.shape != shape)
|
||||
if (shapeClipper.shape != shape) {
|
||||
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1665,29 +1733,33 @@ class _CoversSameAreaAs extends Matcher {
|
|||
j * (areaToCompare.height / sampleSize),
|
||||
);
|
||||
|
||||
if (!_samplePoint(matchState, actualPath, offset))
|
||||
if (!_samplePoint(matchState, actualPath, offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Offset noise = Offset(
|
||||
maxHorizontalNoise * random.nextDouble(),
|
||||
maxVerticalNoise * random.nextDouble(),
|
||||
);
|
||||
|
||||
if (!_samplePoint(matchState, actualPath, offset + noise))
|
||||
if (!_samplePoint(matchState, actualPath, offset + noise)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _samplePoint(Map<dynamic, dynamic> matchState, Path actualPath, Offset offset) {
|
||||
if (expectedPath.contains(offset) == actualPath.contains(offset))
|
||||
if (expectedPath.contains(offset) == actualPath.contains(offset)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actualPath.contains(offset))
|
||||
if (actualPath.contains(offset)) {
|
||||
return failWithDescription(matchState, '$offset is contained in the actual path but not in the expected path');
|
||||
else
|
||||
} else {
|
||||
return failWithDescription(matchState, '$offset is contained in the expected path but not in the actual path');
|
||||
}
|
||||
}
|
||||
|
||||
bool failWithDescription(Map<dynamic, dynamic> matchState, String description) {
|
||||
|
@ -1719,8 +1791,9 @@ class _ColorMatcher extends Matcher {
|
|||
|
||||
@override
|
||||
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
|
||||
if (item is Color)
|
||||
if (item is Color) {
|
||||
return item == targetColor || item.value == targetColor.value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1769,15 +1842,18 @@ class _MatchesReferenceImage extends AsyncMatcher {
|
|||
return binding.runAsync<String?>(() async {
|
||||
final ui.Image image = await imageFuture;
|
||||
final ByteData? bytes = await image.toByteData();
|
||||
if (bytes == null)
|
||||
if (bytes == null) {
|
||||
return 'could not be encoded.';
|
||||
}
|
||||
|
||||
final ByteData? referenceBytes = await referenceImage.toByteData();
|
||||
if (referenceBytes == null)
|
||||
if (referenceBytes == null) {
|
||||
return 'could not have its reference image encoded.';
|
||||
}
|
||||
|
||||
if (referenceImage.height != image.height || referenceImage.width != image.width)
|
||||
if (referenceImage.height != image.height || referenceImage.width != image.width) {
|
||||
return 'does not match as width or height do not match. $image != $referenceImage';
|
||||
}
|
||||
|
||||
final int countDifferentPixels = _countDifferentPixels(
|
||||
Uint8List.view(bytes.buffer),
|
||||
|
@ -1849,63 +1925,88 @@ class _MatchesSemanticsData extends Matcher {
|
|||
@override
|
||||
Description describe(Description description) {
|
||||
description.add('has semantics');
|
||||
if (label != null)
|
||||
if (label != null) {
|
||||
description.add(' with label: $label');
|
||||
if (attributedLabel != null)
|
||||
}
|
||||
if (attributedLabel != null) {
|
||||
description.add(' with attributedLabel: $attributedLabel');
|
||||
if (value != null)
|
||||
}
|
||||
if (value != null) {
|
||||
description.add(' with value: $value');
|
||||
if (attributedValue != null)
|
||||
}
|
||||
if (attributedValue != null) {
|
||||
description.add(' with attributedValue: $attributedValue');
|
||||
if (hint != null)
|
||||
}
|
||||
if (hint != null) {
|
||||
description.add(' with hint: $hint');
|
||||
if (attributedHint != null)
|
||||
}
|
||||
if (attributedHint != null) {
|
||||
description.add(' with attributedHint: $attributedHint');
|
||||
if (increasedValue != null)
|
||||
}
|
||||
if (increasedValue != null) {
|
||||
description.add(' with increasedValue: $increasedValue ');
|
||||
if (attributedIncreasedValue != null)
|
||||
}
|
||||
if (attributedIncreasedValue != null) {
|
||||
description.add(' with attributedIncreasedValue: $attributedIncreasedValue');
|
||||
if (decreasedValue != null)
|
||||
}
|
||||
if (decreasedValue != null) {
|
||||
description.add(' with decreasedValue: $decreasedValue ');
|
||||
if (attributedDecreasedValue != null)
|
||||
}
|
||||
if (attributedDecreasedValue != null) {
|
||||
description.add(' with attributedDecreasedValue: $attributedDecreasedValue');
|
||||
if (tooltip != null)
|
||||
}
|
||||
if (tooltip != null) {
|
||||
description.add(' with tooltip: $tooltip');
|
||||
if (actions != null)
|
||||
}
|
||||
if (actions != null) {
|
||||
description.add(' with actions: ').addDescriptionOf(actions);
|
||||
if (flags != null)
|
||||
}
|
||||
if (flags != null) {
|
||||
description.add(' with flags: ').addDescriptionOf(flags);
|
||||
if (textDirection != null)
|
||||
}
|
||||
if (textDirection != null) {
|
||||
description.add(' with textDirection: $textDirection ');
|
||||
if (rect != null)
|
||||
}
|
||||
if (rect != null) {
|
||||
description.add(' with rect: $rect');
|
||||
if (size != null)
|
||||
}
|
||||
if (size != null) {
|
||||
description.add(' with size: $size');
|
||||
if (elevation != null)
|
||||
}
|
||||
if (elevation != null) {
|
||||
description.add(' with elevation: $elevation');
|
||||
if (thickness != null)
|
||||
}
|
||||
if (thickness != null) {
|
||||
description.add(' with thickness: $thickness');
|
||||
if (platformViewId != null)
|
||||
}
|
||||
if (platformViewId != null) {
|
||||
description.add(' with platformViewId: $platformViewId');
|
||||
if (maxValueLength != null)
|
||||
}
|
||||
if (maxValueLength != null) {
|
||||
description.add(' with maxValueLength: $maxValueLength');
|
||||
if (currentValueLength != null)
|
||||
}
|
||||
if (currentValueLength != null) {
|
||||
description.add(' with currentValueLength: $currentValueLength');
|
||||
if (customActions != null)
|
||||
}
|
||||
if (customActions != null) {
|
||||
description.add(' with custom actions: $customActions');
|
||||
if (hintOverrides != null)
|
||||
}
|
||||
if (hintOverrides != null) {
|
||||
description.add(' with custom hints: $hintOverrides');
|
||||
}
|
||||
if (children != null) {
|
||||
description.add(' with children:\n');
|
||||
for (final _MatchesSemanticsData child in children!.cast<_MatchesSemanticsData>())
|
||||
for (final _MatchesSemanticsData child in children!.cast<_MatchesSemanticsData>()) {
|
||||
child.describe(description);
|
||||
}
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
bool _stringAttributesEqual(List<StringAttribute> first, List<StringAttribute> second) {
|
||||
if (first.length != second.length)
|
||||
if (first.length != second.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < first.length; i++) {
|
||||
if (first[i] is SpellOutStringAttribute &&
|
||||
(second[i] is! SpellOutStringAttribute ||
|
||||
|
@ -1924,72 +2025,88 @@ class _MatchesSemanticsData extends Matcher {
|
|||
|
||||
@override
|
||||
bool matches(dynamic node, Map<dynamic, dynamic> matchState) {
|
||||
if (node == null)
|
||||
if (node == null) {
|
||||
return failWithDescription(matchState, 'No SemanticsData provided. '
|
||||
'Maybe you forgot to enable semantics?');
|
||||
}
|
||||
final SemanticsData data = node is SemanticsNode ? node.getSemanticsData() : (node as SemanticsData);
|
||||
if (label != null && label != data.label)
|
||||
if (label != null && label != data.label) {
|
||||
return failWithDescription(matchState, 'label was: ${data.label}');
|
||||
}
|
||||
if (attributedLabel != null &&
|
||||
(attributedLabel!.string != data.attributedLabel.string ||
|
||||
!_stringAttributesEqual(attributedLabel!.attributes, data.attributedLabel.attributes))) {
|
||||
return failWithDescription(
|
||||
matchState, 'attributedLabel was: ${data.attributedLabel}');
|
||||
}
|
||||
if (hint != null && hint != data.hint)
|
||||
if (hint != null && hint != data.hint) {
|
||||
return failWithDescription(matchState, 'hint was: ${data.hint}');
|
||||
}
|
||||
if (attributedHint != null &&
|
||||
(attributedHint!.string != data.attributedHint.string ||
|
||||
!_stringAttributesEqual(attributedHint!.attributes, data.attributedHint.attributes))) {
|
||||
return failWithDescription(
|
||||
matchState, 'attributedHint was: ${data.attributedHint}');
|
||||
}
|
||||
if (value != null && value != data.value)
|
||||
if (value != null && value != data.value) {
|
||||
return failWithDescription(matchState, 'value was: ${data.value}');
|
||||
}
|
||||
if (attributedValue != null &&
|
||||
(attributedValue!.string != data.attributedValue.string ||
|
||||
!_stringAttributesEqual(attributedValue!.attributes, data.attributedValue.attributes))) {
|
||||
return failWithDescription(
|
||||
matchState, 'attributedValue was: ${data.attributedValue}');
|
||||
}
|
||||
if (increasedValue != null && increasedValue != data.increasedValue)
|
||||
if (increasedValue != null && increasedValue != data.increasedValue) {
|
||||
return failWithDescription(matchState, 'increasedValue was: ${data.increasedValue}');
|
||||
}
|
||||
if (attributedIncreasedValue != null &&
|
||||
(attributedIncreasedValue!.string != data.attributedIncreasedValue.string ||
|
||||
!_stringAttributesEqual(attributedIncreasedValue!.attributes, data.attributedIncreasedValue.attributes))) {
|
||||
return failWithDescription(
|
||||
matchState, 'attributedIncreasedValue was: ${data.attributedIncreasedValue}');
|
||||
}
|
||||
if (decreasedValue != null && decreasedValue != data.decreasedValue)
|
||||
if (decreasedValue != null && decreasedValue != data.decreasedValue) {
|
||||
return failWithDescription(matchState, 'decreasedValue was: ${data.decreasedValue}');
|
||||
}
|
||||
if (attributedDecreasedValue != null &&
|
||||
(attributedDecreasedValue!.string != data.attributedDecreasedValue.string ||
|
||||
!_stringAttributesEqual(attributedDecreasedValue!.attributes, data.attributedDecreasedValue.attributes))) {
|
||||
return failWithDescription(
|
||||
matchState, 'attributedDecreasedValue was: ${data.attributedDecreasedValue}');
|
||||
}
|
||||
if (tooltip != null && tooltip != data.tooltip)
|
||||
if (tooltip != null && tooltip != data.tooltip) {
|
||||
return failWithDescription(matchState, 'tooltip was: ${data.tooltip}');
|
||||
if (textDirection != null && textDirection != data.textDirection)
|
||||
}
|
||||
if (textDirection != null && textDirection != data.textDirection) {
|
||||
return failWithDescription(matchState, 'textDirection was: $textDirection');
|
||||
if (rect != null && rect != data.rect)
|
||||
}
|
||||
if (rect != null && rect != data.rect) {
|
||||
return failWithDescription(matchState, 'rect was: ${data.rect}');
|
||||
if (size != null && size != data.rect.size)
|
||||
}
|
||||
if (size != null && size != data.rect.size) {
|
||||
return failWithDescription(matchState, 'size was: ${data.rect.size}');
|
||||
if (elevation != null && elevation != data.elevation)
|
||||
}
|
||||
if (elevation != null && elevation != data.elevation) {
|
||||
return failWithDescription(matchState, 'elevation was: ${data.elevation}');
|
||||
if (thickness != null && thickness != data.thickness)
|
||||
}
|
||||
if (thickness != null && thickness != data.thickness) {
|
||||
return failWithDescription(matchState, 'thickness was: ${data.thickness}');
|
||||
if (platformViewId != null && platformViewId != data.platformViewId)
|
||||
}
|
||||
if (platformViewId != null && platformViewId != data.platformViewId) {
|
||||
return failWithDescription(matchState, 'platformViewId was: ${data.platformViewId}');
|
||||
if (currentValueLength != null && currentValueLength != data.currentValueLength)
|
||||
}
|
||||
if (currentValueLength != null && currentValueLength != data.currentValueLength) {
|
||||
return failWithDescription(matchState, 'currentValueLength was: ${data.currentValueLength}');
|
||||
if (maxValueLength != null && maxValueLength != data.maxValueLength)
|
||||
}
|
||||
if (maxValueLength != null && maxValueLength != data.maxValueLength) {
|
||||
return failWithDescription(matchState, 'maxValueLength was: ${data.maxValueLength}');
|
||||
}
|
||||
if (actions != null) {
|
||||
int actionBits = 0;
|
||||
for (final SemanticsAction action in actions!)
|
||||
for (final SemanticsAction action in actions!) {
|
||||
actionBits |= action.index;
|
||||
}
|
||||
if (actionBits != data.actions) {
|
||||
final List<String> actionSummary = <String>[
|
||||
for (final SemanticsAction action in SemanticsAction.values.values)
|
||||
|
@ -2004,26 +2121,31 @@ class _MatchesSemanticsData extends Matcher {
|
|||
return CustomSemanticsAction.getAction(id)!;
|
||||
}).toList() ?? <CustomSemanticsAction>[];
|
||||
final List<CustomSemanticsAction> expectedCustomActions = customActions?.toList() ?? <CustomSemanticsAction>[];
|
||||
if (hintOverrides?.onTapHint != null)
|
||||
if (hintOverrides?.onTapHint != null) {
|
||||
expectedCustomActions.add(CustomSemanticsAction.overridingAction(hint: hintOverrides!.onTapHint!, action: SemanticsAction.tap));
|
||||
if (hintOverrides?.onLongPressHint != null)
|
||||
}
|
||||
if (hintOverrides?.onLongPressHint != null) {
|
||||
expectedCustomActions.add(CustomSemanticsAction.overridingAction(hint: hintOverrides!.onLongPressHint!, action: SemanticsAction.longPress));
|
||||
if (expectedCustomActions.length != providedCustomActions.length)
|
||||
}
|
||||
if (expectedCustomActions.length != providedCustomActions.length) {
|
||||
return failWithDescription(matchState, 'custom actions where: $providedCustomActions');
|
||||
}
|
||||
int sortActions(CustomSemanticsAction left, CustomSemanticsAction right) {
|
||||
return CustomSemanticsAction.getIdentifier(left) - CustomSemanticsAction.getIdentifier(right);
|
||||
}
|
||||
expectedCustomActions.sort(sortActions);
|
||||
providedCustomActions.sort(sortActions);
|
||||
for (int i = 0; i < expectedCustomActions.length; i++) {
|
||||
if (expectedCustomActions[i] != providedCustomActions[i])
|
||||
if (expectedCustomActions[i] != providedCustomActions[i]) {
|
||||
return failWithDescription(matchState, 'custom actions where: $providedCustomActions');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags != null) {
|
||||
int flagBits = 0;
|
||||
for (final SemanticsFlag flag in flags!)
|
||||
for (final SemanticsFlag flag in flags!) {
|
||||
flagBits |= flag.index;
|
||||
}
|
||||
if (flagBits != data.flags) {
|
||||
final List<String> flagSummary = <String>[
|
||||
for (final SemanticsFlag flag in SemanticsFlag.values.values)
|
||||
|
@ -2074,8 +2196,9 @@ class _MatchesAccessibilityGuideline extends AsyncMatcher {
|
|||
@override
|
||||
Future<String?> matchAsync(covariant WidgetTester tester) async {
|
||||
final Evaluation result = await guideline.evaluate(tester);
|
||||
if (result.passed)
|
||||
if (result.passed) {
|
||||
return null;
|
||||
}
|
||||
return result.reason;
|
||||
}
|
||||
}
|
||||
|
@ -2093,8 +2216,9 @@ class _DoesNotMatchAccessibilityGuideline extends AsyncMatcher {
|
|||
@override
|
||||
Future<String?> matchAsync(covariant WidgetTester tester) async {
|
||||
final Evaluation result = await guideline.evaluate(tester);
|
||||
if (result.passed)
|
||||
if (result.passed) {
|
||||
return 'Failed';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,8 +78,9 @@ class TestAsyncUtils {
|
|||
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
||||
while (_scopeStack.isNotEmpty) {
|
||||
closedScope = _scopeStack.removeLast();
|
||||
if (closedScope == scope)
|
||||
if (closedScope == scope) {
|
||||
break;
|
||||
}
|
||||
if (!leaked) {
|
||||
information.add(ErrorSummary('Asynchronous call to guarded function leaked.'));
|
||||
information.add(ErrorHint('You must use "await" with all Future-returning test APIs.'));
|
||||
|
@ -107,8 +108,9 @@ class TestAsyncUtils {
|
|||
}
|
||||
throw FlutterError.fromParts(information);
|
||||
}
|
||||
if (error != null)
|
||||
if (error != null) {
|
||||
return Future<T>.error(error! as Object, stack);
|
||||
}
|
||||
return Future<T>.value(resultValue);
|
||||
}
|
||||
return result.then<T>(
|
||||
|
@ -123,8 +125,9 @@ class TestAsyncUtils {
|
|||
static Zone? get _currentScopeZone {
|
||||
Zone? zone = Zone.current;
|
||||
while (zone != null) {
|
||||
if (zone[_scopeStack] == true)
|
||||
if (zone[_scopeStack] == true) {
|
||||
return zone;
|
||||
}
|
||||
zone = zone.parent;
|
||||
}
|
||||
return null;
|
||||
|
@ -174,8 +177,9 @@ class TestAsyncUtils {
|
|||
skipCount += 1;
|
||||
scope = candidateScope;
|
||||
if (skipCount >= _scopeStack.length) {
|
||||
if (zone == null)
|
||||
if (zone == null) {
|
||||
break;
|
||||
}
|
||||
// Some people have reported reaching this point, but it's not clear
|
||||
// why. For now, just silently return.
|
||||
// TODO(ianh): If we ever get a test case that shows how we reach
|
||||
|
|
|
@ -89,11 +89,13 @@ class TestDefaultBinaryMessenger extends BinaryMessenger {
|
|||
ui.PlatformMessageResponseCallback? callback,
|
||||
) {
|
||||
Future<ByteData?>? result;
|
||||
if (_inboundHandlers.containsKey(channel))
|
||||
if (_inboundHandlers.containsKey(channel)) {
|
||||
result = _inboundHandlers[channel]!(data);
|
||||
}
|
||||
result ??= Future<ByteData?>.value();
|
||||
if (callback != null)
|
||||
if (callback != null) {
|
||||
result = result.then((ByteData? result) { callback(result); return result; });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,9 @@ void _defaultTestExceptionReporter(FlutterErrorDetails errorDetails, String test
|
|||
// get the same effect here by calling that error handler directly or indeed just throwing.
|
||||
// However, we call registerException because that's the semantically correct thing...
|
||||
String additional = '';
|
||||
if (testDescription.isNotEmpty)
|
||||
if (testDescription.isNotEmpty) {
|
||||
additional = '\nThe test description was: $testDescription';
|
||||
}
|
||||
test_package.registerException('Test failed. See exception logs above.$additional', _emptyStackTrace);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,8 +98,9 @@ class TestPointer {
|
|||
int? buttons,
|
||||
}) {
|
||||
_location = newLocation;
|
||||
if (buttons != null)
|
||||
if (buttons != null) {
|
||||
_buttons = buttons;
|
||||
}
|
||||
switch (event.runtimeType) {
|
||||
case PointerDownEvent:
|
||||
assert(!isDown);
|
||||
|
@ -132,8 +133,9 @@ class TestPointer {
|
|||
assert(!isPanZoomActive);
|
||||
_isDown = true;
|
||||
_location = newLocation;
|
||||
if (buttons != null)
|
||||
if (buttons != null) {
|
||||
_buttons = buttons;
|
||||
}
|
||||
return PointerDownEvent(
|
||||
timeStamp: timeStamp,
|
||||
kind: kind,
|
||||
|
@ -167,8 +169,9 @@ class TestPointer {
|
|||
assert(!isPanZoomActive);
|
||||
final Offset delta = newLocation - location!;
|
||||
_location = newLocation;
|
||||
if (buttons != null)
|
||||
if (buttons != null) {
|
||||
_buttons = buttons;
|
||||
}
|
||||
return PointerMoveEvent(
|
||||
timeStamp: timeStamp,
|
||||
kind: kind,
|
||||
|
|
|
@ -69,8 +69,9 @@ E? _lastWhereOrNull<E>(Iterable<E> list, bool Function(E) test) {
|
|||
foundMatching = true;
|
||||
}
|
||||
}
|
||||
if (foundMatching)
|
||||
if (foundMatching) {
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -414,8 +415,9 @@ Future<void> benchmarkWidgets(
|
|||
bool semanticsEnabled = false,
|
||||
}) {
|
||||
assert(() {
|
||||
if (mayRunWithAsserts)
|
||||
if (mayRunWithAsserts) {
|
||||
return true;
|
||||
}
|
||||
debugPrint(kDebugWarning);
|
||||
return true;
|
||||
}());
|
||||
|
@ -499,8 +501,9 @@ Future<void> expectLater(
|
|||
/// `testWidgets`) can be used as the `vsync` for `AnimationController` objects.
|
||||
class WidgetTester extends WidgetController implements HitTestDispatcher, TickerProvider {
|
||||
WidgetTester._(super.binding) {
|
||||
if (binding is LiveTestWidgetsFlutterBinding)
|
||||
if (binding is LiveTestWidgetsFlutterBinding) {
|
||||
(binding as LiveTestWidgetsFlutterBinding).deviceEventDispatcher = this;
|
||||
}
|
||||
}
|
||||
|
||||
/// The description string of the test currently being run.
|
||||
|
@ -663,8 +666,9 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
|||
final DateTime endTime = binding.clock.fromNowBy(timeout);
|
||||
int count = 0;
|
||||
do {
|
||||
if (binding.clock.now().isAfter(endTime))
|
||||
if (binding.clock.now().isAfter(endTime)) {
|
||||
throw FlutterError('pumpAndSettle timed out');
|
||||
}
|
||||
await binding.pump(duration, phase);
|
||||
count += 1;
|
||||
} while (binding.hasScheduledFrame);
|
||||
|
@ -837,8 +841,9 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
|||
int totalNumber = 0;
|
||||
printToConsole('Some possible finders for the widgets at ${event.position}:');
|
||||
for (final Element element in candidates) {
|
||||
if (totalNumber > 13) // an arbitrary number of finders that feels useful without being overwhelming
|
||||
if (totalNumber > 13) {
|
||||
break;
|
||||
}
|
||||
totalNumber += 1; // optimistically assume we'll be able to describe it
|
||||
|
||||
final Widget widget = element.widget;
|
||||
|
@ -912,8 +917,9 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
|||
|
||||
totalNumber -= 1; // if we got here, we didn't actually find something to say about it
|
||||
}
|
||||
if (totalNumber == 0)
|
||||
if (totalNumber == 0) {
|
||||
printToConsole(' <could not come up with any unique finders>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -569,8 +569,9 @@ class FakeAccessibilityFeatures implements ui.AccessibilityFeatures {
|
|||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (other.runtimeType != runtimeType)
|
||||
if (other.runtimeType != runtimeType) {
|
||||
return false;
|
||||
}
|
||||
return other is FakeAccessibilityFeatures
|
||||
&& other.accessibleNavigation == accessibleNavigation
|
||||
&& other.invertColors == invertColors
|
||||
|
|
|
@ -416,12 +416,13 @@ void main() {
|
|||
|
||||
const String b = '$kSecondaryMouseButton';
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
expect(logs[i], 'down $b');
|
||||
else if (i != logs.length - 1)
|
||||
} else if (i != logs.length - 1) {
|
||||
expect(logs[i], 'move $b');
|
||||
else
|
||||
} else {
|
||||
expect(logs[i], 'up 0');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -472,12 +473,13 @@ void main() {
|
|||
|
||||
const String b = '$kSecondaryMouseButton';
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
expect(logs[i], 'down $b');
|
||||
else if (i != logs.length - 1)
|
||||
} else if (i != logs.length - 1) {
|
||||
expect(logs[i], 'move $b');
|
||||
else
|
||||
} else {
|
||||
expect(logs[i], 'up 0');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -503,12 +505,13 @@ void main() {
|
|||
|
||||
const String b = '$kSecondaryMouseButton';
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
expect(logs[i], 'down $b');
|
||||
else if (i != logs.length - 1)
|
||||
} else if (i != logs.length - 1) {
|
||||
expect(logs[i], 'move $b');
|
||||
else
|
||||
} else {
|
||||
expect(logs[i], 'up 0');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -535,12 +538,13 @@ void main() {
|
|||
|
||||
const String b = '$kSecondaryMouseButton';
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
expect(logs[i], 'down $b');
|
||||
else if (i != logs.length - 1)
|
||||
} else if (i != logs.length - 1) {
|
||||
expect(logs[i], 'move $b');
|
||||
else
|
||||
} else {
|
||||
expect(logs[i], 'up 0');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -599,12 +603,13 @@ void main() {
|
|||
|
||||
const String b = '$kSecondaryMouseButton';
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
expect(logs[i], 'down $b');
|
||||
else if (i != logs.length - 1)
|
||||
} else if (i != logs.length - 1) {
|
||||
expect(logs[i], 'move $b');
|
||||
else
|
||||
} else {
|
||||
expect(logs[i], 'up 0');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
@ -15,8 +15,9 @@ import 'package:flutter_test/flutter_test.dart';
|
|||
class _MockToStringDeep {
|
||||
_MockToStringDeep(String str) : _lines = <String>[] {
|
||||
final List<String> lines = str.split('\n');
|
||||
for (int i = 0; i < lines.length - 1; ++i)
|
||||
for (int i = 0; i < lines.length - 1; ++i) {
|
||||
_lines.add('${lines[i]}\n');
|
||||
}
|
||||
|
||||
// If the last line is empty, that really just means that the previous
|
||||
// line was terminated with a line break.
|
||||
|
@ -34,11 +35,13 @@ class _MockToStringDeep {
|
|||
|
||||
String toStringDeep({ String prefixLineOne = '', String prefixOtherLines = '' }) {
|
||||
final StringBuffer sb = StringBuffer();
|
||||
if (_lines.isNotEmpty)
|
||||
if (_lines.isNotEmpty) {
|
||||
sb.write('$prefixLineOne${_lines.first}');
|
||||
}
|
||||
|
||||
for (int i = 1; i < _lines.length; ++i)
|
||||
for (int i = 1; i < _lines.length; ++i) {
|
||||
sb.write('$prefixOtherLines${_lines[i]}');
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -560,12 +563,15 @@ void main() {
|
|||
int actions = 0;
|
||||
int flags = 0;
|
||||
const CustomSemanticsAction action = CustomSemanticsAction(label: 'test');
|
||||
for (final int index in SemanticsAction.values.keys)
|
||||
for (final int index in SemanticsAction.values.keys) {
|
||||
actions |= index;
|
||||
for (final int index in SemanticsFlag.values.keys)
|
||||
}
|
||||
for (final int index in SemanticsFlag.values.keys) {
|
||||
// TODO(mdebbar): Remove this if after https://github.com/flutter/engine/pull/9894
|
||||
if (SemanticsFlag.values[index] != SemanticsFlag.isMultiline)
|
||||
if (SemanticsFlag.values[index] != SemanticsFlag.isMultiline) {
|
||||
flags |= index;
|
||||
}
|
||||
}
|
||||
final SemanticsData data = SemanticsData(
|
||||
flags: flags,
|
||||
actions: actions,
|
||||
|
|
|
@ -158,10 +158,11 @@ class Registrar extends BinaryMessenger {
|
|||
|
||||
@override
|
||||
void setMessageHandler(String channel, MessageHandler? handler) {
|
||||
if (handler == null)
|
||||
if (handler == null) {
|
||||
_handlers.remove(channel);
|
||||
else
|
||||
} else {
|
||||
_handlers[channel] = handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,8 +154,9 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
|
|||
///
|
||||
/// * [WidgetsFlutterBinding.ensureInitialized], the equivalent in the widgets framework.
|
||||
static IntegrationTestWidgetsFlutterBinding ensureInitialized() {
|
||||
if (_instance == null)
|
||||
if (_instance == null) {
|
||||
IntegrationTestWidgetsFlutterBinding();
|
||||
}
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue