text stringlengths 1 372 |
|---|
gesture the user intends by having each recognizer join |
the gesture arena. the gesture arena determines which |
gesture wins using the following rules: |
at any time, a recognizer can eliminate itself and leave the |
arena. if there’s only one recognizer left in the arena, |
that recognizer wins. |
at any time, a recognizer can declare itself the winner, |
causing all of the remaining recognizers to lose. |
for example, when disambiguating horizontal and vertical dragging, |
both recognizers enter the arena when they receive the pointer |
down event. the recognizers observe the pointer move events. |
if the user moves the pointer more than a certain number of |
logical pixels horizontally, the horizontal recognizer declares |
the win and the gesture is interpreted as a horizontal drag. |
similarly, if the user moves more than a certain number of logical |
pixels vertically, the vertical recognizer declares itself the winner. |
the gesture arena is beneficial when there is only a horizontal |
(or vertical) drag recognizer. in that case, there is only one |
recognizer in the arena and the horizontal drag is recognized |
immediately, which means the first pixel of horizontal movement |
can be treated as a drag and the user won’t need to wait for |
further gesture disambiguation. |
<topic_end> |
<topic_start> |
handle taps |
you not only want to display information to users, |
you want users to interact with your app. |
use the GestureDetector widget to respond |
to fundamental actions, such as tapping and dragging. |
info note |
to learn more, watch this short widget of the week video on the GestureDetector widget: |
this recipe shows how to make a custom button that shows |
a snackbar when tapped with the following steps: |
<code_start> |
// the GestureDetector wraps the button. |
GestureDetector( |
// when the child is tapped, show a snackbar. |
onTap: () { |
const snackBar = SnackBar(content: Text('Tap')); |
ScaffoldMessenger.of(context).showSnackBar(snackBar); |
}, |
// the custom button |
child: container( |
padding: const EdgeInsets.all(12), |
decoration: BoxDecoration( |
color: Colors.lightBlue, |
borderRadius: BorderRadius.circular(8), |
), |
child: const Text('My button'), |
), |
) |
<code_end> |
<topic_end> |
<topic_start> |
notes |
<topic_end> |
<topic_start> |
interactive example |
<code_start> |
import 'package:flutter/material.dart'; |
void main() => runApp(const MyApp()); |
class MyApp extends StatelessWidget { |
const MyApp({super.key}); |
@override |
widget build(BuildContext context) { |
const title = 'gesture demo'; |
return const MaterialApp( |
title: title, |
home: MyHomePage(title: title), |
); |
} |
} |
class MyHomePage extends StatelessWidget { |
final string title; |
const MyHomePage({super.key, required this.title}); |
@override |
widget build(BuildContext context) { |
return scaffold( |
appBar: AppBar( |
title: text(title), |
), |
body: const center( |
child: MyButton(), |
), |
); |
} |
} |
class MyButton extends StatelessWidget { |
const MyButton({super.key}); |
@override |
widget build(BuildContext context) { |
// the GestureDetector wraps the button. |
return GestureDetector( |
// when the child is tapped, show a snackbar. |
onTap: () { |
const snackBar = SnackBar(content: Text('Tap')); |
ScaffoldMessenger.of(context).showSnackBar(snackBar); |
}, |
// the custom button |
child: container( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.