GestureDetector fills its parent if child-less. (#5397)

Fixes https://github.com/flutter/flutter/issues/5380
This commit is contained in:
Ian Hickson 2016-08-15 12:42:02 -07:00 committed by GitHub
parent c0a71e341c
commit e2d0917ed6
4 changed files with 52 additions and 2 deletions

View File

@ -1713,6 +1713,10 @@ typedef void PointerUpEventListener(PointerUpEvent event);
typedef void PointerCancelEventListener(PointerCancelEvent event); typedef void PointerCancelEventListener(PointerCancelEvent event);
/// Calls callbacks in response to pointer events. /// Calls callbacks in response to pointer events.
///
/// If it has a child, defers to the child for sizing behavior.
///
/// If it does not have a child, grows to fit the parent-provided constraints.
class RenderPointerListener extends RenderProxyBoxWithHitTestBehavior { class RenderPointerListener extends RenderProxyBoxWithHitTestBehavior {
/// Creates a render object that forwards point events to callbacks. /// Creates a render object that forwards point events to callbacks.
/// ///
@ -1732,12 +1736,19 @@ class RenderPointerListener extends RenderProxyBoxWithHitTestBehavior {
/// Called when a pointer that triggered an [onPointerDown] changes position. /// Called when a pointer that triggered an [onPointerDown] changes position.
PointerMoveEventListener onPointerMove; PointerMoveEventListener onPointerMove;
/// Called when a pointer that triggered an [onPointerDown] is no longer in contact with the screen. /// Called when a pointer that triggered an [onPointerDown] is no longer in
/// contact with the screen.
PointerUpEventListener onPointerUp; PointerUpEventListener onPointerUp;
/// Called when the input from a pointer that triggered an [onPointerDown] is no longer directed towards this receiver. /// Called when the input from a pointer that triggered an [onPointerDown] is
/// no longer directed towards this receiver.
PointerCancelEventListener onPointerCancel; PointerCancelEventListener onPointerCancel;
@override
void performResize() {
size = constraints.biggest;
}
@override @override
void handleEvent(PointerEvent event, HitTestEntry entry) { void handleEvent(PointerEvent event, HitTestEntry entry) {
if (onPointerDown != null && event is PointerDownEvent) if (onPointerDown != null && event is PointerDownEvent)

View File

@ -2477,6 +2477,9 @@ class WidgetToRenderBoxAdapter extends LeafRenderObjectWidget {
/// ///
/// Rather than listening for raw pointer events, consider listening for /// Rather than listening for raw pointer events, consider listening for
/// higher-level gestures using [GestureDetector]. /// higher-level gestures using [GestureDetector].
///
/// If it has a child, this widget defers to the child for sizing behavior. If
/// it does not have a child, it grows to fit the parent instead.
class Listener extends SingleChildRenderObjectWidget { class Listener extends SingleChildRenderObjectWidget {
/// Creates a widget that forwards point events to callbacks. /// Creates a widget that forwards point events to callbacks.
/// ///

View File

@ -40,6 +40,9 @@ typedef GestureRecognizer GestureRecognizerFactory(GestureRecognizer recognizer)
/// ///
/// Attempts to recognize gestures that correspond to its non-null callbacks. /// Attempts to recognize gestures that correspond to its non-null callbacks.
/// ///
/// If this widget has a child, it defers to that child for its sizing behavior.
/// If it does not have a child, it grows to fit the parent instead.
///
/// GestureDetector also listens for accessibility events and maps /// GestureDetector also listens for accessibility events and maps
/// them to the callbacks. To ignore accessibility events, set /// them to the callbacks. To ignore accessibility events, set
/// [excludeFromSemantics] to true. /// [excludeFromSemantics] to true.

View File

@ -190,4 +190,37 @@ void main() {
expect(didTap, isTrue); expect(didTap, isTrue);
}); });
testWidgets('Empty', (WidgetTester tester) async {
bool didTap = false;
await tester.pumpWidget(
new Center(
child: new GestureDetector(
onTap: () {
didTap = true;
},
)
)
);
expect(didTap, isFalse);
await tester.tapAt(new Point(10.0, 10.0));
expect(didTap, isTrue);
});
testWidgets('Only container', (WidgetTester tester) async {
bool didTap = false;
await tester.pumpWidget(
new Center(
child: new GestureDetector(
onTap: () {
didTap = true;
},
child: new Container(),
)
)
);
expect(didTap, isFalse);
await tester.tapAt(new Point(10.0, 10.0));
expect(didTap, isFalse);
});
} }