Unverified Commit be2918ff authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Fix ImageStreamListener's hashCode & operator== (#33217)

I forgot to add `onChunk` to them in #33092
parent ef9866bf
......@@ -113,7 +113,7 @@ class ImageStreamListener {
final ImageErrorListener onError;
@override
int get hashCode => hashValues(onImage, onError);
int get hashCode => hashValues(onImage, onChunk, onError);
@override
bool operator ==(dynamic other) {
......@@ -121,6 +121,7 @@ class ImageStreamListener {
return false;
final ImageStreamListener typedOther = other;
return onImage == typedOther.onImage
&& onChunk == typedOther.onChunk
&& onError == typedOther.onError;
}
}
......
......@@ -9,6 +9,7 @@ import 'dart:ui';
import 'package:flutter/painting.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:flutter_test/flutter_test.dart';
import 'package:meta/meta.dart';
class FakeFrameInfo implements FrameInfo {
FakeFrameInfo(int width, int height, this._duration)
......@@ -606,6 +607,38 @@ void main() {
await tester.pump(const Duration(milliseconds: 200)); // emit 2nd frame.
});
testWidgets('ImageStreamListener hashCode and equals', (WidgetTester tester) {
void handleImage(ImageInfo image, bool synchronousCall) { }
void handleImageDifferently(ImageInfo image, bool synchronousCall) { }
void handleError(dynamic error, StackTrace stackTrace) { }
void handleChunk(ImageChunkEvent event) { }
void compare({
@required ImageListener onImage1,
@required ImageListener onImage2,
ImageChunkListener onChunk1,
ImageChunkListener onChunk2,
ImageErrorListener onError1,
ImageErrorListener onError2,
bool areEqual = true,
}) {
final ImageStreamListener l1 = ImageStreamListener(onImage1, onChunk: onChunk1, onError: onError1);
final ImageStreamListener l2 = ImageStreamListener(onImage2, onChunk: onChunk2, onError: onError2);
Matcher comparison(dynamic expected) => areEqual ? equals(expected) : isNot(equals(expected));
expect(l1, comparison(l2));
expect(l1.hashCode, comparison(l2.hashCode));
}
compare(onImage1: handleImage, onImage2: handleImage);
compare(onImage1: handleImage, onImage2: handleImageDifferently, areEqual: false);
compare(onImage1: handleImage, onChunk1: handleChunk, onImage2: handleImage, onChunk2: handleChunk);
compare(onImage1: handleImage, onChunk1: handleChunk, onError1: handleError, onImage2: handleImage, onChunk2: handleChunk, onError2: handleError);
compare(onImage1: handleImage, onChunk1: handleChunk, onImage2: handleImage, areEqual: false);
compare(onImage1: handleImage, onChunk1: handleChunk, onError1: handleError, onImage2: handleImage, areEqual: false);
compare(onImage1: handleImage, onChunk1: handleChunk, onError1: handleError, onImage2: handleImage, onChunk2: handleChunk, areEqual: false);
compare(onImage1: handleImage, onChunk1: handleChunk, onError1: handleError, onImage2: handleImage, onError2: handleError, areEqual: false);
});
// TODO(amirh): enable this once WidgetTester supports flushTimers.
// https://github.com/flutter/flutter/issues/30344
// testWidgets('remove and add listener before a delayed frame is scheduled', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment