Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: Text("Gestur App"),
- ),
- body: Column(
- children: [
- HorizontalDrag(),
- Divider(),
- VerticalDrag(),
- Divider(),
- TapExample(),
- Divider(),
- DoubleTapExample(),
- Divider(),
- OnLongPressExample(),
- ],
- ),
- ),
- );
- }
- }
- class VerticalDrag extends StatefulWidget {
- @override
- State<VerticalDrag> createState() => _VerticalDragState();
- }
- class _VerticalDragState extends State<VerticalDrag> {
- bool _dragging = false;
- Offset _move = Offset.zero;
- int _dragCount = 0;
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onVerticalDragStart: (DragStartDetails details) {
- setState(() {
- _dragging = true;
- //_move = Offset.zero;
- });
- },
- onVerticalDragEnd: (DragEndDetails details) {
- setState(() {
- _dragging = false;
- _dragCount++;
- });
- },
- onVerticalDragUpdate: (DragUpdateDetails details) {
- setState(() {
- _move += details.delta;
- });
- },
- child: Container(
- color: Colors.grey,
- child: Center(
- child: Transform.translate(
- offset: _move,
- child: Text(
- _dragging ? "DRAGGING!" : "Drag : $_dragCount",
- style: Theme.of(context).textTheme.headline4,
- ),
- ),
- ),
- ),
- );
- }
- }
- class HorizontalDrag extends StatefulWidget {
- @override
- State<HorizontalDrag> createState() => _HorizontalDragState();
- }
- class _HorizontalDragState extends State<HorizontalDrag> {
- bool _dragging = false;
- Offset _move = Offset.zero;
- int _dragCount = 0;
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onHorizontalDragStart: (DragStartDetails details) {
- setState(() {
- _dragging = true;
- //_move = Offset.zero;
- });
- },
- onHorizontalDragEnd: (DragEndDetails details) {
- setState(() {
- _dragging = false;
- _dragCount++;
- });
- },
- onHorizontalDragUpdate: (DragUpdateDetails details) {
- setState(() {
- _move += details.delta;
- });
- },
- child: Container(
- color: Colors.grey,
- child: Center(
- child: Transform.translate(
- offset: _move,
- child: Text(
- _dragging ? "DRAGGING!" : "Drag : $_dragCount",
- style: Theme.of(context).textTheme.headline4,
- ),
- ),
- ),
- ),
- );
- }
- }
- class TapExample extends StatefulWidget {
- @override
- State<TapExample> createState() => _TapExampleState();
- }
- class _TapExampleState extends State<TapExample> {
- 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.headline4,
- ),
- ),
- ),
- );
- }
- }
- class DoubleTapExample extends StatefulWidget {
- @override
- State<DoubleTapExample> createState() => _DoubleTapExampleState();
- }
- class _DoubleTapExampleState extends State<DoubleTapExample> {
- int _counter = 0;
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onDoubleTap: () {
- setState(() {
- _counter++;
- });
- },
- child: Container(
- color: Colors.grey,
- child: Center(
- child: Text(
- "Double Tap Count : $_counter",
- style: Theme.of(context).textTheme.headline4,
- ),
- ),
- ),
- );
- }
- }
- class OnLongPressExample extends StatefulWidget {
- @override
- State<OnLongPressExample> createState() => _OnLongPressExampleState();
- }
- class _OnLongPressExampleState extends State<OnLongPressExample> {
- int _counter = 0;
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onLongPress: () {
- setState(() {
- _counter++;
- });
- },
- child: Container(
- color: Colors.grey,
- child: Center(
- child: Text(
- "On Long Press Count : $_counter",
- style: Theme.of(context).textTheme.headline4,
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement