|
1 | 1 | import 'dart:math' as math;
|
2 | 2 |
|
3 | 3 | import 'package:checks/checks.dart';
|
| 4 | +import 'package:flutter/foundation.dart'; |
4 | 5 | import 'package:flutter/gestures.dart';
|
5 | 6 | import 'package:flutter/widgets.dart';
|
6 | 7 | import 'package:flutter_test/flutter_test.dart';
|
@@ -304,10 +305,11 @@ Future<void> _checkSequence(
|
304 | 305 | // Check the header gets hit when it should, and not when it shouldn't.
|
305 | 306 | await tester.tapAt(headerInset(1));
|
306 | 307 | await tester.tapAt(headerInset(expectedHeaderInsetExtent - 1));
|
307 |
| - check(_Header.takeTapCount()).equals(2); |
| 308 | + check(_TapLogged.takeTapLog())..length.equals(2) |
| 309 | + ..every((it) => it.isA<_Header>()); |
308 | 310 | await tester.tapAt(headerInset(extent - 1));
|
309 | 311 | await tester.tapAt(headerInset(extent - (expectedHeaderInsetExtent - 1)));
|
310 |
| - check(_Header.takeTapCount()).equals(0); |
| 312 | + check(_TapLogged.takeTapLog()).isEmpty(); |
311 | 313 | }
|
312 | 314 |
|
313 | 315 | Future<void> jumpAndCheck(double position) async {
|
@@ -354,28 +356,36 @@ Iterable<int> _itemIndexes(WidgetTester tester) {
|
354 | 356 | return tester.widgetList<_Item>(find.byType(_Item)).map((w) => w.index);
|
355 | 357 | }
|
356 | 358 |
|
357 |
| -class _Header extends StatelessWidget { |
| 359 | +sealed class _TapLogged { |
| 360 | + static List<_TapLogged> takeTapLog() { |
| 361 | + final result = _tapLog; |
| 362 | + _tapLog = []; |
| 363 | + return result; |
| 364 | + } |
| 365 | + static List<_TapLogged> _tapLog = []; |
| 366 | +} |
| 367 | + |
| 368 | +class _Header extends StatelessWidget implements _TapLogged { |
358 | 369 | const _Header(this.index, {required this.height});
|
359 | 370 |
|
360 | 371 | final int index;
|
361 | 372 | final double height;
|
362 | 373 |
|
363 |
| - static int takeTapCount() { |
364 |
| - final result = _tapCount; |
365 |
| - _tapCount = 0; |
366 |
| - return result; |
367 |
| - } |
368 |
| - static int _tapCount = 0; |
369 |
| - |
370 | 374 | @override
|
371 | 375 | Widget build(BuildContext context) {
|
372 | 376 | return SizedBox(
|
373 | 377 | height: height,
|
374 | 378 | width: height, // TODO clean up
|
375 | 379 | child: GestureDetector(
|
376 |
| - onTap: () => _tapCount++, |
| 380 | + onTap: () => _TapLogged._tapLog.add(this), |
377 | 381 | child: Text("Header $index")));
|
378 | 382 | }
|
| 383 | + |
| 384 | + @override |
| 385 | + void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
| 386 | + super.debugFillProperties(properties); |
| 387 | + properties.add(IntProperty('index', index)); |
| 388 | + } |
379 | 389 | }
|
380 | 390 |
|
381 | 391 | class _Item extends StatelessWidget {
|
|
0 commit comments