Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
dashboard_card.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:flutter_screenutil/flutter_screenutil.dart';
3import 'package:go_router/go_router.dart';
4import 'dart:math' as math;
5
6class DashboardCard extends StatefulWidget {
8 final double? size;
9
11 super.key,
12 required this.item,
13 this.size,
14 });
15
16 @override
17 State<DashboardCard> createState() => _DashboardCardState();
18}
19
20class _DashboardCardState extends State<DashboardCard>
21 with SingleTickerProviderStateMixin {
22 late AnimationController _controller;
23 late Animation<double> _scaleAnimation;
24 bool _isPressed = false;
25
26 @override
27 void initState() {
28 super.initState();
29 _controller = AnimationController(
30 duration: const Duration(milliseconds: 150),
31 vsync: this,
32 );
33 _scaleAnimation = Tween<double>(begin: 1.0, end: 0.95).animate(
34 CurvedAnimation(
35 parent: _controller,
36 curve: Curves.easeInOut,
37 ),
38 );
39 }
40
41 @override
42 void dispose() {
43 _controller.dispose();
44 super.dispose();
45 }
46
47 void _handleTapDown(TapDownDetails details) {
48 if (widget.item.isEnabled ?? true) {
49 setState(() => _isPressed = true);
50 _controller.forward();
51 }
52 }
53
54 void _handleTapUp(TapUpDetails details) {
55 if (widget.item.isEnabled ?? true) {
56 setState(() => _isPressed = false);
57 _controller.reverse();
58
59 if (widget.item.onTap != null) {
60 widget.item.onTap!();
61 } else if (widget.item.path != null) {
62 context.push(widget.item.path!);
63 }
64 }
65 }
66
68 setState(() => _isPressed = false);
69 _controller.reverse();
70 }
71
72 @override
73 Widget build(BuildContext context) {
74 final size = widget.size ?? 170.sp;
75
76 return AnimatedBuilder(
77 animation: _scaleAnimation,
78 builder: (context, child) => Transform.scale(
79 scale: _scaleAnimation.value,
80 child: child,
81 ),
82 child: GestureDetector(
83 onTapDown: _handleTapDown,
84 onTapUp: _handleTapUp,
85 onTapCancel: _handleTapCancel,
86 child: Container(
87 height: size,
88 width: size,
89 decoration: BoxDecoration(
90 color: (widget.item.isEnabled ?? true) ? Colors.white : Colors.grey.withValues(alpha: 0.3),
91 shape: BoxShape.circle,
92 boxShadow: [
93 BoxShadow(
94 color: Colors.black.withValues(alpha: 0.08),
95 blurRadius: 24,
96 offset: const Offset(0, 8),
97 spreadRadius: 0,
98 ),
99 ],
100 ),
101 child: Stack(
102 children: [
103 // Circular Progress Indicator
104 CustomPaint(
105 size: Size(size, size),
106 painter: CircularProgressPainter(
107 progress: 0.75, // You can add this to DashboardItem if needed
108 progressColor: widget.item.color,
109 strokeWidth: 3.0,
110 ),
111 ),
112
113 Center(
114 child: Padding(
115 padding: EdgeInsets.all(20.sp),
116 child: Column(
117 crossAxisAlignment: CrossAxisAlignment.center,
118 mainAxisSize: MainAxisSize.min,
119 children: [
120 Container(
121 padding: EdgeInsets.all(12.sp),
122 decoration: BoxDecoration(
123 color: widget.item.color.withValues(alpha: 0.1),
124 borderRadius: BorderRadius.circular(16),
125 ),
126 child: Icon(
127 widget.item.icon,
128 color: (widget.item.isEnabled ?? true)
129 ? widget.item.color
130 : widget.item.color.withValues(alpha: 0.5),
131 size: 23,
132 ),
133 ),
134 SizedBox(height: 13.sp),
135 Text(
136 widget.item.title,
137 textAlign: TextAlign.center,
138 style: Theme.of(context)
139 .textTheme
140 .titleMedium
141 ?.copyWith(
142 fontSize: 14.sp,
143 fontWeight: FontWeight.w500,
144 color: (widget.item.isEnabled ?? true)
145 ? Theme.of(context).colorScheme.onSurface
146 : Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.5),
147 ),
148 ),
149 if (widget.item.subtitle != null) ...[
150 SizedBox(height: 4.sp),
151 Text(
152 widget.item.subtitle!,
153 textAlign: TextAlign.center,
154 style:
155 Theme.of(context).textTheme.bodyMedium?.copyWith(
156 color: (widget.item.isEnabled ?? true)
157 ? Theme.of(context)
158 .colorScheme
159 .onSurface
160 .withValues(alpha: 0.6)
161 : Theme.of(context)
162 .colorScheme
163 .onSurface
164 .withValues(alpha: 0.3),
165 ),
166 ),
167 ],
168 ],
169 ),
170 ),
171 ),
172
173 if (_isPressed)
174 Positioned.fill(
175 child: Container(
176 decoration: BoxDecoration(
177 color: widget.item.color.withValues(alpha: 0.05),
178 shape: BoxShape.circle,
179 ),
180 ),
181 ),
182 ],
183 ),
184 ),
185 ),
186 );
187 }
188}
189
190class CircularProgressPainter extends CustomPainter {
191 final double progress;
192 final Color progressColor;
193 final double strokeWidth;
194
196 required this.progress,
197 required this.progressColor,
198 this.strokeWidth = 2.0,
199 });
200
201 @override
202 void paint(Canvas canvas, Size size) {
203 final center = Offset(size.width / 2, size.height / 2);
204 final radius = (size.width - strokeWidth) / 2;
205
206 // Draw progress arc
207 final progressPaint = Paint()
209 ..style = PaintingStyle.stroke
211 ..strokeCap = StrokeCap.round;
212
213 canvas.drawArc(
214 Rect.fromCircle(center: center, radius: radius),
215 -math.pi / 2,
216 2 * math.pi * progress,
217 false,
218 progressPaint,
219 );
220 }
221
222 @override
223 bool shouldRepaint(CustomPainter oldDelegate) => true;
224}
225
226class DashboardItem {
228 final IconData icon;
229 final Color color;
231 final String? path;
232 final bool? isEnabled;
233 final VoidCallback? onTap;
234
236 required this.title,
237 required this.icon,
238 required this.color,
239 this.subtitle,
240 this.path,
241 this.isEnabled,
242 this.onTap,
243 });
244}
override void initState()
override void dispose()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
final Color progressColor
override void paint(Canvas canvas, Size size)
CircularProgressPainter({ required this.progress, required this.progressColor, this.strokeWidth=2.0, })
override bool shouldRepaint(CustomPainter oldDelegate)
final double strokeWidth
const DashboardCard({ super.key, required this.item, this.size, })
final double size
override State< DashboardCard > createState()
final DashboardItem item
final Widget child
final EdgeInsets padding
final Color color
void _handleTapUp(TapUpDetails details)
final String subtitle
final bool isEnabled
late Animation< double > _scaleAnimation
void _handleTapDown(TapDownDetails details)
void _handleTapCancel()
bool _isPressed
final String path
class Partner String
final Color color
Definition failures.dart:1
List< DashboardItem > get DashboardItem(title:'home.transactions'.tr(), icon:FluentIcons.arrow_swap_16_regular, color:ColorPalette.lightGreen, path:Routes.transactionsHistoryScreen.route,)
class LanguageSelector extends StatefulWidget _controller
final VoidCallback onTap
final String title
final double progress
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)