-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenTap.dart
More file actions
105 lines (95 loc) · 2.9 KB
/
Copy pathscreenTap.dart
File metadata and controls
105 lines (95 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import 'package:flutter/material.dart';
void main() {
runApp(const SafeTapCounterApp());
}
class SafeTapCounterApp extends StatelessWidget {
const SafeTapCounterApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Zero-Loop Tap Counter',
debugShowCheckedModeBanner: false,
theme: ThemeData(brightness: Brightness.dark, useMaterial3: true),
home: const SafeCounterScreen(),
);
}
}
class SafeCounterScreen extends StatefulWidget {
const SafeCounterScreen({super.key});
@override
State<SafeCounterScreen> createState() => _SafeCounterScreenState();
}
class _SafeCounterScreenState extends State<SafeCounterScreen> {
int _counter = 0;
void _handleScreenTap() {
setState(() {
_counter++;
});
}
void _handleReset() {
setState(() {
_counter = 0;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xff121212),
body: Stack(
children: [
// Full-screen structural Tap Target
Positioned.fill(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _handleScreenTap,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'TAP COUNT',
style: TextStyle(
fontSize: 14,
letterSpacing: 6.0,
fontWeight: FontWeight.w600,
color: Colors.white.withValues(alpha: 0.4),
),
),
const SizedBox(height: 20),
Text(
'$_counter',
style: const TextStyle(
fontSize: 120,
fontWeight: FontWeight.w900,
color: Colors.white,
),
),
const SizedBox(height: 20),
Text(
'Tap anywhere to count',
style: TextStyle(
fontSize: 14,
color: Colors.white.withValues(alpha: 0.3),
),
),
],
),
),
),
),
// Reset Action Button aligned to safely clear state
Positioned(
top: MediaQuery.paddingOf(context).top + 16,
right: 16,
child: IconButton(
icon: const Icon(Icons.refresh_rounded, size: 28),
color: Colors.white.withValues(alpha: 0.6),
onPressed: _handleReset,
),
),
],
),
);
}
}