Created
October 9, 2023 14:48
-
-
Save codesxt/852fb9907deca95efb54c9e0c5cc7285 to your computer and use it in GitHub Desktop.
GestureDetector example 01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | |
useMaterial3: true, | |
), | |
home: const MyHomePage(title: 'Gestures'), | |
debugShowCheckedModeBanner: false, | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({super.key, required this.title}); | |
final String title; | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _taps = 0; | |
int _doubleTaps = 0; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Container( | |
margin: const EdgeInsets.symmetric(horizontal: 20), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
mainAxisSize: MainAxisSize.min, | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: <Widget>[ | |
GestureDetector( | |
onTap: () { | |
_taps++; | |
setState(() {}); | |
}, | |
onDoubleTap: () { | |
_doubleTaps++; | |
setState(() {}); | |
}, | |
child: Card( | |
elevation: 10, | |
child: Container( | |
height: 100, | |
), | |
), | |
), | |
Text( | |
'$_taps toques', | |
style: Theme.of(context).textTheme.headlineMedium, | |
), | |
Text( | |
'$_doubleTaps doble toques', | |
style: Theme.of(context).textTheme.headlineMedium, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment