September 2019
Beginner
512 pages
12h 52m
English
Let's see how to implement the tap event using the GestureDetector widget's onTap callback:
// part of tap_event_example.dart (full source code in the attached files)class _TapWidgetExampleState extends State<TapWidgetExample> { int _counter = 0; @override Widget build(BuildContext context) { return GestureDetector( onTap: () { setState(() { _counter++; }); }, child: Container( color: Colors.grey, child: Center( child: Text( "Tap count: $_counter", style: Theme.of(context).textTheme.display1, ), ), ), ); }}
This is the state implementation of a widget that holds the example. It has a single counter to show how many taps were performed on the screen. In this example, the onTap property holds a callback that updates the widget state after ...
Read now
Unlock full access