Skip to content

Instantly share code, notes, and snippets.

@JaveedIshaq
Last active March 2, 2020 18:57
Show Gist options
  • Save JaveedIshaq/fe6da201060f1d1b9a776104a3d57131 to your computer and use it in GitHub Desktop.
Save JaveedIshaq/fe6da201060f1d1b9a776104a3d57131 to your computer and use it in GitHub Desktop.
flutter-Gesture Detector Widget with tap Example
// this gist demonstrate the Flutter Gesture Detector Widget
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
GestureDetector(
onTap: () {
setState(() {
_counter++;
});
},
child: Container(
color: Colors.green,
child: Center(
child: Text(
"Tap here to increase the counter",
),
),
),
),
GestureDetector(
onTap: () { setState((){ _counter--;});},
child: Text("Tap to decrease <counter"),
)
],
),
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment