nord vpnnord vpn
Ad

Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.8 kB
1
Indexable
Never
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  double boxSize = 100;
  int numTaps = 0;
  int numDblTaps = 0;
  int numLongPress = 0;
  double posX = 0.0;
  double posY = 0.0;

  void center(BuildContext context){
    setState(() {
    posX= MediaQuery.of(context).size.width/2 - boxSize / 2;
    posY= (MediaQuery.of(context).size.width/2 - boxSize / 2) - (boxSize/2) - 40;
    });
  }

  @override
  Widget build(BuildContext context) {
    if (posX == 0){
      center(context);
    }
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Gestur Detector'),
      ),
      body: Stack(
        children: [
          Positioned(
            top: posY,
            left: posX,
            child: GestureDetector(
            onTap: () {
              setState(() {
                numTaps++;
              });
            },
            onDoubleTap: (){
              setState(() {
                numDblTaps++;
              });
            },
            onLongPress: (){
              setState(() {
                numLongPress++;
              });
            },
            onPanUpdate: (DragUpdateDetails details) {
              setState(() {
                double deltaY = details.delta.dy;
                posY += deltaY;
                double deltaX = details.delta.dx;
                posX += deltaX;
              });
            },
            child: Container(
              color: Colors.red,
              width: boxSize,
              height: boxSize,
            ),
            ),
            ),
        ]
      ),
      bottomNavigationBar: Container(
        color: Colors.yellow,
        padding: const EdgeInsets.all(16.0),
        child: Text(
          'Taps: $numTaps - Double Taps: $numDblTaps - Long Press: $numLongPress',
          style: Theme.of(context).textTheme.headlineLarge,
        ),
      ),
    );
  }
}

nord vpnnord vpn
Ad