import 'package:flutter_test/flutter_test.dart'; import 'package:halkyon_ui/halkyon_ui.dart'; import 'package:material_ui/material_ui.dart'; void main() { /// A list of [lines] with a button that hides while reading onwards. Future show( WidgetTester tester, { int lines = 100, bool pinned = false, }) async { tester.view.physicalSize = const Size(400, 800); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget( MaterialApp( home: ScrollHidingFab( pinned: pinned, builder: (context, fab) => Scaffold( floatingActionButton: fab, body: ListView( children: [ for (var i = 0; i < lines; i++) SizedBox(height: 48, child: Text('Line $i')), ], ), ), fab: FloatingActionButton( tooltip: 'New studyset', onPressed: () {}, child: const Icon(Icons.add), ), ), ), ); } Finder fab() => find.byTooltip('New studyset').hitTestable(); testWidgets('hides while scrolling down and returns when scrolling up', ( tester, ) async { await show(tester); expect(fab(), findsOneWidget); await tester.drag(find.byType(ListView), const Offset(0, -300)); await tester.pumpAndSettle(); expect(fab(), findsNothing); await tester.drag(find.byType(ListView), const Offset(0, 100)); await tester.pumpAndSettle(); expect(fab(), findsOneWidget); }); testWidgets('stays when the list fits without scrolling', (tester) async { await show(tester, lines: 3); await tester.drag(find.byType(ListView), const Offset(0, -300)); await tester.pumpAndSettle(); expect(fab(), findsOneWidget); }); testWidgets('stays while pinned, as a field being written in', ( tester, ) async { await show(tester, pinned: true); await tester.drag(find.byType(ListView), const Offset(0, -300)); await tester.pumpAndSettle(); expect(fab(), findsOneWidget); }); }