import 'dart:async'; import 'package:flutter/material.dart'; class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { int _counter = 0; Timer? timer; void _incrementCounter() { setState(() { _counter++; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( toolbarHeight: 35, title: Text(widget.title), backgroundColor: Theme.of(context).colorScheme.primary, ), body: Center( child: SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ const SizedBox( height: 150, child: Text( 'You have pushed the button this many times:', ), ), Text( '$_counter', style: Theme.of(context).textTheme.headlineMedium, ), TextButton( onPressed: () { Navigator.pushNamed(context,"/media"); }, child: const Text("to media"), ), TextButton( onPressed: () { Navigator.pushNamed(context,"/video"); }, child: const Text("to video"), ) ], ), ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, floatingActionButton: FloatingActionButton( tooltip: 'Increment', onPressed: () {}, child: GestureDetector( onLongPressStart: (_) { timer?.cancel(); Timer.periodic(const Duration(milliseconds: 10), (timer) { this.timer = timer; _incrementCounter(); }); debugPrint("onLongPressStart"); }, onLongPressEnd: (_) { timer?.cancel(); debugPrint("onLongPressEnd"); }, onLongPress: () { debugPrint("onLongPress"); }, onTap: () { _incrementCounter(); debugPrint("onTap"); }, child: const Icon(Icons.add), ), )); } }