@@ -28,6 +28,8 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
2828
2929 DateTime ? _startTime;
3030 DateTime ? _endTime;
31+ RepeatFrequency ? _selectedFrequency;
32+ List <bool > _selectedDays = List .filled (7 , false );
3133
3234 Color _color = Colors .blue;
3335
@@ -43,6 +45,7 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
4345 super .initState ();
4446
4547 _setDefaults ();
48+ _setInitialWeekday ();
4649 }
4750
4851 @override
@@ -102,7 +105,9 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
102105 }
103106
104107 _startDate = date.withoutTime;
105-
108+ // Reset weekday from new start date
109+ _selectedDays.fillRange (0 , _selectedDays.length, false );
110+ _selectedDays[date.weekday - 1 ] = true ;
106111 if (mounted) {
107112 setState (() {});
108113 }
@@ -247,6 +252,103 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
247252 hintText: "Event Description" ,
248253 ),
249254 ),
255+ Align (
256+ alignment: Alignment .centerLeft,
257+ child: Text (
258+ "Repeat" ,
259+ style: TextStyle (
260+ color: AppColors .black,
261+ fontWeight: FontWeight .w500,
262+ fontSize: 17 ,
263+ ),
264+ ),
265+ ),
266+ Column (
267+ crossAxisAlignment: CrossAxisAlignment .start,
268+ children: [
269+ Row (
270+ children: [
271+ Radio <RepeatFrequency >(
272+ value: RepeatFrequency .doNotRepeat,
273+ groupValue: _selectedFrequency,
274+ onChanged: (value) {
275+ setState (
276+ () => _selectedFrequency = value,
277+ );
278+ },
279+ ),
280+ Text (
281+ "Do not repeat" ,
282+ style: TextStyle (
283+ color: AppColors .black,
284+ fontSize: 17 ,
285+ ),
286+ ),
287+ ],
288+ ),
289+ Row (
290+ children: [
291+ Radio <RepeatFrequency >(
292+ value: RepeatFrequency .daily,
293+ groupValue: _selectedFrequency,
294+ onChanged: (value) {
295+ setState (
296+ () => _selectedFrequency = value,
297+ );
298+ },
299+ ),
300+ Text (
301+ "Daily" ,
302+ style: TextStyle (
303+ color: AppColors .black,
304+ fontSize: 17 ,
305+ ),
306+ )
307+ ],
308+ ),
309+ Row (
310+ children: [
311+ Radio <RepeatFrequency >(
312+ value: RepeatFrequency .weekly,
313+ groupValue: _selectedFrequency,
314+ onChanged: (value) {
315+ setState (
316+ () => _selectedFrequency = value,
317+ );
318+ },
319+ ),
320+ Text (
321+ "Weekly" ,
322+ style: TextStyle (
323+ color: AppColors .black,
324+ fontSize: 17 ,
325+ ),
326+ ),
327+ ],
328+ )
329+ ],
330+ ),
331+ if (_selectedFrequency == RepeatFrequency .weekly) ...[
332+ Wrap (
333+ children: List <Widget >.generate (AppConstants .weekTitles.length,
334+ (int index) {
335+ return ChoiceChip (
336+ label: Text (AppConstants .weekTitles[index]),
337+ showCheckmark: false ,
338+ selected: _selectedDays[index],
339+ onSelected: (bool selected) {
340+ setState (() {
341+ _selectedDays[index] = selected;
342+ if (! _selectedDays.contains (true )) {
343+ _selectedDays[_startDate.weekday - 1 ] = true ;
344+ }
345+ });
346+ },
347+ shape: CircleBorder (),
348+ );
349+ }).toList (),
350+ ),
351+ ],
250352 SizedBox (
251353 height: 15.0 ,
252354 ),
@@ -286,19 +388,40 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
286388 _form.currentState? .save ();
287389
288390 final event = CalendarEventData (
289- date: _startDate,
290- endTime: _endTime,
291- startTime: _startTime,
292- endDate: _endDate,
293- color: _color,
294- title: _titleController.text.trim (),
295- description: _descriptionController.text.trim (),
296- );
391+ date: _startDate,
392+ endTime: _endTime,
393+ startTime: _startTime,
394+ endDate: _endDate,
395+ color: _color,
396+ title: _titleController.text.trim (),
397+ description: _descriptionController.text.trim (),
398+ recurrenceSettings: RecurrenceSettings (
399+ _startDate,
400+ frequency: _selectedFrequency ?? RepeatFrequency .daily,
401+ weekdays: _selectedIndexes,
402+ ));
297403
298404 widget.onEventAdd? .call (event);
299405 _resetForm ();
300406 }
301407
408+ /// Get list of weekdays in indices from the selected days
409+ List <int > get _selectedIndexes {
410+ List <int > selectedIndexes = [];
411+ for (int i = 0 ; i < _selectedDays.length; i++ ) {
412+ if (_selectedDays[i] == true ) {
413+ selectedIndexes.add (i);
414+ }
415+ }
416+ return selectedIndexes;
417+ }
418+
419+ /// Set initial selected week to start date
420+ void _setInitialWeekday () {
421+ final currentWeekday = DateTime .now ().weekday - 1 ;
422+ _selectedDays[currentWeekday] = true ;
423+ }
424+
302425 void _setDefaults () {
303426 if (widget.event == null ) return ;
304427
0 commit comments