From 8aa5612ed0d80c88908a9b5c43bf9547b63e65f6 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Jul 2024 15:17:24 +0530 Subject: [PATCH] fix: fixed reports for taskc --- lib/app/modules/home/views/nav_drawer.dart | 36 ++- .../controllers/reports_controller.dart | 8 +- .../reports/views/burn_down_daily_taskc.dart | 247 ++++++++-------- .../views/burn_down_monthly_taskc.dart | 260 ++++++++--------- .../reports/views/burn_down_weekly_taskc.dart | 273 +++++++++--------- .../reports/views/reports_view_taskc.dart | 21 +- 6 files changed, 430 insertions(+), 415 deletions(-) diff --git a/lib/app/modules/home/views/nav_drawer.dart b/lib/app/modules/home/views/nav_drawer.dart index 3822d8e..2904963 100644 --- a/lib/app/modules/home/views/nav_drawer.dart +++ b/lib/app/modules/home/views/nav_drawer.dart @@ -5,6 +5,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:taskwarrior/app/modules/home/controllers/home_controller.dart'; import 'package:taskwarrior/app/modules/home/views/home_page_nav_drawer_menu_item.dart'; import 'package:taskwarrior/app/modules/home/views/theme_clipper.dart'; +import 'package:taskwarrior/app/modules/reports/views/reports_view_taskc.dart'; import 'package:taskwarrior/app/routes/app_pages.dart'; import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart'; import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart'; @@ -183,15 +184,32 @@ class NavDrawer extends StatelessWidget { ), ), ), - Obx( - () => NavDrawerMenuItem( - icon: Icons.summarize, - text: SentenceManager( - currentLanguage: homeController.selectedLanguage.value, - ).sentences.navDrawerReports, - onTap: () { - Get.toNamed(Routes.REPORTS); - }, + Visibility( + visible: !homeController.taskchampion.value, + child: Obx( + () => NavDrawerMenuItem( + icon: Icons.summarize, + text: SentenceManager( + currentLanguage: homeController.selectedLanguage.value, + ).sentences.navDrawerReports, + onTap: () { + Get.toNamed(Routes.REPORTS); + }, + ), + ), + ), + Visibility( + visible: homeController.taskchampion.value, + child: Obx( + () => NavDrawerMenuItem( + icon: Icons.summarize, + text: SentenceManager( + currentLanguage: homeController.selectedLanguage.value, + ).sentences.navDrawerReports, + onTap: () { + Get.to(() => ReportsHomeTaskc()); + }, + ), ), ), Obx( diff --git a/lib/app/modules/reports/controllers/reports_controller.dart b/lib/app/modules/reports/controllers/reports_controller.dart index abfe98f..739f4b963 100644 --- a/lib/app/modules/reports/controllers/reports_controller.dart +++ b/lib/app/modules/reports/controllers/reports_controller.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; +import 'package:taskwarrior/api_service.dart'; import 'package:taskwarrior/app/models/json/task.dart'; import 'package:taskwarrior/app/models/storage.dart'; import 'package:taskwarrior/app/modules/home/controllers/home_controller.dart'; @@ -24,7 +25,7 @@ class ReportsController extends GetxController final GlobalKey daily = GlobalKey(); final GlobalKey weekly = GlobalKey(); final GlobalKey monthly = GlobalKey(); - + late TaskDatabase taskDatabase; var isSaved = false.obs; late TutorialCoachMark tutorialCoachMark; @@ -344,6 +345,11 @@ class ReportsController extends GetxController }); } + Future> fetchTasks() async { + await taskDatabase.open(); + return await taskDatabase.fetchTasksFromDatabase(); + } + // monthly report late TooltipBehavior monthlyBurndownTooltipBehaviour; RxMap> monthlyInfo = diff --git a/lib/app/modules/reports/views/burn_down_daily_taskc.dart b/lib/app/modules/reports/views/burn_down_daily_taskc.dart index 59a7aa4..ed9e946 100644 --- a/lib/app/modules/reports/views/burn_down_daily_taskc.dart +++ b/lib/app/modules/reports/views/burn_down_daily_taskc.dart @@ -9,74 +9,50 @@ import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart'; import 'package:taskwarrior/app/utils/constants/utilites.dart'; import 'package:taskwarrior/app/utils/theme/app_settings.dart'; -class BurnDownDailyTaskc extends StatefulWidget { - const BurnDownDailyTaskc({super.key}); +class BurnDownDailyTaskc extends StatelessWidget { + BurnDownDailyTaskc({super.key}); - @override - State createState() => _BurnDownDailyTaskcState(); -} - -class _BurnDownDailyTaskcState extends State - with TickerProviderStateMixin { - late TaskDatabase taskDatabase; - late TooltipBehavior _dailyBurndownTooltipBehaviour; - Map> dailyInfo = {}; - - @override - void initState() { - super.initState(); - - // Initialize the tooltip behavior for the chart - _dailyBurndownTooltipBehaviour = TooltipBehavior( - enable: true, - builder: (dynamic data, dynamic point, dynamic series, int pointIndex, - int seriesIndex) { - final String date = data.x; - final int pendingCount = data.y1; - final int completedCount = data.y2; + final TooltipBehavior _dailyBurndownTooltipBehaviour = TooltipBehavior( + enable: true, + builder: (dynamic data, dynamic point, dynamic series, int pointIndex, + int seriesIndex) { + final String date = data.x; + final int pendingCount = data.y1; + final int completedCount = data.y2; - return Container( - padding: const EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(5), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - 'Date: $date', - style: GoogleFonts.poppins( - fontWeight: TaskWarriorFonts.bold, - ), - ), - Text( - 'Pending: $pendingCount', - ), - Text( - 'Completed: $completedCount', + return Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(5), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Date: $date', + style: GoogleFonts.poppins( + fontWeight: TaskWarriorFonts.bold, ), - ], - ), - ); - }, - ); + ), + Text('Pending: $pendingCount'), + Text('Completed: $completedCount'), + ], + ), + ); + }, + ); - // Initialize the database and fetch data - taskDatabase = TaskDatabase(); - taskDatabase.open().then((_) { - taskDatabase.fetchTasksFromDatabase().then((tasks) { - setState(() { - // Process the data and update the chart - _processData(tasks); - }); - }); - }); + Future>> fetchDailyInfo() async { + TaskDatabase taskDatabase = TaskDatabase(); + await taskDatabase.open(); + List tasks = await taskDatabase.fetchTasksFromDatabase(); + return _processData(tasks); } - void _processData(List tasks) { - dailyInfo = {}; + Map> _processData(List tasks) { + Map> dailyInfo = {}; // Sort tasks by entry date in ascending order tasks.sort((a, b) => a.entry.compareTo(b.entry)); @@ -98,80 +74,101 @@ class _BurnDownDailyTaskcState extends State }; } } + + return dailyInfo; } @override Widget build(BuildContext context) { double height = MediaQuery.of(context).size.height; // Screen height - return Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - child: SizedBox( - height: height * 0.6, - child: SfCartesianChart( - primaryXAxis: CategoryAxis( - title: AxisTitle( - text: 'Day - Month', - textStyle: GoogleFonts.poppins( - fontWeight: TaskWarriorFonts.bold, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - fontSize: TaskWarriorFonts.fontSizeSmall, + return FutureBuilder>>( + future: fetchDailyInfo(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } + + if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } + + Map> dailyInfo = snapshot.data ?? {}; + + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: SizedBox( + height: height * 0.6, + child: SfCartesianChart( + primaryXAxis: CategoryAxis( + title: AxisTitle( + text: 'Day - Month', + textStyle: GoogleFonts.poppins( + fontWeight: TaskWarriorFonts.bold, + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + fontSize: TaskWarriorFonts.fontSizeSmall, + ), + ), ), - ), - ), - primaryYAxis: NumericAxis( - title: AxisTitle( - text: 'Tasks', - textStyle: GoogleFonts.poppins( - fontWeight: TaskWarriorFonts.bold, - fontSize: TaskWarriorFonts.fontSizeSmall, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, + primaryYAxis: NumericAxis( + title: AxisTitle( + text: 'Tasks', + textStyle: GoogleFonts.poppins( + fontWeight: TaskWarriorFonts.bold, + fontSize: TaskWarriorFonts.fontSizeSmall, + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + ), + ), ), + tooltipBehavior: _dailyBurndownTooltipBehaviour, + series: [ + StackedColumnSeries( + groupName: 'Group A', + enableTooltip: true, + color: TaskWarriorColors.green, + dataSource: dailyInfo.entries + .map((entry) => ChartData( + entry.key, + entry.value['pending'] ?? 0, + entry.value['completed'] ?? 0, + )) + .toList(), + xValueMapper: (ChartData data, _) => data.x, + yValueMapper: (ChartData data, _) => data.y2, + name: 'Completed', + ), + StackedColumnSeries( + groupName: 'Group A', + color: TaskWarriorColors.yellow, + enableTooltip: true, + dataSource: dailyInfo.entries + .map((entry) => ChartData( + entry.key, + entry.value['pending'] ?? 0, + entry.value['completed'] ?? 0, + )) + .toList(), + xValueMapper: (ChartData data, _) => data.x, + yValueMapper: (ChartData data, _) => data.y1, + name: 'Pending', + ), + ], ), ), - tooltipBehavior: _dailyBurndownTooltipBehaviour, - series: [ - StackedColumnSeries( - groupName: 'Group A', - enableTooltip: true, - color: TaskWarriorColors.green, - dataSource: dailyInfo.entries - .map((entry) => ChartData( - entry.key, - entry.value['pending'] ?? 0, - entry.value['completed'] ?? 0, - )) - .toList(), - xValueMapper: (ChartData data, _) => data.x, - yValueMapper: (ChartData data, _) => data.y2, - name: 'Completed', - ), - StackedColumnSeries( - groupName: 'Group A', - color: TaskWarriorColors.yellow, - enableTooltip: true, - dataSource: dailyInfo.entries - .map((entry) => ChartData( - entry.key, - entry.value['pending'] ?? 0, - entry.value['completed'] ?? 0, - )) - .toList(), - xValueMapper: (ChartData data, _) => data.x, - yValueMapper: (ChartData data, _) => data.y1, - name: 'Pending', - ), - ], ), - ), - ), - const CommonChartIndicator( - title: 'Daily Burndown Chart', - ), - ], + const CommonChartIndicator( + title: 'Daily Burndown Chart', + ), + ], + ); + }, ); } } diff --git a/lib/app/modules/reports/views/burn_down_monthly_taskc.dart b/lib/app/modules/reports/views/burn_down_monthly_taskc.dart index 3e75115..2d1477f 100644 --- a/lib/app/modules/reports/views/burn_down_monthly_taskc.dart +++ b/lib/app/modules/reports/views/burn_down_monthly_taskc.dart @@ -9,75 +9,54 @@ import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart'; import 'package:taskwarrior/app/utils/constants/utilites.dart'; import 'package:taskwarrior/app/utils/theme/app_settings.dart'; -class BurnDownMonthlyTaskc extends StatefulWidget { - const BurnDownMonthlyTaskc({super.key}); - - @override - State createState() => _BurnDownMonthlyTaskcState(); -} - -class _BurnDownMonthlyTaskcState extends State - with TickerProviderStateMixin { - late TaskDatabase taskDatabase; - Map> monthlyInfo = {}; - - late TooltipBehavior _weeklyBurndownTooltipBehaviour; - - @override - void initState() { - super.initState(); - - _weeklyBurndownTooltipBehaviour = TooltipBehavior( - enable: true, - builder: (dynamic data, dynamic point, dynamic series, int pointIndex, - int seriesIndex) { - final String monthYear = data.x; - final int pendingCount = data.y1; - final int completedCount = data.y2; - - return Container( - padding: const EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(5), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - 'Month-Year: $monthYear', - style: const TextStyle( - fontWeight: TaskWarriorFonts.bold, - ), - ), - Text( - 'Pending: $pendingCount', - ), - Text( - 'Completed: $completedCount', +class BurnDownMonthlyTaskc extends StatelessWidget { + BurnDownMonthlyTaskc({super.key}); + + final _monthlyBurndownTooltipBehaviour = TooltipBehavior( + enable: true, + builder: (dynamic data, dynamic point, dynamic series, int pointIndex, + int seriesIndex) { + final String monthYear = data.x; + final int pendingCount = data.y1; + final int completedCount = data.y2; + + return Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(5), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Month-Year: $monthYear', + style: const TextStyle( + fontWeight: TaskWarriorFonts.bold, ), - ], - ), - ); - }, - ); - - taskDatabase = TaskDatabase(); - - ///fetch all data from the database - fetchAllData(); - } - - void fetchAllData() async { - List allData = await taskDatabase.fetchTasksFromDatabase(); - if (allData.isNotEmpty) { - sortBurnDownMonthly(allData); - } + ), + Text( + 'Pending: $pendingCount', + ), + Text( + 'Completed: $completedCount', + ), + ], + ), + ); + }, + ); + + Future>> fetchMonthlyInfo() async { + TaskDatabase taskDatabase = TaskDatabase(); + await taskDatabase.open(); + List tasks = await taskDatabase.fetchTasksFromDatabase(); + return sortBurnDownMonthly(tasks); } - void sortBurnDownMonthly(List allData) { - monthlyInfo = {}; + Map> sortBurnDownMonthly(List allData) { + Map> monthlyInfo = {}; allData.sort((a, b) => a.entry.compareTo(b.entry)); @@ -103,82 +82,99 @@ class _BurnDownMonthlyTaskcState extends State } debugPrint("monthlyInfo: $monthlyInfo"); - - // Update the state to refresh the chart - setState(() {}); + return monthlyInfo; } @override Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; - return Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - child: SizedBox( - height: height * 0.6, - child: SfCartesianChart( - primaryXAxis: CategoryAxis( - title: AxisTitle( - text: 'Month - Year', - textStyle: GoogleFonts.poppins( - fontWeight: TaskWarriorFonts.bold, - fontSize: TaskWarriorFonts.fontSizeSmall, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, + + return FutureBuilder>>( + future: fetchMonthlyInfo(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } + + if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } + + Map> monthlyInfo = snapshot.data ?? {}; + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: SizedBox( + height: height * 0.6, + child: SfCartesianChart( + primaryXAxis: CategoryAxis( + title: AxisTitle( + text: 'Month - Year', + textStyle: GoogleFonts.poppins( + fontWeight: TaskWarriorFonts.bold, + fontSize: TaskWarriorFonts.fontSizeSmall, + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + ), + ), ), - ), - ), - primaryYAxis: NumericAxis( - title: AxisTitle( - text: 'Tasks', - textStyle: GoogleFonts.poppins( - fontWeight: TaskWarriorFonts.bold, - fontSize: TaskWarriorFonts.fontSizeSmall, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, + primaryYAxis: NumericAxis( + title: AxisTitle( + text: 'Tasks', + textStyle: GoogleFonts.poppins( + fontWeight: TaskWarriorFonts.bold, + fontSize: TaskWarriorFonts.fontSizeSmall, + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + ), + ), ), + tooltipBehavior: _monthlyBurndownTooltipBehaviour, + series: [ + StackedColumnSeries( + groupName: 'Group A', + enableTooltip: true, + color: TaskWarriorColors.green, + dataSource: monthlyInfo.entries + .map((entry) => ChartData( + entry.key, + entry.value['pending'] ?? 0, + entry.value['completed'] ?? 0, + )) + .toList(), + xValueMapper: (ChartData data, _) => data.x, + yValueMapper: (ChartData data, _) => data.y2, + name: 'Completed', + ), + StackedColumnSeries( + groupName: 'Group A', + color: TaskWarriorColors.yellow, + enableTooltip: true, + dataSource: monthlyInfo.entries + .map((entry) => ChartData( + entry.key, + entry.value['pending'] ?? 0, + entry.value['completed'] ?? 0, + )) + .toList(), + xValueMapper: (ChartData data, _) => data.x, + yValueMapper: (ChartData data, _) => data.y1, + name: 'Pending', + ), + ], ), ), - tooltipBehavior: _weeklyBurndownTooltipBehaviour, - series: [ - StackedColumnSeries( - groupName: 'Group A', - enableTooltip: true, - color: TaskWarriorColors.green, - dataSource: monthlyInfo.entries - .map((entry) => ChartData( - entry.key, - entry.value['pending'] ?? 0, - entry.value['completed'] ?? 0, - )) - .toList(), - xValueMapper: (ChartData data, _) => data.x, - yValueMapper: (ChartData data, _) => data.y2, - name: 'Completed', - ), - StackedColumnSeries( - groupName: 'Group A', - color: TaskWarriorColors.yellow, - enableTooltip: true, - dataSource: monthlyInfo.entries - .map((entry) => ChartData( - entry.key, - entry.value['pending'] ?? 0, - entry.value['completed'] ?? 0, - )) - .toList(), - xValueMapper: (ChartData data, _) => data.x, - yValueMapper: (ChartData data, _) => data.y1, - name: 'Pending', - ), - ], ), - ), - ), - const CommonChartIndicator( - title: 'Monthly Burndown Chart', - ) - ], + const CommonChartIndicator( + title: 'Monthly Burndown Chart', + ), + ], + ); + }, ); } } diff --git a/lib/app/modules/reports/views/burn_down_weekly_taskc.dart b/lib/app/modules/reports/views/burn_down_weekly_taskc.dart index 193600a..6d2430d 100644 --- a/lib/app/modules/reports/views/burn_down_weekly_taskc.dart +++ b/lib/app/modules/reports/views/burn_down_weekly_taskc.dart @@ -9,76 +9,55 @@ import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart'; import 'package:taskwarrior/app/utils/constants/utilites.dart'; import 'package:taskwarrior/app/utils/theme/app_settings.dart'; -class BurnDownWeeklyTask extends StatefulWidget { - const BurnDownWeeklyTask({super.key}); - - @override - State createState() => _BurnDownWeeklyTaskState(); -} - -class _BurnDownWeeklyTaskState extends State - with TickerProviderStateMixin { - late TaskDatabase taskDatabase; - late TooltipBehavior _weeklyBurndownTooltipBehaviour; - Map> weeklyInfo = {}; - - @override - void initState() { - super.initState(); - - ///initialize the _weeklyBurndownTooltipBehaviour tooltip behavior - _weeklyBurndownTooltipBehaviour = TooltipBehavior( - enable: true, - builder: (dynamic data, dynamic point, dynamic series, int pointIndex, - int seriesIndex) { - final String weekNumber = data.x; - final int pendingCount = data.y1; - final int completedCount = data.y2; - - return Container( - padding: const EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(5), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - weekNumber, - style: const TextStyle( - fontWeight: TaskWarriorFonts.bold, - ), - ), - Text( - 'Pending: $pendingCount', - ), - Text( - 'Completed: $completedCount', +class BurnDownWeeklyTask extends StatelessWidget { + BurnDownWeeklyTask({super.key}); + + final TooltipBehavior _weeklyBurndownTooltipBehaviour = TooltipBehavior( + enable: true, + builder: (dynamic data, dynamic point, dynamic series, int pointIndex, + int seriesIndex) { + final String weekNumber = data.x; + final int pendingCount = data.y1; + final int completedCount = data.y2; + + return Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(5), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + weekNumber, + style: const TextStyle( + fontWeight: TaskWarriorFonts.bold, ), - ], - ), - ); - }, - ); - - taskDatabase = TaskDatabase(); - - ///fetch all data from the database - fetchAllData(); - } - - void fetchAllData() async { - List allData = await taskDatabase.fetchTasksFromDatabase(); - if (allData.isNotEmpty) { - sortBurnDownWeekly(allData); - } + ), + Text( + 'Pending: $pendingCount', + ), + Text( + 'Completed: $completedCount', + ), + ], + ), + ); + }, + ); + + Future>> fetchWeeklyInfo() async { + TaskDatabase taskDatabase = TaskDatabase(); + await taskDatabase.open(); + List tasks = await taskDatabase.fetchTasksFromDatabase(); + return sortBurnDownWeekly(tasks); } - void sortBurnDownWeekly(List allData) { + Map> sortBurnDownWeekly(List allData) { // Initialize weeklyInfo map - weeklyInfo = {}; + Map> weeklyInfo = {}; // Sort allData by entry date in ascending order allData.sort((a, b) => a.entry.compareTo(b.entry)); @@ -102,7 +81,8 @@ class _BurnDownWeeklyTaskState extends State } } else { ///if weeklyInfo does not contain the week number - weeklyInfo[weekNumber] = { + // ignore: collection_methods_unrelated_type + weeklyInfo[weekNumber.toString()] = { 'pending': allData[i].status == 'pending' ? 1 : 0, 'completed': allData[i].status == 'completed' ? 1 : 0, }; @@ -110,86 +90,101 @@ class _BurnDownWeeklyTaskState extends State } debugPrint("weeklyInfo $weeklyInfo"); - - // Update the state to refresh the chart - setState(() {}); + return weeklyInfo; } @override Widget build(BuildContext context) { double height = MediaQuery.of(context).size.height; // Screen height - - return Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - child: SizedBox( - height: height * 0.6, - child: SfCartesianChart( - primaryXAxis: CategoryAxis( - title: AxisTitle( - text: 'Weeks - Year', - textStyle: GoogleFonts.poppins( - fontWeight: TaskWarriorFonts.bold, - fontSize: TaskWarriorFonts.fontSizeSmall, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, + return FutureBuilder>>( + future: fetchWeeklyInfo(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } + + if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } + + Map> weeklyInfo = snapshot.data ?? {}; + + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: SizedBox( + height: height * 0.6, + child: SfCartesianChart( + primaryXAxis: CategoryAxis( + title: AxisTitle( + text: 'Weeks - Year', + textStyle: GoogleFonts.poppins( + fontWeight: TaskWarriorFonts.bold, + fontSize: TaskWarriorFonts.fontSizeSmall, + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + ), + ), + ), + primaryYAxis: NumericAxis( + title: AxisTitle( + text: 'Tasks', + textStyle: GoogleFonts.poppins( + fontWeight: TaskWarriorFonts.bold, + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + fontSize: TaskWarriorFonts.fontSizeSmall, + ), + ), + ), + tooltipBehavior: _weeklyBurndownTooltipBehaviour, + series: [ + ///this is the completed tasks + StackedColumnSeries( + groupName: 'Group A', + enableTooltip: true, + color: TaskWarriorColors.green, + dataSource: weeklyInfo.entries + .map((entry) => ChartData( + 'Week ${entry.key}', + entry.value['pending'] ?? 0, + entry.value['completed'] ?? 0, + )) + .toList(), + xValueMapper: (ChartData data, _) => data.x, + yValueMapper: (ChartData data, _) => data.y2, + name: 'Completed', + ), + + ///this is the pending tasks + StackedColumnSeries( + groupName: 'Group A', + color: TaskWarriorColors.yellow, + enableTooltip: true, + dataSource: weeklyInfo.entries + .map((entry) => ChartData( + 'Week ${entry.key}', + entry.value['pending'] ?? 0, + entry.value['completed'] ?? 0, + )) + .toList(), + xValueMapper: (ChartData data, _) => data.x, + yValueMapper: (ChartData data, _) => data.y1, + name: 'Pending', + ), + ], ), ), ), - primaryYAxis: NumericAxis( - title: AxisTitle( - text: 'Tasks', - textStyle: GoogleFonts.poppins( - fontWeight: TaskWarriorFonts.bold, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - fontSize: TaskWarriorFonts.fontSizeSmall, - ), - ), + const CommonChartIndicator( + title: 'Weekly Burndown Chart', ), - tooltipBehavior: _weeklyBurndownTooltipBehaviour, - series: [ - ///this is the completed tasks - StackedColumnSeries( - groupName: 'Group A', - enableTooltip: true, - color: TaskWarriorColors.green, - dataSource: weeklyInfo.entries - .map((entry) => ChartData( - 'Week ${entry.key}', - entry.value['pending'] ?? 0, - entry.value['completed'] ?? 0, - )) - .toList(), - xValueMapper: (ChartData data, _) => data.x, - yValueMapper: (ChartData data, _) => data.y2, - name: 'Completed', - ), - - ///this is the pending tasks - StackedColumnSeries( - groupName: 'Group A', - color: TaskWarriorColors.yellow, - enableTooltip: true, - dataSource: weeklyInfo.entries - .map((entry) => ChartData( - 'Week ${entry.key}', - entry.value['pending'] ?? 0, - entry.value['completed'] ?? 0, - )) - .toList(), - xValueMapper: (ChartData data, _) => data.x, - yValueMapper: (ChartData data, _) => data.y1, - name: 'Pending', - ), - ], - ), - ), - ), - const CommonChartIndicator( - title: 'Weekly Burndown Chart', - ), - ], - ); + ], + ); + }); } } diff --git a/lib/app/modules/reports/views/reports_view_taskc.dart b/lib/app/modules/reports/views/reports_view_taskc.dart index 7b5cf61..202f9eb 100644 --- a/lib/app/modules/reports/views/reports_view_taskc.dart +++ b/lib/app/modules/reports/views/reports_view_taskc.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:taskwarrior/api_service.dart'; +import 'package:get/get.dart'; import 'package:taskwarrior/app/modules/reports/controllers/reports_controller.dart'; import 'package:taskwarrior/app/modules/reports/views/burn_down_daily_taskc.dart'; import 'package:taskwarrior/app/modules/reports/views/burn_down_monthly_taskc.dart'; @@ -8,9 +8,10 @@ import 'package:taskwarrior/app/modules/reports/views/burn_down_weekly_taskc.dar import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart'; import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart'; import 'package:taskwarrior/app/utils/theme/app_settings.dart'; +import 'package:taskwarrior/api_service.dart'; class ReportsHomeTaskc extends StatelessWidget { - final ReportsController reportsController = ReportsController(); + final ReportsController reportsController = Get.put(ReportsController()); final TaskDatabase taskDatabase = TaskDatabase(); ReportsHomeTaskc({super.key}); @@ -132,13 +133,15 @@ class ReportsHomeTaskc extends StatelessWidget { ), ], ) - : IndexedStack( - index: reportsController.selectedIndex.value, - children: const [ - BurnDownDailyTaskc(), - BurnDownWeeklyTask(), - BurnDownMonthlyTaskc(), - ], + : Obx( + () => IndexedStack( + index: reportsController.selectedIndex.value, + children: [ + BurnDownDailyTaskc(), + BurnDownWeeklyTask(), + BurnDownMonthlyTaskc(), + ], + ), ), ); },