From 766eda6bf6dfe58a598ba33ad37eea5ac69d09ec Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Mon, 2 Nov 2015 14:33:11 -0800 Subject: [PATCH] Restored BottomSheet dismiss tap --- .../lib/src/material/bottom_sheet.dart | 35 +++++++------- .../unit/test/widget/bottom_sheet_test.dart | 47 +++++++++++++++++++ 2 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 packages/unit/test/widget/bottom_sheet_test.dart diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index fa5c8e5ac2..4edc362b7a 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -68,23 +68,26 @@ class _BottomSheetState extends State<_BottomSheet> { } Widget build(BuildContext context) { - return new BuilderTransition( - performance: config.route._performance, - variables: >[_layout.childTop], - builder: (BuildContext context) { - return new ClipRect( - child: new CustomOneChildLayout( - delegate: _layout, - token: _layout.childTop.value, - child: new GestureDetector( - onVerticalDragStart: _handleDragStart, - onVerticalDragUpdate: _handleDragUpdate, - onVerticalDragEnd: _handleDragEnd, - child: new Material(child: config.route.child) + return new GestureDetector( + onTap: () { Navigator.of(context).pop(); }, + child: new BuilderTransition( + performance: config.route._performance, + variables: >[_layout.childTop], + builder: (BuildContext context) { + return new ClipRect( + child: new CustomOneChildLayout( + delegate: _layout, + token: _layout.childTop.value, + child: new GestureDetector( + onVerticalDragStart: _handleDragStart, + onVerticalDragUpdate: _handleDragUpdate, + onVerticalDragEnd: _handleDragEnd, + child: new Material(child: config.route.child) + ) ) - ) - ); - } + ); + } + ) ); } } diff --git a/packages/unit/test/widget/bottom_sheet_test.dart b/packages/unit/test/widget/bottom_sheet_test.dart new file mode 100644 index 0000000000..39f308d42c --- /dev/null +++ b/packages/unit/test/widget/bottom_sheet_test.dart @@ -0,0 +1,47 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:test/test.dart'; + +import 'widget_tester.dart'; + +void main() { + test('Verify that a tap dismisses the BottomSheet', () { + testWidgets((WidgetTester tester) { + BuildContext context; + tester.pumpWidget(new MaterialApp( + routes: { + '/': (RouteArguments args) { + context = args.context; + return new Container(); + } + } + )); + + tester.pump(); + expect(tester.findText('BottomSheet'), isNull); + + showModalBottomSheet(context: context, child: new Text('BottomSheet')); + tester.pump(); // bottom sheet show animation starts + tester.pump(new Duration(seconds: 1)); // animation done + expect(tester.findText('BottomSheet'), isNotNull); + + // Tap on the the bottom sheet itself to dismiss it + tester.tap(tester.findText('BottomSheet')); + tester.pump(); // bottom sheet dismiss animation starts + tester.pump(new Duration(seconds: 1)); // animation done + expect(tester.findText('BottomSheet'), isNull); + + showModalBottomSheet(context: context, child: new Text('BottomSheet')); + tester.pump(); // bottom sheet show animation starts + tester.pump(new Duration(seconds: 1)); // animation done + expect(tester.findText('BottomSheet'), isNotNull); + + // Tap above the the bottom sheet to dismiss it + tester.tapAt(new Point(20.0, 20.0)); + tester.pump(); // bottom sheet dismiss animation starts + tester.pump(new Duration(seconds: 1)); // animation done + expect(tester.findText('BottomSheet'), isNull); + }); + }); + +}