From 03524a426f3bf8bad1cc6ba1e3a0737ad67e0c58 Mon Sep 17 00:00:00 2001 From: Tomohiro Hattori <45988993+Hattomo@users.noreply.github.com> Date: Fri, 5 Jun 2020 02:43:01 +0900 Subject: [PATCH] Add sample code of GestureDetector with no children (#57838) --- .../lib/src/widgets/gesture_detector.dart | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/widgets/gesture_detector.dart b/packages/flutter/lib/src/widgets/gesture_detector.dart index c0a2914198..cfca89e7c4 100644 --- a/packages/flutter/lib/src/widgets/gesture_detector.dart +++ b/packages/flutter/lib/src/widgets/gesture_detector.dart @@ -51,6 +51,7 @@ export 'package:flutter/rendering.dart' show RenderSemanticsGestureHandler; // bool _lights; // void setState(VoidCallback fn) { } // String _last; +// Color _color; /// Factory for creating gesture recognizers. /// @@ -130,8 +131,9 @@ class GestureRecognizerFactoryWithHandlers extends /// /// {@tool snippet} /// -/// This example turns the light bulb yellow when the "turn lights on" button is -/// tapped by setting the `_lights` field: +/// This example of a [Container] contains a black light bulb wrapped in a [GestureDetector]. +/// It turns the light bulb yellow when the "turn lights on" button is tapped +/// by setting the `_lights` field. Above animation shows the code in use: /// /// ```dart /// Container( @@ -166,6 +168,29 @@ class GestureRecognizerFactoryWithHandlers extends /// ``` /// {@end-tool} /// +/// {@tool snippet} +/// +/// This example of a [Container] wraps a [GestureDetector] widget. +/// Since the [GestureDetector] does not have a child it takes on the size of +/// its parent making the entire area of the surrounding [Container] clickable. +/// When tapped the [Container] turns yellow by setting the `_color` field: +/// +/// ```dart +/// Container( +/// color: _color, +/// height: 200.0, +/// width: 200.0, +/// child: GestureDetector( +/// onTap: () { +/// setState(() { +/// _color = Colors.yellow; +/// }); +/// }, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// /// ## Debugging /// /// To see how large the hit test box of a [GestureDetector] is for debugging