@@ -9,74 +9,50 @@ import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart';
99import 'package:taskwarrior/app/utils/constants/utilites.dart' ;
1010import 'package:taskwarrior/app/utils/theme/app_settings.dart' ;
1111
12- class BurnDownDailyTaskc extends StatefulWidget {
13- const BurnDownDailyTaskc ({super .key});
12+ class BurnDownDailyTaskc extends StatelessWidget {
13+ BurnDownDailyTaskc ({super .key});
1414
15- @override
16- State <BurnDownDailyTaskc > createState () => _BurnDownDailyTaskcState ();
17- }
18-
19- class _BurnDownDailyTaskcState extends State <BurnDownDailyTaskc >
20- with TickerProviderStateMixin {
21- late TaskDatabase taskDatabase;
22- late TooltipBehavior _dailyBurndownTooltipBehaviour;
23- Map <String , Map <String , int >> dailyInfo = {};
24-
25- @override
26- void initState () {
27- super .initState ();
28-
29- // Initialize the tooltip behavior for the chart
30- _dailyBurndownTooltipBehaviour = TooltipBehavior (
31- enable: true ,
32- builder: (dynamic data, dynamic point, dynamic series, int pointIndex,
33- int seriesIndex) {
34- final String date = data.x;
35- final int pendingCount = data.y1;
36- final int completedCount = data.y2;
15+ final TooltipBehavior _dailyBurndownTooltipBehaviour = TooltipBehavior (
16+ enable: true ,
17+ builder: (dynamic data, dynamic point, dynamic series, int pointIndex,
18+ int seriesIndex) {
19+ final String date = data.x;
20+ final int pendingCount = data.y1;
21+ final int completedCount = data.y2;
3722
38- return Container (
39- padding: const EdgeInsets .all (10 ),
40- decoration: BoxDecoration (
41- color: Colors .white,
42- borderRadius: BorderRadius .circular (5 ),
43- ),
44- child: Column (
45- crossAxisAlignment: CrossAxisAlignment .start,
46- mainAxisSize: MainAxisSize .min,
47- children: [
48- Text (
49- 'Date: $date ' ,
50- style: GoogleFonts .poppins (
51- fontWeight: TaskWarriorFonts .bold,
52- ),
53- ),
54- Text (
55- 'Pending: $pendingCount ' ,
56- ),
57- Text (
58- 'Completed: $completedCount ' ,
23+ return Container (
24+ padding: const EdgeInsets .all (10 ),
25+ decoration: BoxDecoration (
26+ color: Colors .white,
27+ borderRadius: BorderRadius .circular (5 ),
28+ ),
29+ child: Column (
30+ crossAxisAlignment: CrossAxisAlignment .start,
31+ mainAxisSize: MainAxisSize .min,
32+ children: [
33+ Text (
34+ 'Date: $date ' ,
35+ style: GoogleFonts .poppins (
36+ fontWeight: TaskWarriorFonts .bold,
5937 ),
60- ],
61- ),
62- );
63- },
64- );
38+ ),
39+ Text ('Pending: $pendingCount ' ),
40+ Text ('Completed: $completedCount ' ),
41+ ],
42+ ),
43+ );
44+ },
45+ );
6546
66- // Initialize the database and fetch data
67- taskDatabase = TaskDatabase ();
68- taskDatabase.open ().then ((_) {
69- taskDatabase.fetchTasksFromDatabase ().then ((tasks) {
70- setState (() {
71- // Process the data and update the chart
72- _processData (tasks);
73- });
74- });
75- });
47+ Future <Map <String , Map <String , int >>> fetchDailyInfo () async {
48+ TaskDatabase taskDatabase = TaskDatabase ();
49+ await taskDatabase.open ();
50+ List <Tasks > tasks = await taskDatabase.fetchTasksFromDatabase ();
51+ return _processData (tasks);
7652 }
7753
78- void _processData (List <Tasks > tasks) {
79- dailyInfo = {};
54+ Map < String , Map < String , int >> _processData (List <Tasks > tasks) {
55+ Map < String , Map < String , int >> dailyInfo = {};
8056
8157 // Sort tasks by entry date in ascending order
8258 tasks.sort ((a, b) => a.entry.compareTo (b.entry));
@@ -98,80 +74,101 @@ class _BurnDownDailyTaskcState extends State<BurnDownDailyTaskc>
9874 };
9975 }
10076 }
77+
78+ return dailyInfo;
10179 }
10280
10381 @override
10482 Widget build (BuildContext context) {
10583 double height = MediaQuery .of (context).size.height; // Screen height
10684
107- return Column (
108- mainAxisAlignment: MainAxisAlignment .center,
109- crossAxisAlignment: CrossAxisAlignment .center,
110- children: [
111- Expanded (
112- child: SizedBox (
113- height: height * 0.6 ,
114- child: SfCartesianChart (
115- primaryXAxis: CategoryAxis (
116- title: AxisTitle (
117- text: 'Day - Month' ,
118- textStyle: GoogleFonts .poppins (
119- fontWeight: TaskWarriorFonts .bold,
120- color: AppSettings .isDarkMode ? Colors .white : Colors .black,
121- fontSize: TaskWarriorFonts .fontSizeSmall,
85+ return FutureBuilder <Map <String , Map <String , int >>>(
86+ future: fetchDailyInfo (),
87+ builder: (context, snapshot) {
88+ if (snapshot.connectionState == ConnectionState .waiting) {
89+ return const Center (child: CircularProgressIndicator ());
90+ }
91+
92+ if (snapshot.hasError) {
93+ return Center (child: Text ('Error: ${snapshot .error }' ));
94+ }
95+
96+ Map <String , Map <String , int >> dailyInfo = snapshot.data ?? {};
97+
98+ return Column (
99+ mainAxisAlignment: MainAxisAlignment .center,
100+ crossAxisAlignment: CrossAxisAlignment .center,
101+ children: [
102+ Expanded (
103+ child: SizedBox (
104+ height: height * 0.6 ,
105+ child: SfCartesianChart (
106+ primaryXAxis: CategoryAxis (
107+ title: AxisTitle (
108+ text: 'Day - Month' ,
109+ textStyle: GoogleFonts .poppins (
110+ fontWeight: TaskWarriorFonts .bold,
111+ color: AppSettings .isDarkMode
112+ ? Colors .white
113+ : Colors .black,
114+ fontSize: TaskWarriorFonts .fontSizeSmall,
115+ ),
116+ ),
122117 ),
123- ),
124- ),
125- primaryYAxis: NumericAxis (
126- title: AxisTitle (
127- text: 'Tasks' ,
128- textStyle: GoogleFonts .poppins (
129- fontWeight: TaskWarriorFonts .bold,
130- fontSize: TaskWarriorFonts .fontSizeSmall,
131- color: AppSettings .isDarkMode ? Colors .white : Colors .black,
118+ primaryYAxis: NumericAxis (
119+ title: AxisTitle (
120+ text: 'Tasks' ,
121+ textStyle: GoogleFonts .poppins (
122+ fontWeight: TaskWarriorFonts .bold,
123+ fontSize: TaskWarriorFonts .fontSizeSmall,
124+ color: AppSettings .isDarkMode
125+ ? Colors .white
126+ : Colors .black,
127+ ),
128+ ),
132129 ),
130+ tooltipBehavior: _dailyBurndownTooltipBehaviour,
131+ series: < ChartSeries > [
132+ StackedColumnSeries <ChartData , String >(
133+ groupName: 'Group A' ,
134+ enableTooltip: true ,
135+ color: TaskWarriorColors .green,
136+ dataSource: dailyInfo.entries
137+ .map ((entry) => ChartData (
138+ entry.key,
139+ entry.value['pending' ] ?? 0 ,
140+ entry.value['completed' ] ?? 0 ,
141+ ))
142+ .toList (),
143+ xValueMapper: (ChartData data, _) => data.x,
144+ yValueMapper: (ChartData data, _) => data.y2,
145+ name: 'Completed' ,
146+ ),
147+ StackedColumnSeries <ChartData , String >(
148+ groupName: 'Group A' ,
149+ color: TaskWarriorColors .yellow,
150+ enableTooltip: true ,
151+ dataSource: dailyInfo.entries
152+ .map ((entry) => ChartData (
153+ entry.key,
154+ entry.value['pending' ] ?? 0 ,
155+ entry.value['completed' ] ?? 0 ,
156+ ))
157+ .toList (),
158+ xValueMapper: (ChartData data, _) => data.x,
159+ yValueMapper: (ChartData data, _) => data.y1,
160+ name: 'Pending' ,
161+ ),
162+ ],
133163 ),
134164 ),
135- tooltipBehavior: _dailyBurndownTooltipBehaviour,
136- series: < ChartSeries > [
137- StackedColumnSeries <ChartData , String >(
138- groupName: 'Group A' ,
139- enableTooltip: true ,
140- color: TaskWarriorColors .green,
141- dataSource: dailyInfo.entries
142- .map ((entry) => ChartData (
143- entry.key,
144- entry.value['pending' ] ?? 0 ,
145- entry.value['completed' ] ?? 0 ,
146- ))
147- .toList (),
148- xValueMapper: (ChartData data, _) => data.x,
149- yValueMapper: (ChartData data, _) => data.y2,
150- name: 'Completed' ,
151- ),
152- StackedColumnSeries <ChartData , String >(
153- groupName: 'Group A' ,
154- color: TaskWarriorColors .yellow,
155- enableTooltip: true ,
156- dataSource: dailyInfo.entries
157- .map ((entry) => ChartData (
158- entry.key,
159- entry.value['pending' ] ?? 0 ,
160- entry.value['completed' ] ?? 0 ,
161- ))
162- .toList (),
163- xValueMapper: (ChartData data, _) => data.x,
164- yValueMapper: (ChartData data, _) => data.y1,
165- name: 'Pending' ,
166- ),
167- ],
168165 ),
169- ),
170- ) ,
171- const CommonChartIndicator (
172- title : 'Daily Burndown Chart' ,
173- ),
174- ] ,
166+ const CommonChartIndicator (
167+ title : 'Daily Burndown Chart' ,
168+ ),
169+ ] ,
170+ );
171+ } ,
175172 );
176173 }
177174}
0 commit comments