Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
time_selector.dart
Go to the documentation of this file.
1import 'dart:developer';
2
3import 'package:easy_localization/easy_localization.dart';
4import 'package:flutter/material.dart';
5
6import '../../../../../core/ui/theme/color_palette.dart';
7
8class TimeSelector extends StatefulWidget {
9 final Function(String) onTimeRangeChanged;
11 super.key,
12 required this.onTimeRangeChanged,
13 });
14
15 @override
16 State<TimeSelector> createState() => _TimeSelectorState();
17}
18
19class _TimeSelectorState extends State<TimeSelector> {
20
22 DateTime _startDate = DateTime.now().subtract(Duration(days: DateTime.now().weekday - 1));
23 DateTime _endDate = DateTime.now();
24
25 @override
26 Widget build(BuildContext context) {
27 return Container(
28 padding: const EdgeInsets.all(8),
29 decoration: BoxDecoration(
31 borderRadius: BorderRadius.circular(20),
32 boxShadow: [
33 BoxShadow(
34 color: ColorPalette.black.withValues(alpha: 0.05),
35 blurRadius: 20,
36 offset: const Offset(0, 10),
37 ),
38 ],
39 ),
41 children: [
42 Row(
43 children: [
44 Expanded(
45 child: GestureDetector(
46 onTap: () => _updateTimeRange(TimeRange.week),
48 "common.this_week".tr(),
50 ),
51 ),
52 ),
53 Expanded(
54 child: GestureDetector(
55 onTap: () => _updateTimeRange(TimeRange.month),
57 "common.this_month".tr(),
59 ),
60 ),
61 ),
62 Expanded(
63 child: GestureDetector(
64 onTap: () async {
65 await _showDateRangePicker(context);
67 },
69 "dashboard.custom".tr(),
71 ),
72 ),
73 ),
74 ],
75 ),
76 const SizedBox(height: 16),
77 Padding(
78 padding: const EdgeInsets.all(8.0),
79 child: Row(
80 mainAxisAlignment: MainAxisAlignment.center,
81 children: [
83 const SizedBox(width: 16),
84 Container(
85 width: 20,
86 height: 2,
87 color: ColorPalette.grey.withValues(alpha: 0.3),
88 ),
89 const SizedBox(width: 16),
91 ],
92 ),
93 ),
94 ],
95 ),
96 );
97 }
98
100 return DateFormat('dd MMM').format(date);
101 }
102
103 Widget _buildTab(String text, bool isSelected) {
104 return Container(
105 margin: const EdgeInsets.all(4),
106 padding: const EdgeInsets.symmetric(vertical: 12),
107 decoration: BoxDecoration(
108 color: isSelected ? ColorPalette.lightGreen : Colors.transparent,
109 borderRadius: BorderRadius.circular(12),
110 ),
111 child: Text(
112 text,
113 textAlign: TextAlign.center,
114 style: TextStyle(
116 fontWeight: isSelected ? FontWeight.bold : FontWeight.w500,
117 fontSize: 14,
118 ),
119 ),
120 );
121 }
122
124 return Container(
125 padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
126 decoration: BoxDecoration(
128 borderRadius: BorderRadius.circular(12),
129 ),
130 child: Row(
131 mainAxisSize: MainAxisSize.min,
132 children: [
133 Text(
134 label,
135 style: const TextStyle(
137 fontSize: 14,
138 ),
139 ),
140 const SizedBox(width: 8),
141 Text(
142 date,
143 style: const TextStyle(
145 fontWeight: FontWeight.bold,
146 fontSize: 14,
147 ),
148 ),
149 ],
150 ),
151 );
152 }
153
154 Future<void> _showDateRangePicker(BuildContext context) async {
155
156 final DateTimeRange? pickedDateRange = await showDateRangePicker(
157 lastDate: DateTime.now(),
158 context: context,
159 firstDate: DateTime(2025),
160 builder: (context, child) {
161 return Theme(
162 data: Theme.of(context).copyWith(
163 colorScheme: const ColorScheme.light(
164 primary: ColorPalette.lightGreen,
165 onPrimary: ColorPalette.white,
166 surface: ColorPalette.white,
167 onSurface: ColorPalette.darkGrey,
168 ),
169 ),
170 child: child!,
171 );
172 },
173 );
174
175 if (pickedDateRange != null) {
176 setState(() {
177 _startDate = pickedDateRange.start;
178 _endDate = pickedDateRange.end;
179 });
181 }
182 }
183
185 setState(() {
186 _selectedTimeRange = range;
187 switch (range) {
188 case TimeRange.week:
189 _startDate = DateTime.now().subtract(Duration(days: DateTime.now().weekday - 1));
190 _endDate = DateTime.now();
191 widget.onTimeRangeChanged('week');
192 break;
193 case TimeRange.month:
194 _startDate = DateTime(DateTime.now().year, DateTime.now().month, 1);
195 _endDate = DateTime.now();
196 widget.onTimeRangeChanged('month');
197 break;
198 case TimeRange.custom:
199 // Custom range is handled by date picker
200 break;
201 }
202 });
204 }
205
206 void _fetchDataForTimeRange(DateTime start, DateTime end) {
207 // Implement your data fetching logic here
208 // This could involve calling an API, updating state, etc.
209 log('Fetching data from ${DateFormat('dd MMM yyyy').format(start)} to ${DateFormat('dd MMM yyyy').format(end)}');
210 }
211}
212
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
static const darkGrey
static const lightGreen
static const black
static const white
static const antiFlashWhite
static const grey
const TimeSelector({ super.key, required this.onTimeRangeChanged, })
override State< TimeSelector > createState()
final Function(String) onTimeRangeChanged
final Widget child
final EdgeInsets padding
class Partner String
final Color color
Definition failures.dart:1
Future< void > _showDateRangePicker() async
final String date
final VoidCallback onTap
DateTime _endDate
Widget _buildTab(String text, bool isSelected)
DateTime _startDate
class TimeSelector extends StatefulWidget _selectedTimeRange
void _fetchDataForTimeRange(DateTime start, DateTime end)
@ month
@ custom
void _updateTimeRange(TimeRange range)
Widget _buildDateChip(String label, String date)
class UnloadingCollectionItem extends StatefulWidget isSelected
final String label
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
String _formatDate(DateTime date)
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,),),),],)