11import 'package:flutter/material.dart' ;
2- import 'package:get/get.dart' ;
32import 'package:google_fonts/google_fonts.dart' ;
43import 'package:taskwarrior/api_service.dart' ;
54import 'package:taskwarrior/app/modules/reports/controllers/reports_controller.dart' ;
@@ -9,165 +8,140 @@ import 'package:taskwarrior/app/modules/reports/views/burn_down_weekly_taskc.dar
98import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart' ;
109import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart' ;
1110import 'package:taskwarrior/app/utils/theme/app_settings.dart' ;
12- import 'package:tutorial_coach_mark/tutorial_coach_mark.dart' ;
1311
14- class ReportsHomeTaskc extends StatefulWidget {
15- const ReportsHomeTaskc ({
16- super .key,
17- });
12+ class ReportsHomeTaskc extends StatelessWidget {
13+ final ReportsController reportsController = ReportsController ();
14+ final TaskDatabase taskDatabase = TaskDatabase ();
1815
19- @override
20- State <ReportsHomeTaskc > createState () => _ReportsHomeTaskcState ();
21- }
22-
23- class _ReportsHomeTaskcState extends State <ReportsHomeTaskc >
24- with TickerProviderStateMixin {
25- late TabController _tabController;
26- final GlobalKey daily = GlobalKey ();
27- final GlobalKey weekly = GlobalKey ();
28- final GlobalKey monthly = GlobalKey ();
16+ ReportsHomeTaskc ({super .key});
2917
30- bool isSaved = false ;
31- late TutorialCoachMark tutorialCoachMark;
32- late ReportsController reportsController;
33- int _selectedIndex = 0 ;
34- late TaskDatabase taskDatabase;
35- List <Tasks > allTasks = [];
36-
37- @override
38- void initState () {
39- super .initState ();
40- reportsController = Get .find <ReportsController >();
41- reportsController.initReportsTour ();
42- reportsController.showReportsTour (context);
43- _tabController = TabController (length: 3 , vsync: this );
44-
45- // Initialize the database and fetch data
46- taskDatabase = TaskDatabase ();
47- taskDatabase.open ().then ((_) {
48- taskDatabase.fetchTasksFromDatabase ().then ((tasks) {
49- setState (() {
50- allTasks = tasks;
51- });
52- });
53- });
18+ Future <List <Tasks >> fetchTasks () async {
19+ await taskDatabase.open ();
20+ return await taskDatabase.fetchTasksFromDatabase ();
5421 }
5522
5623 @override
5724 Widget build (BuildContext context) {
58- double height = MediaQuery .of (context).size.height; // Screen height
25+ double height = MediaQuery .of (context).size.height;
26+ reportsController.initReportsTour ();
27+ reportsController.showReportsTour (context);
28+ return FutureBuilder <List <Tasks >>(
29+ future: fetchTasks (),
30+ builder: (context, snapshot) {
31+ List <Tasks > allTasks = snapshot.data ?? [];
5932
60- return Scaffold (
61- appBar: AppBar (
62- backgroundColor: TaskWarriorColors .kprimaryBackgroundColor,
63- title: Text (
64- 'Reports' ,
65- style: GoogleFonts .poppins (color: TaskWarriorColors .white),
66- ),
67- leading: GestureDetector (
68- onTap: () {
69- Navigator .pop (context);
70- },
71- child: Icon (
72- Icons .chevron_left,
73- color: TaskWarriorColors .white,
74- ),
75- ),
76- bottom: PreferredSize (
77- preferredSize: Size .fromHeight (
78- height * 0.1 ), // Adjust the preferred height as needed
79- child: TabBar (
80- controller: _tabController,
81- labelColor: TaskWarriorColors .white,
82- labelStyle: GoogleFonts .poppins (
83- fontWeight: TaskWarriorFonts .medium,
84- fontSize: TaskWarriorFonts .fontSizeSmall,
33+ return Scaffold (
34+ appBar: AppBar (
35+ backgroundColor: TaskWarriorColors .kprimaryBackgroundColor,
36+ title: Text (
37+ 'Reports' ,
38+ style: GoogleFonts .poppins (color: TaskWarriorColors .white),
8539 ),
86- unselectedLabelStyle: GoogleFonts .poppins (
87- fontWeight: TaskWarriorFonts .light,
88- ),
89- onTap: (value) {
90- setState (() {
91- _selectedIndex = value;
92- });
93- },
94- tabs: < Widget > [
95- Tab (
96- key: daily,
97- icon: const Icon (Icons .schedule),
98- text: 'Daily' ,
99- iconMargin: const EdgeInsets .only (bottom: 0.0 ),
100- ),
101- Tab (
102- key: weekly,
103- icon: const Icon (Icons .today),
104- text: 'Weekly' ,
105- iconMargin: const EdgeInsets .only (bottom: 0.0 ),
106- ),
107- Tab (
108- key: monthly,
109- icon: const Icon (Icons .date_range),
110- text: 'Monthly' ,
111- iconMargin: const EdgeInsets .only (bottom: 0.0 ),
40+ leading: GestureDetector (
41+ onTap: () {
42+ Navigator .pop (context);
43+ },
44+ child: Icon (
45+ Icons .chevron_left,
46+ color: TaskWarriorColors .white,
11247 ),
113- ],
114- ),
115- ),
116- ),
117- backgroundColor: AppSettings .isDarkMode
118- ? TaskWarriorColors .kprimaryBackgroundColor
119- : TaskWarriorColors .white,
120- body: allTasks.isEmpty
121- ? Column (
122- mainAxisAlignment: MainAxisAlignment .center,
123- crossAxisAlignment: CrossAxisAlignment .center,
124- children: [
125- Icon (
126- Icons .heart_broken,
127- color: AppSettings .isDarkMode
128- ? TaskWarriorColors .white
129- : TaskWarriorColors .black,
130- ),
131- Row (
132- mainAxisAlignment: MainAxisAlignment .center,
133- children: [
134- Text (
135- 'No Task found' ,
136- style: GoogleFonts .poppins (
137- fontWeight: TaskWarriorFonts .medium,
138- fontSize: TaskWarriorFonts .fontSizeSmall,
139- color: AppSettings .isDarkMode
140- ? TaskWarriorColors .white
141- : TaskWarriorColors .black,
142- ),
143- ),
144- ],
48+ ),
49+ bottom: PreferredSize (
50+ preferredSize: Size .fromHeight (height * 0.1 ),
51+ child: TabBar (
52+ controller: reportsController.tabController,
53+ labelColor: TaskWarriorColors .white,
54+ labelStyle: GoogleFonts .poppins (
55+ fontWeight: TaskWarriorFonts .medium,
56+ fontSize: TaskWarriorFonts .fontSizeSmall,
14557 ),
146- Row (
147- mainAxisAlignment: MainAxisAlignment .center,
148- children: [
149- Text (
150- 'Add a task to see reports' ,
151- style: GoogleFonts .poppins (
152- fontWeight: TaskWarriorFonts .light,
153- fontSize: TaskWarriorFonts .fontSizeSmall,
154- color: AppSettings .isDarkMode
155- ? TaskWarriorColors .white
156- : TaskWarriorColors .black,
157- ),
158- ),
159- ],
58+ unselectedLabelStyle: GoogleFonts .poppins (
59+ fontWeight: TaskWarriorFonts .light,
16060 ),
161- ],
162- )
163- : IndexedStack (
164- index: _selectedIndex,
165- children: const [
166- BurnDownDailyTaskc (),
167- BurnDownWeeklyTask (),
168- BurnDownMonthlyTaskc (),
169- ],
61+ onTap: (value) {
62+ reportsController.selectedIndex.value = value;
63+ },
64+ tabs: < Widget > [
65+ Tab (
66+ key: reportsController.daily,
67+ icon: const Icon (Icons .schedule),
68+ text: 'Daily' ,
69+ iconMargin: const EdgeInsets .only (bottom: 0.0 ),
70+ ),
71+ Tab (
72+ key: reportsController.weekly,
73+ icon: const Icon (Icons .today),
74+ text: 'Weekly' ,
75+ iconMargin: const EdgeInsets .only (bottom: 0.0 ),
76+ ),
77+ Tab (
78+ key: reportsController.monthly,
79+ icon: const Icon (Icons .date_range),
80+ text: 'Monthly' ,
81+ iconMargin: const EdgeInsets .only (bottom: 0.0 ),
82+ ),
83+ ],
84+ ),
17085 ),
86+ ),
87+ backgroundColor: AppSettings .isDarkMode
88+ ? TaskWarriorColors .kprimaryBackgroundColor
89+ : TaskWarriorColors .white,
90+ body: snapshot.connectionState == ConnectionState .waiting
91+ ? const Center (child: CircularProgressIndicator ())
92+ : allTasks.isEmpty
93+ ? Column (
94+ mainAxisAlignment: MainAxisAlignment .center,
95+ crossAxisAlignment: CrossAxisAlignment .center,
96+ children: [
97+ Icon (
98+ Icons .heart_broken,
99+ color: AppSettings .isDarkMode
100+ ? TaskWarriorColors .white
101+ : TaskWarriorColors .black,
102+ ),
103+ Row (
104+ mainAxisAlignment: MainAxisAlignment .center,
105+ children: [
106+ Text (
107+ 'No Task found' ,
108+ style: GoogleFonts .poppins (
109+ fontWeight: TaskWarriorFonts .medium,
110+ fontSize: TaskWarriorFonts .fontSizeSmall,
111+ color: AppSettings .isDarkMode
112+ ? TaskWarriorColors .white
113+ : TaskWarriorColors .black,
114+ ),
115+ ),
116+ ],
117+ ),
118+ Row (
119+ mainAxisAlignment: MainAxisAlignment .center,
120+ children: [
121+ Text (
122+ 'Add a task to see reports' ,
123+ style: GoogleFonts .poppins (
124+ fontWeight: TaskWarriorFonts .light,
125+ fontSize: TaskWarriorFonts .fontSizeSmall,
126+ color: AppSettings .isDarkMode
127+ ? TaskWarriorColors .white
128+ : TaskWarriorColors .black,
129+ ),
130+ ),
131+ ],
132+ ),
133+ ],
134+ )
135+ : IndexedStack (
136+ index: reportsController.selectedIndex.value,
137+ children: const [
138+ BurnDownDailyTaskc (),
139+ BurnDownWeeklyTask (),
140+ BurnDownMonthlyTaskc (),
141+ ],
142+ ),
143+ );
144+ },
171145 );
172146 }
173147}
0 commit comments