-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.dart
1589 lines (1473 loc) · 60.3 KB
/
calendar.dart
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import 'dart:ui';
import 'dart:core';
import 'package:flutter/animation.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:calendar_widget/streakservice.dart';
class DuoCalendar {
late int numberOfDaysInMonth;
//StreakData Calculation as part of the calendar class__________________________
int longest_Streak = 0;
int last_Streak = 0;
bool current_StreakIsLastStreak = false;
//Supply [start]________________________________________________________________
//Supply back and forward button functions
Function() backButtonFunction = () {};
Function() forwardButtonFunction = () {};
DateTime supplyDate = DateTime.now(); //Date to be supplied
DateTime supplyDateForPreviousMonth = DateTime.now();
DateTime supplyDateForNextMonth = DateTime.now();
//Supply [end]__________________________________________________________________
//Constructor___________________________________________________________________
DuoCalendar({this.dayNameLetters = 3});
//USER_PROPERTY [start]_________________________________________________________
List<DateTime> streakList =
[]; //USER_PROPERTY //List of dates to be highlighted
List<int> colorList = [];
List<Color> colorPaletteList = [];
int dayNameLetters;
//Colors___________________________________>>>>>>>
//Miscellaneous
Color calendarColor = Color.fromARGB(0, 255, 255, 255); //USER_PROPERTY
Color calendarBorderColor =
Color.fromARGB(255, 148, 148, 148); //USER_PROPERTY
//Control Colors
Color controlcolor = const Color.fromARGB(255, 255, 255, 255); //USER_PROPERTY
Color controlBorderColor = const Color.fromARGB(255, 0, 0, 0); //USER_PROPERTY
Color controlFontColor = const Color.fromARGB(255, 0, 0, 0); //USER_PROPERTY
//Header Colors
Color headercolor = Color.fromARGB(255, 202, 202, 202); //USER_PROPERTY
Color headerElemcolor = Color.fromARGB(255, 202, 202, 202); //USER_PROPERTY
Color headerBorderColor = Color.fromARGB(255, 202, 202, 202); //USER_PROPERTY
Color headerElemBorderColor =
Color.fromARGB(255, 202, 202, 202); //USER_PROPERTY
Color headerFontColor = Color.fromARGB(255, 0, 0, 0); //USER_PROPERTY
//Body Colors
Color bodycolor = Color.fromARGB(255, 255, 255, 255); //USER_PROPERTY
Color bodyBorderColor = Color.fromARGB(255, 128, 128, 128); //USER_PROPERTY
Color bodyFontColor = const Color.fromARGB(255, 0, 0, 0); //USER_PROPERTY
Color bodyRowcolor = Color.fromARGB(255, 255, 208, 158); //USER_PROPERTY
Color bodyRowBorderColor = Color.fromARGB(0, 0, 0, 0); //USER_PROPERTY
Color rowElementCircleColor =
Color.fromARGB(255, 133, 133, 133); //USER_PROPERTY
//Leading Days Colors
Color leadingElementColor =
Color.fromARGB(255, 175, 105, 105); //USER_PROPERTY
Color leadingDaysFontColor =
Color.fromARGB(255, 255, 255, 255); //USER_PROPERTY
Color leadingElemBorderColor = Color.fromARGB(0, 0, 0, 0); //USER_PROPERTY
//Trailing Days Colors
Color trailingElementColor = Color.fromARGB(255, 50, 166, 70); //USER_PROPERTY
Color trailingDaysFontColor =
Color.fromARGB(255, 255, 255, 255); //USER_PROPERTY
Color trailingElemBorderColor = Color.fromARGB(255, 0, 0, 0); //USER_PROPERTY
//Streak Colors
Color streakColorCurrentMonth =
Color.fromARGB(255, 255, 144, 144); //USER_PROPERTY
Color streakColorPreviousMonth =
Color.fromARGB(255, 255, 160, 160); //USER_PROPERTY
Color streakStartColor = Color.fromARGB(255, 234, 53, 53); //USER_PROPERTY
Color streakEndColor = Color.fromARGB(255, 234, 53, 53); //USER_PROPERTY
Color streakSingleDayColor = Color.fromARGB(255, 234, 53, 53); //USER_PROPERTY
//Streak Dashboard
Color streakDashboardColor =
Color.fromARGB(255, 212, 212, 212); //USER_PROPERTY
Color streakDashboardBorderColor =
Color.fromARGB(255, 59, 59, 59); //USER_PROPERTY
Color streakDashboardFontColor = Color.fromARGB(255, 0, 0, 0); //USER_PROPERTY
Color streakDashboardDigitFontColor =
Color.fromARGB(255, 228, 122, 0); //USER_PROPERTY
String streakDashboardFontFamily = 'Nunito'; //USER_PROPERTY
double streakDashboardFontSize = 40; //USER_PROPERTY
double streakDashboardDigitFontSize = 60; //USER_PROPERTY
double streakDashboardLineSpace = 0; //USER_PROPERTY
FontWeight streakDashboardFontWeight = FontWeight.w900; //USER_PROPERTY
FontWeight streakDashboardDigitFontWeight = FontWeight.w900; //USER_PROPERTY
double streakDashboardDividerHeight = 150; //USER_PROPERTY
Color streakDashboardDividerColor =
Color.fromARGB(255, 108, 108, 108); //USER_PROPERTY
double streakDashboardDividerThickness = 5; //USER_PROPERTY
double streakDashboardDividerWidth = 10; //USER_PROPERTY
//Colors [end]__________________________>>>>>>>>
//Border Width
double headerBorderWidth = 0; //USER_PROPERTY
double bodyBorderWidth = 2; //USER_PROPERTY
double controlBorderWidth = 1; //USER_PROPERTY
double bodyRowBorderWidth = 3; //USER_PROPERTY
double bodyElemBorderWidth = 0; //USER_PROPERTY
double headerElemBorderWidth = 0; //USER_PROPERTY
double calendarBorderWidth = 3; //USER_PROPERTY
double streakDashboardBorderWidth = 3; //USER_PROPERTY
//Width
double allElemWidth = 54; //USER_PROPERTY
double headerBodyGap = 15; //USER_PROPERTY
double controlHeaderGap = 15; //USER_PROPERTY
//Padding
double calendarBodyPad = 10; //NOT USER PROPERTY //KEEP 0
double headerSidePad = 0; //NOT USER PROPERTY //KEEP 0
double headerUpDownPad =
10; //USER_PROPERTY // Padding of header row container
double bodyRowSidePad =
5; //USER_PROPERTY //MARKED //B/w calendar total body and row body //1 //DONE_DOCUMENTATION
double bodyRowUpDownPad = 5; //USER_PROPERTY //2 //DONE_DOCUMENTATION
double bodyRowSpaceing = 3; //USER_PROPERTY //3 //DONE_DOCUMENTATION
double headerHorizontalPad =
0; //USER_PROPERTY //NOT_REQUIRED //KEEP 0 //4 //DONE_DOCUMENTATION
double headerVerticalPad =
5; //USER_PROPERTY //Header elem container padding //5 //DONE_DOCUMENTATION
double rowHorizontalPad =
0; //USER_PROPERTY //NOT_REQUIRED , since Expanded used //KEEP 0
double rowElemVerticalPad = 5; //USER_PROPERTY //Row elem container padding
double bodyRowHorizontalPad =
2; //USER_PROPERTY //MARKED //b/w 1st and last elem with start and end sides of row
double bodyRowVerticalPad =
3; //USER_PROPERTY //Row elem container and row container vertical gap, padding of row container
//Border Radius
BorderRadius headerBorderRadius = BorderRadius.circular(100); //USER_PROPERTY
BorderRadius bodyBorderRadius = BorderRadius.circular(20); //USER_PROPERTY
BorderRadius controlBorderRadius = BorderRadius.circular(100); //USER_PROPERTY
BorderRadius bodyRowBorderRadius = BorderRadius.circular(100); //USER_PROPERTY
double bodyRowElemBorderRadius = 40; //USER_PROPERTY
BorderRadius calendarBorderRadius = BorderRadius.circular(20); //USER_PROPERTY
BorderRadius headerElemBorderRadius =
BorderRadius.circular(100); //USER_PROPERTY
//Fonts
//Control_Font
String controlFontFamily = 'Nunito'; //USER_PROPERTY //From Google Fonts
double controlFontSize = 20; //USER_PROPERTY
FontWeight controlFontWeight = FontWeight.bold; //USER_PROPERTY
//Header_Font
String headerFontFamily = 'Nunito'; //USER_PROPERTY //From Google Fonts
double headerFontSize = 18; //USER_PROPERTY
FontWeight headerFontWeight = FontWeight.w800; //USER_PROPERTY
//Body_Font
String bodyFontFamily = 'Nunito'; //USER_PROPERTY //From Google Fonts
double bodyFontSize = 20; //USER_PROPERTY
FontWeight bodyFontWeight = FontWeight.w700; //USER_PROPERTY
//Leading_Days_Font
String leadingDaysFontFamily = 'Nunito'; //USER_PROPERTY //From Google Fonts
double leadingDaysFontSize = 20; //USER_PROPERTY
FontWeight leadingDaysFontWeight = FontWeight.w700; //USER_PROPERTY
//Trailing_Days_Font
String trailingDaysFontFamily = 'Nunito'; //USER_PROPERTY //From Google Fonts
double trailingDaysFontSize = 20; //USER_PROPERTY
FontWeight trailingDaysFontWeight = FontWeight.bold; //USER_PROPERTY
//USER_PROPERTY [end]___________________________________________________________
List<int> currentMonthColorList = [];
//Day Names, choose any list according to choice //Contains USER_PROPERTY
List<String> dayNames = []; //Determined by user while building the widget
//Day Names, 3 letters
List<String> dayNames3letters = [
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
'Sun'
];
//Day Names, 2 letters
List<String> dayNames2letters = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
int selectedMonth =
DateTime.now().month; //TODO: Set to currently selected month
int selectedYear = DateTime.now().year; //TODO: Set to currently selected year
List<int> dayList = []; //TODO
List<int> leadingDayList = []; //TODO
List<int> trailingDayList = []; //TODO
int numberOfRows = 0; //Number of rows in the calendar
List<int> monthList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
//initializing variable values //INITIALIZER
List<List<int>> setValues() {
streakList = streakList.toSet().toList();
//sort the streakList
streakList.sort();
dayList = [];
leadingDayList = [];
trailingDayList = [];
selectedMonth = supplyDate.month;
// print('supplyDate: $supplyDate');
selectedYear = supplyDate.year;
numberOfDaysInMonth = setNumberofdaysInMonth(selectedMonth);
supplyDateForPreviousMonth = DateTime(selectedYear, selectedMonth - 1, 1);
supplyDateForNextMonth = DateTime(selectedYear, selectedMonth + 1, 1);
// print('supplyDateForPreviousMonth: $supplyDateForPreviousMonth');
// print('supplyDateForNextMonth: $supplyDateForNextMonth');
generateDayList();
List<List<int>> dayListMap_pre = buildDayListMap();
//Now we fill the dayListMap Such that it has 42 elements
//the list within the main list looks like [day, streakdata, month], all dates in the dayList are taken
//But now, the streak data has one more value 4, day is not in streak
List<List<int>> dayListMap = buildFinalDayListMap(dayListMap_pre);
return dayListMap;
}
List<List<int>> buildFinalDayListMap(List<List<int>> dayListMap_pre) {
List<List<int>> dayListMap_final = [];
bool monthflag = true;
// print('dayListMap_pre: $dayListMap_pre');
if (dayListMap_pre.length == 0) {
for (int i = 0; i < dayList.length; i++) {
dayListMap_final.add([dayList[i], 4, 0, 4]);
}
} else {
for (int i = 0, j = 0;
i < dayList.length && j < dayListMap_pre.length;
i++) {
int monthdata = 0;
if (i < 7) {
//previous month dates will be within 1st 7 elements
if (dayList[i] == 1) {
monthflag = false;
} else if (i > 0 && dayList[i - 1] > dayList[i]) {
monthflag = false;
}
if (monthflag) {
monthdata = -1;
}
}
if (dayList[i] == dayListMap_pre[j][0] &&
monthdata == dayListMap_pre[j][2]) {
// print('dayList[i] == dayListMap_pre[j][0]');
// print('dayListMap_pre[j]: ${dayListMap_pre[j]}');
dayListMap_final.add(dayListMap_pre[j]);
j++;
} else {
dayListMap_final.add([dayList[i], 4, monthdata, 4]);
}
}
}
//make the dayListMap_final upto 42 days, add trailing [0,4,1]s
//but we don't update numberOfRows here
//later we hide the rows with all 0s
while (dayListMap_final.length < 42) {
dayListMap_final.add([0, 4, 1, 4]);
}
print('dayListMap_final: $dayListMap_final');
// print('dayListMap_final length: ${dayListMap_final.length}');
//For rounding the corners of the 1st row-1st element and last row last elem,
// if those have streakdata 2 or 3
//if 3, we change to 1
//if 2, we change to 0
List<List<int>> dayListMap_final_round = roundCorners(dayListMap_final);
print('dayListMap_final_round ____1: $dayListMap_final_round');
// print('dayListMap_final_round: $dayListMap_final_round');
List<List<int>> dayListMapColorSet =
Confirm5elem(dayListMapColorSetter(dayListMap_final_round));
print('dayListMapColorSet: $dayListMapColorSet');
return dayListMapColorSet;
}
List<List<int>> Confirm5elem(List<List<int>> dayListMapList) {
List<List<int>> dayListMapListFinal = [];
for (int i = 0; i < dayListMapList.length; i++) {
if (dayListMapList[i].length == 4) {
dayListMapListFinal.add([
dayListMapList[i][0],
dayListMapList[i][1],
dayListMapList[i][2],
dayListMapList[i][3],
dayListMapList[i][1]
]);
} else {
dayListMapListFinal.add(dayListMapList[i]);
}
}
return dayListMapListFinal;
}
List<List<int>> roundCorners(List<List<int>> dayListMap_final_round) {
if (dayListMap_final_round[0][1] == 3) {
dayListMap_final_round[0][1] = 1;
} else if (dayListMap_final_round[0][1] == 2) {
dayListMap_final_round[0][1] = 0;
}
if (dayListMap_final_round[6][1] == 3) {
dayListMap_final_round[6][1] = 2;
} else if (dayListMap_final_round[6][1] == 1) {
dayListMap_final_round[6][1] = 0;
}
if (dayListMap_final_round[7][1] == 3) {
dayListMap_final_round[7][1] = 1;
} else if (dayListMap_final_round[7][1] == 2) {
dayListMap_final_round[7][1] = 0;
}
if (dayListMap_final_round[13][1] == 3) {
dayListMap_final_round[13][1] = 2;
} else if (dayListMap_final_round[13][1] == 1) {
dayListMap_final_round[13][1] = 0;
}
if (dayListMap_final_round[14][1] == 3) {
dayListMap_final_round[14][1] = 1;
} else if (dayListMap_final_round[14][1] == 2) {
dayListMap_final_round[14][1] = 0;
}
if (dayListMap_final_round[20][1] == 3) {
dayListMap_final_round[20][1] = 2;
} else if (dayListMap_final_round[20][1] == 1) {
dayListMap_final_round[20][1] = 0;
}
if (dayListMap_final_round[21][1] == 3) {
dayListMap_final_round[21][1] = 1;
} else if (dayListMap_final_round[21][1] == 2) {
dayListMap_final_round[21][1] = 0;
}
if (dayListMap_final_round[27][1] == 3) {
dayListMap_final_round[27][1] = 2;
} else if (dayListMap_final_round[27][1] == 1) {
dayListMap_final_round[27][1] = 0;
}
if (dayListMap_final_round[28][1] == 3) {
dayListMap_final_round[28][1] = 1;
} else if (dayListMap_final_round[28][1] == 2) {
dayListMap_final_round[28][1] = 0;
}
if (dayListMap_final_round[34][1] == 3) {
dayListMap_final_round[34][1] = 2;
} else if (dayListMap_final_round[34][1] == 1) {
dayListMap_final_round[34][1] = 0;
}
if (dayListMap_final_round[35][1] == 3) {
dayListMap_final_round[35][1] = 1;
} else if (dayListMap_final_round[35][1] == 2) {
dayListMap_final_round[35][1] = 0;
}
if (dayListMap_final_round[41][1] == 3) {
dayListMap_final_round[41][1] = 2;
} else if (dayListMap_final_round[41][1] == 1) {
dayListMap_final_round[41][1] = 0;
}
return dayListMap_final_round;
}
//generating list of days
void generateDayList() {
//Value settings of global variables in this function:
//numberOfRows, dayList
dayList = [];
int prevMonthDays = setNumberofdaysInMonth(selectedMonth - 1);
// int nextMonthDays = setNumberofdaysInMonth(selectedMonth + 1); //Not used
int firstDayWeekDay = DateTime(selectedYear, selectedMonth, 1).weekday;
int lastDayWeekDay =
DateTime(selectedYear, selectedMonth, numberOfDaysInMonth)
.weekday; //Last day of the month
//Number of rows in the calendar
numberOfRows = determineNumberOfRows(
firstDayWeekDay, lastDayWeekDay, numberOfDaysInMonth);
//Adding days of previous month
int startDay = prevMonthDays - firstDayWeekDay + 2;
for (int i = 0; i < firstDayWeekDay - 1; i++) {
dayList.add(startDay + i);
leadingDayList.add(startDay + i);
}
//Adding days of current month
for (int i = 1; i <= numberOfDaysInMonth; i++) {
dayList.add(i);
}
//Adding days of next month
for (int i = 1; i <= 7 - lastDayWeekDay; i++) {
dayList.add(0);
trailingDayList.add(i);
}
//make the dayList upto 42 days, add trailing 0s
//but we don't update numberOfRows here
//later we hide the rows with all 0s
while (dayList.length < 42) {
dayList.add(0);
}
}
//Determining number of rows in the calendar
int determineNumberOfRows(int firstDay, int lastDay, int numberOfDays) {
//no global variables are used in this function //LOCAL FUNCTION
int no_rows = 0;
int startOffset = 8 - firstDay;
int endOffset = lastDay;
//Now, one row for each startOffset and endOffset
//rest of the days are divided by 7
no_rows = (2 + (numberOfDays - startOffset - endOffset) ~/ 7);
return no_rows;
}
//Set number of days in a month
int setNumberofdaysInMonth(choiceMonth) {
//no global variables are used in this function //LOCAL FUNCTION
int entryMonthDays;
List days31months = [1, 3, 5, 7, 8, 10, 12];
List days30months = [4, 6, 9, 11];
//function used inside the Widget build function
if (days31months.contains(choiceMonth)) {
entryMonthDays = 31;
} else if (days30months.contains(choiceMonth)) {
entryMonthDays = 30;
} else {
if (selectedYear % 4 == 0) {
if (selectedYear % 100 == 0) {
if (selectedYear % 400 == 0) {
entryMonthDays = 29;
} else {
entryMonthDays = 28;
}
} else {
entryMonthDays = 29;
}
} else {
entryMonthDays = 28;
}
}
return entryMonthDays;
}
//Building dayListMapList for total view, for Streaks
//[[daylistelem0, 0], [daylistelem1,2],....]
List<List<int>> buildDayListMap() {
circleColorSetter(); //prepares for Circle Color code addition at 4th index
List<List<int>> dayListMapList = [];
List<List<int>> dayListMapListPrevMonth = [];
List<List<int>> dayListMapListNextMonth = [];
//RULE:
//the lists inside the list looks like [27,2,-1]
//1st element is the day, 2nd element is the streak status, 3rd element is the month status
//month status: -1 for previous month, 0 for current month, 1 for next month
//for the leading days
StreakService _leadingStreak = StreakService();
_leadingStreak.streakList = streakList;
_leadingStreak.supplyDate = DateTime(
supplyDate.year, supplyDate.month - 1, 1); //supplyDateForPreviousMonth
_leadingStreak.CalculateStreaks();
if (_leadingStreak.streakListFilter.length > 0) {
for (DateTime dateTime in _leadingStreak.streakListFilter) {
// Check if the key (dateTime) exists in streakListFilterGroup
for (Map<DateTime, int> dateTimeMap
in _leadingStreak.streakListFilterGroup) {
if (dateTimeMap.containsKey(dateTime)) {
dayListMapListPrevMonth.add([
dateTime.day,
dateTimeMap[dateTime]!,
-1,
dateTimeMap[dateTime]!
]);
}
}
}
//Now, we have the dayListMapListPrevMonth
//We check against the leadingDayList, and fill the dayListMapList
for (int i = 0; i < leadingDayList.length; i++) {
for (int j = 0; j < dayListMapListPrevMonth.length; j++) {
if (leadingDayList[i] == dayListMapListPrevMonth[j][0]) {
dayListMapList.add(dayListMapListPrevMonth[j]);
}
}
}
}
//for the current month
StreakService _currentMonthStreak = StreakService();
_currentMonthStreak.streakList = streakList;
_currentMonthStreak.supplyDate = supplyDate;
_currentMonthStreak.CalculateStreaks();
for (DateTime dateTime in _currentMonthStreak.streakListFilter) {
// Check if the key (dateTime) exists in streakListFilterGroup
for (Map<DateTime, int> dateTimeMap
in _currentMonthStreak.streakListFilterGroup) {
if (dateTimeMap.containsKey(dateTime)) {
dayListMapList.add([
dateTime.day,
dateTimeMap[dateTime]!,
0,
dateTimeMap[dateTime]!
]);
}
}
}
//for the trailing days
StreakService _trailingStreak = StreakService();
_trailingStreak.streakList = streakList;
_trailingStreak.supplyDate = supplyDateForNextMonth;
_trailingStreak.CalculateStreaks();
if (_trailingStreak.streakListFilter.length > 0) {
for (DateTime dateTime in _trailingStreak.streakListFilter) {
// Check if the key (dateTime) exists in streakListFilterGroup
for (Map<DateTime, int> dateTimeMap
in _trailingStreak.streakListFilterGroup) {
if (dateTimeMap.containsKey(dateTime)) {
dayListMapListNextMonth.add([
dateTime.day,
dateTimeMap[dateTime]!,
1,
dateTimeMap[dateTime]!
]);
}
}
}
//Now, we have the dayListMapListNextMonth
//We check against the trailingDayList, and fill the dayListMapList
for (int i = 0; i < trailingDayList.length; i++) {
for (int j = 0; j < dayListMapListNextMonth.length; j++) {
if (trailingDayList[i] == dayListMapListNextMonth[j][0]) {
dayListMapList.add(dayListMapListNextMonth[j]);
}
}
}
}
return (dayListMapList);
}
void setStreakData() {
StreakService _streakService = StreakService();
_streakService.streakList = streakList;
_streakService.supplyDate = supplyDate;
_streakService.CalculateStreaks();
_streakService.CalculateStreakData();
longest_Streak = _streakService.longestStreak;
last_Streak = _streakService.lastStreak;
current_StreakIsLastStreak = _streakService.currentStreakIsLastStreak;
}
BorderRadius getBorderRadius(int x, double r) {
switch (x) {
case 0:
return BorderRadius.all(Radius.circular(r));
case 1:
return BorderRadius.only(
topLeft: Radius.circular(r),
bottomLeft: Radius.circular(r),
);
case 2:
return BorderRadius.only(
topRight: Radius.circular(r),
bottomRight: Radius.circular(r),
);
default:
return BorderRadius.zero; // All corners with 0 radius
}
}
Color getRowElementColor(int streakData, int monthData) {
if (streakData != 4) {
switch (monthData) {
case -1:
return streakColorPreviousMonth;
case 0:
return streakColorCurrentMonth;
default:
return Colors.transparent;
}
} else {
return Colors.transparent;
}
}
Color getElemBorderColor(int streakData, int monthData) {
if (streakData != 4) {
switch (monthData) {
case -1:
return streakColorPreviousMonth;
case 0:
return streakColorCurrentMonth;
default:
return Colors.transparent;
}
} else {
return Colors.transparent;
}
}
Color getCircleColor(int streakData, int monthData) {
print('streakData: $streakData');
if (streakData == 4) {
return Colors.transparent;
}
if (streakData >= 0 && monthData == 0) {
print('inside streakData >= 0');
if (streakData == 1) {
return streakStartColor;
} else if (streakData == 2) {
return streakEndColor;
} else if (streakData == 0) {
return streakSingleDayColor;
} else {
return streakColorCurrentMonth;
}
}
if (streakData < 0 && monthData == 0) {
print('streakData negative, colorPaletteList used');
// print(
// 'returning colorPaletteList[${temp - 1}]: ${colorPaletteList[temp - 1]}');
return colorPaletteList[(-streakData) - 1];
// return Colors.transparent;
}
return Colors.transparent;
}
void circleColorSetter() {
currentMonthColorList = [];
if (streakList.length != colorList.length) {
//fill colorList with 4s
for (int i = 0; i < streakList.length; i++) {
colorList.add(0);
}
print('ColorList length is less than streakList length, Does not match');
return;
} else {
//we prepare currentMonthColorList
for (int i = 0; i < streakList.length; i++) {
if (streakList[i].month == supplyDate.month &&
streakList[i].year == supplyDate.year) {
currentMonthColorList.add(colorList[i]);
}
}
}
//NOTE: We would use the streakData field in the Lists for storing Circle Color Data
//since 0,1,2,3,4 are already used for streakData, So we make
//the colorList elements negative, then -1, -2, -3, -4 and so on colors can be used
//Also no restriction on the number of colors, can be any number of colors
//We define getCircleColor() such that, if streakData is negative then it is a color,
//Now we take that negative numeber, make it positive, subtract 1,
//and use that as index for the Color Pallette List
//making the colorList elements negative
for (int i = 0; i < colorList.length; i++) {
colorList[i] = -colorList[i];
}
for (int i = 0; i < currentMonthColorList.length; i++) {
currentMonthColorList[i] = -currentMonthColorList[i];
}
//Rest Setup in buildDayListMap(),
// we add the colorList elems to the dayListMapList accordingly
}
List<List<int>> dayListMapColorSetter(List<List<int>> dayListMapList) {
//modify the DayListMapList with circle colors
print('inside ColorSetter dayListMapList: $dayListMapList');
bool colorFlag = false;
List<List<int>> DayListMapList = [];
for (int i = 0; i < dayListMapList.length; i++) {
DayListMapList.add(dayListMapList[i]);
}
for (int i = 0; i < currentMonthColorList.length; i++) {
if (currentMonthColorList[i] < 0) {
colorFlag = true;
break;
}
}
//Now, this ensures that there are colors in the currentMonthColorList
if (colorFlag == false) {
//we add a 4th element to the dayListMapList, which is the color
for (int i = 0; i < DayListMapList.length; i++) {
int temp = DayListMapList[i][1];
DayListMapList[i].add(temp);
}
return DayListMapList;
} //No colors, return the original list, with added 4th element as original streakData
//If function reaches here, then colorFlag is true,
// so we change the colors in streakData, with negative values
for (int i = 0, j = 0;
i < DayListMapList.length && j < currentMonthColorList.length;
i++) {
//we first check month data, if 0, then we change streakData
if (DayListMapList[i][2] == 0) {
if (DayListMapList[i][1] != 4) {
DayListMapList[i].add(currentMonthColorList[j]);
j++;
}
}
}
print('dayListMapList return: $DayListMapList');
return DayListMapList;
}
Widget calendarBuild(BuildContext context) {
setStreakData();
List<List<int>> dayListMapListFinal;
//TODO: take supplyDate as input
dayListMapListFinal = setValues();
return Container(
padding: EdgeInsets.all(calendarBodyPad),
decoration: BoxDecoration(
border: Border.all(
color: calendarBorderColor,
width: calendarBorderWidth,
),
color: calendarColor,
borderRadius: calendarBorderRadius,
),
child: Column(
children: [
Control(context),
SizedBox(height: controlHeaderGap),
DayNames(context),
SizedBox(height: headerBodyGap),
Calendar(context, dayListMapListFinal),
],
));
}
Widget StreakDataDashboard(BuildContext context) {
return Center(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: streakDashboardBorderColor,
width: streakDashboardBorderWidth,
),
color: streakDashboardColor,
borderRadius: BorderRadius.circular(20),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Center(
child: Column(
children: [
Center(
child: Container(
margin:
EdgeInsets.only(bottom: streakDashboardLineSpace),
child: Text(
'Longest',
style: GoogleFonts.getFont(
streakDashboardFontFamily,
fontSize: streakDashboardFontSize,
fontWeight: streakDashboardFontWeight,
color: streakDashboardFontColor,
),
)),
),
Center(
child: Container(
margin:
EdgeInsets.only(bottom: streakDashboardLineSpace),
child: Text(
'Streak',
style: GoogleFonts.getFont(
streakDashboardFontFamily,
fontSize: streakDashboardFontSize,
fontWeight: streakDashboardFontWeight,
color: streakDashboardFontColor,
),
)),
),
Center(
child: Text(
'$longest_Streak',
style: GoogleFonts.getFont(
streakDashboardFontFamily,
fontSize: streakDashboardDigitFontSize,
fontWeight: streakDashboardDigitFontWeight,
color: streakDashboardDigitFontColor,
),
)),
],
),
),
Container(
//vertical divider
height: streakDashboardDividerHeight,
child: Container(
width: streakDashboardDividerThickness,
decoration: BoxDecoration(
border: Border.all(
color: streakDashboardDividerColor,
width: 0,
),
color: streakDashboardDividerColor,
borderRadius: BorderRadius.circular(100))),
),
Center(
child: Column(
children: [
Center(
child: Text(current_StreakIsLastStreak ? 'Current' : 'Last',
style: GoogleFonts.getFont(
streakDashboardFontFamily,
fontSize: streakDashboardFontSize,
fontWeight: streakDashboardFontWeight,
color: streakDashboardFontColor,
)),
),
Center(
child: Text('Streak',
style: GoogleFonts.getFont(
streakDashboardFontFamily,
fontSize: streakDashboardFontSize,
fontWeight: streakDashboardFontWeight,
color: streakDashboardFontColor,
)),
),
Center(
child: Text(
'$last_Streak',
style: GoogleFonts.getFont(
streakDashboardFontFamily,
fontSize: streakDashboardDigitFontSize,
fontWeight: streakDashboardDigitFontWeight,
color: streakDashboardDigitFontColor,
),
)),
],
),
),
],
),
),
);
}
Widget Control(BuildContext context) {
Map monthNameMap = {
1: 'January',
2: 'February',
3: 'March',
4: 'April',
5: 'May',
6: 'June',
7: 'July',
8: 'August',
9: 'September',
10: 'October',
11: 'November',
12: 'December'
};
return Container(
child: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
setValues();
backButtonFunction();
}),
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: controlBorderColor,
width: controlBorderWidth,
),
color: controlcolor,
borderRadius: controlBorderRadius,
),
child: Center(
child: Text(
'${monthNameMap[selectedMonth]} $selectedYear',
style: GoogleFonts.getFont(
controlFontFamily,
fontSize: controlFontSize,
fontWeight: controlFontWeight,
color: controlFontColor,
),
),
),
),
),
IconButton(
icon: Icon(Icons.arrow_forward_ios),
onPressed: () {
setValues();
forwardButtonFunction();
}),
],
),
);
}
Widget DayNames(BuildContext context) {
//Setting day names
if (dayNameLetters == 3) {
dayNames = dayNames3letters;
} else if (dayNameLetters == 2) {
dayNames = dayNames2letters;
} else {
dayNames = dayNames3letters; //Default //Other options can be added later
}
BoxDecoration headerElemDecor = BoxDecoration(
border: Border.all(
color: headerElemBorderColor,
width: headerElemBorderWidth,
),
color: headerElemcolor,
borderRadius: headerElemBorderRadius,
);
headerSidePad = bodyRowHorizontalPad + bodyRowSidePad;
return Container(
padding: EdgeInsets.symmetric(
horizontal: headerSidePad, vertical: headerUpDownPad),
decoration: BoxDecoration(
border: Border.all(
color: headerBorderColor,
width: headerBorderWidth,
),
color: headercolor,
borderRadius: headerBorderRadius,
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [