|
| 1 | +import 'dart:math'; |
| 2 | + |
1 | 3 | import 'package:flutter/material.dart'; |
2 | 4 | import 'package:meta/meta.dart'; |
3 | 5 | import '../../sentry_flutter.dart'; |
@@ -198,42 +200,31 @@ class SentryScreenshotWidgetStatus { |
198 | 200 |
|
199 | 201 | if (orientation != other.orientation) return false; |
200 | 202 |
|
201 | | - if (!_pixelRatioAlmostEqual( |
202 | | - pixelRatio, other.pixelRatio, _pixelRatioTolerance)) { |
203 | | - return false; |
204 | | - } |
| 203 | + final pr1 = pixelRatio?.roundToResolution(_pixelRatioTolerance); |
| 204 | + final pr2 = other.pixelRatio?.roundToResolution(_pixelRatioTolerance); |
| 205 | + if (pr1 != pr2) return false; |
205 | 206 |
|
206 | | - if (!_sizeAlmostEqual(size, other.size, _sizeTolerance)) { |
207 | | - return false; |
208 | | - } |
| 207 | + final w1 = size?.width.roundToResolution(_sizeTolerance); |
| 208 | + final h1 = size?.height.roundToResolution(_sizeTolerance); |
| 209 | + final w2 = other.size?.width.roundToResolution(_sizeTolerance); |
| 210 | + final h2 = other.size?.height.roundToResolution(_sizeTolerance); |
| 211 | + if (w1 != w2 || h1 != h2) return false; |
209 | 212 |
|
210 | 213 | return true; |
211 | 214 | } |
212 | 215 |
|
213 | 216 | @override |
214 | 217 | int get hashCode { |
215 | | - final prHash = _quantize(pixelRatio, _pixelRatioTolerance); |
216 | | - final wHash = _quantize(size?.width, _sizeTolerance); |
217 | | - final hHash = _quantize(size?.height, _sizeTolerance); |
218 | | - |
219 | | - return Object.hash(orientation, prHash, wHash, hHash); |
220 | | - } |
221 | | - |
222 | | - static bool _pixelRatioAlmostEqual(double? a, double? b, double tol) { |
223 | | - if (a == b) return true; |
224 | | - if (a == null || b == null) return false; |
225 | | - return (a - b).abs() <= tol; |
226 | | - } |
227 | | - |
228 | | - static bool _sizeAlmostEqual(Size? a, Size? b, double tol) { |
229 | | - if (a == b) return true; |
230 | | - if (a == null || b == null) return false; |
231 | | - return (a.width - b.width).abs() <= tol && |
232 | | - (a.height - b.height).abs() <= tol; |
| 218 | + final pr = pixelRatio?.roundToResolution(_pixelRatioTolerance); |
| 219 | + final w = size?.width.roundToResolution(_sizeTolerance); |
| 220 | + final h = size?.height.roundToResolution(_sizeTolerance); |
| 221 | + return Object.hash(orientation, pr, w, h); |
233 | 222 | } |
| 223 | +} |
234 | 224 |
|
235 | | - static int _quantize(double? value, double tol) { |
236 | | - if (value == null) return 0; |
237 | | - return (value / tol).round(); |
| 225 | +extension _RoundToTolerance on double { |
| 226 | + /// Rounds this value to the nearest multiple of [resolution]. |
| 227 | + double roundToResolution(double resolution) { |
| 228 | + return (this / resolution).round() * resolution; |
238 | 229 | } |
239 | 230 | } |
0 commit comments