Skip to content

Commit f66ffac

Browse files
committed
sticky_header test [nfc]: Generalize tap-logging from headers
1 parent 6ee204a commit f66ffac

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

test/widgets/sticky_header_test.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:math' as math;
22

33
import 'package:checks/checks.dart';
4+
import 'package:flutter/foundation.dart';
45
import 'package:flutter/gestures.dart';
56
import 'package:flutter/widgets.dart';
67
import 'package:flutter_test/flutter_test.dart';
@@ -304,10 +305,11 @@ Future<void> _checkSequence(
304305
// Check the header gets hit when it should, and not when it shouldn't.
305306
await tester.tapAt(headerInset(1));
306307
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>());
308310
await tester.tapAt(headerInset(extent - 1));
309311
await tester.tapAt(headerInset(extent - (expectedHeaderInsetExtent - 1)));
310-
check(_Header.takeTapCount()).equals(0);
312+
check(_TapLogged.takeTapLog()).isEmpty();
311313
}
312314

313315
Future<void> jumpAndCheck(double position) async {
@@ -354,28 +356,36 @@ Iterable<int> _itemIndexes(WidgetTester tester) {
354356
return tester.widgetList<_Item>(find.byType(_Item)).map((w) => w.index);
355357
}
356358

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 {
358369
const _Header(this.index, {required this.height});
359370

360371
final int index;
361372
final double height;
362373

363-
static int takeTapCount() {
364-
final result = _tapCount;
365-
_tapCount = 0;
366-
return result;
367-
}
368-
static int _tapCount = 0;
369-
370374
@override
371375
Widget build(BuildContext context) {
372376
return SizedBox(
373377
height: height,
374378
width: height, // TODO clean up
375379
child: GestureDetector(
376-
onTap: () => _tapCount++,
380+
onTap: () => _TapLogged._tapLog.add(this),
377381
child: Text("Header $index")));
378382
}
383+
384+
@override
385+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
386+
super.debugFillProperties(properties);
387+
properties.add(IntProperty('index', index));
388+
}
379389
}
380390

381391
class _Item extends StatelessWidget {

0 commit comments

Comments
 (0)