From a1307801934f237bd29ddeb390baf9c1a59c4de1 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 15 Nov 2023 16:41:38 +0300 Subject: [PATCH] chart improvement --- .../progress_fragment.dart | 135 +++++++++--------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/lib/new_views/pages/land_page/dashboard_fragments/progress_fragment.dart b/lib/new_views/pages/land_page/dashboard_fragments/progress_fragment.dart index 8a956ce9..7a97d79a 100644 --- a/lib/new_views/pages/land_page/dashboard_fragments/progress_fragment.dart +++ b/lib/new_views/pages/land_page/dashboard_fragments/progress_fragment.dart @@ -21,73 +21,78 @@ class ProgressFragment extends StatelessWidget { @override Widget build(BuildContext context) { - const Map statuses = { - "Completed": 12, - "In Progress": 12, - "Open": 12, - }; return Consumer( - builder: (context, snapshot, _) => Column( - children: [ - AspectRatio( - aspectRatio: 398 / 237, - child: PieChart( - dataMap: statuses, - animationDuration: const Duration(milliseconds: 500), - chartRadius: 190.toScreenWidth, - colorList: [AColors.statusGreen, AColors.statusBlue, AColors.statusYellowLight], - initialAngleInDegree: 270, - chartType: ChartType.ring, - ringStrokeWidth: 40.toScreenWidth, - centerText: "${context.translation.total}\n20", - centerTextStyle: AppTextStyles.heading5.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), - legendOptions: const LegendOptions(showLegends: false), - chartValuesOptions: ChartValuesOptions( - chartValueBackgroundColor: Colors.transparent, - chartValueStyle: AppTextStyles.heading6.copyWith(color: AppColor.neutral20), - showChartValuesOutside: true, - ), - ).toShimmer(isShow: snapshot.isOpenLoading || snapshot.isInProgressLoading || snapshot.isCompleteLoading, radius: 300).paddingAll(12).toShadowContainer(context), - ).paddingOnly(start: 16, end: 16, bottom: 16), - DefaultTabController( - length: 3, - child: Column( - children: [ - Container( - margin: const EdgeInsets.only(left: 16, right: 16), - decoration: BoxDecoration(color: AppColor.neutral30, borderRadius: BorderRadius.circular(16)), - child: TabBar( - //controller: _tabController, - padding: EdgeInsets.zero, - labelColor: AppColor.neutral60, - unselectedLabelColor: AppColor.neutral20, - unselectedLabelStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF757575)), - labelStyle: AppTextStyles.bodyText.copyWith(color: AppColor.neutral60), - indicatorPadding: const EdgeInsets.all(4), - indicator: BoxDecoration(color: context.isDark? AppColor.neutral20:Theme.of(context).cardColor, borderRadius: BorderRadius.circular(13)), - onTap: (index) { - // setState(() {}); - }, - tabs: [ - Tab(text: context.translation.open, height: 57.toScreenHeight), - Tab(text: context.translation.inProgress, height: 57.toScreenHeight), - Tab(text: context.translation.completed, height: 57.toScreenHeight), - ], - ), + builder: (context, snapshot, _) { + Map statuses = { + "Completed": snapshot.completedRequests?.requestsDetails?.length?.toDouble() ?? 0.0, + "In Progress": snapshot.inProgressRequests?.requestsDetails?.length?.toDouble() ?? 0.0, + "Open": snapshot.openRequests.requestsDetails?.length?.toDouble() ?? 0.0, + }; + int total = (snapshot.completedRequests?.requestsDetails?.length ?? 0) + (snapshot.inProgressRequests?.requestsDetails?.length ?? 0) + (snapshot.openRequests?.requestsDetails?.length ?? 0); + + return Column( + children: [ + AspectRatio( + aspectRatio: 398 / 237, + child: PieChart( + dataMap: statuses, + animationDuration: const Duration(milliseconds: 500), + chartRadius: 190.toScreenWidth, + colorList: [AColors.statusGreen, AColors.statusBlue, AColors.statusYellowLight], + initialAngleInDegree: 270, + chartType: ChartType.ring, + ringStrokeWidth: 40.toScreenWidth, + centerText: "${context.translation.total}\n$total", + centerTextStyle: AppTextStyles.heading5.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), + legendOptions: const LegendOptions(showLegends: false), + chartValuesOptions: ChartValuesOptions( + chartValueBackgroundColor: Colors.white, + showChartValuesInPercentage: true, + chartValueStyle: AppTextStyles.heading6.copyWith(color: AppColor.neutral20), + showChartValuesOutside: true, ), - 8.height, - TabBarView( - children: [ - RequestItemViewList(snapshot.openRequests?.requestsDetails ?? [], snapshot.isOpenLoading), - RequestItemViewList(snapshot.inProgressRequests?.requestsDetails ?? [], snapshot.isInProgressLoading), - RequestItemViewList(snapshot.completedRequests?.requestsDetails ?? [], snapshot.isCompleteLoading), - ], - ).expanded, - ], - ), - ).expanded, - ], - ), + ).toShimmer(isShow: snapshot.isOpenLoading || snapshot.isInProgressLoading || snapshot.isCompleteLoading, radius: 300).paddingAll(12).toShadowContainer(context), + ).paddingOnly(start: 16, end: 16, bottom: 16), + DefaultTabController( + length: 3, + child: Column( + children: [ + Container( + margin: const EdgeInsets.only(left: 16, right: 16), + decoration: BoxDecoration(color: AppColor.neutral30, borderRadius: BorderRadius.circular(16)), + child: TabBar( + //controller: _tabController, + padding: EdgeInsets.zero, + labelColor: AppColor.neutral60, + unselectedLabelColor: AppColor.neutral20, + unselectedLabelStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF757575)), + labelStyle: AppTextStyles.bodyText.copyWith(color: AppColor.neutral60), + indicatorPadding: const EdgeInsets.all(4), + indicator: BoxDecoration(color: context.isDark ? AppColor.neutral20 : Theme.of(context).cardColor, borderRadius: BorderRadius.circular(13)), + onTap: (index) { + // setState(() {}); + }, + tabs: [ + Tab(text: context.translation.open, height: 57.toScreenHeight), + Tab(text: context.translation.inProgress, height: 57.toScreenHeight), + Tab(text: context.translation.completed, height: 57.toScreenHeight), + ], + ), + ), + 8.height, + TabBarView( + children: [ + RequestItemViewList(snapshot.openRequests?.requestsDetails ?? [], snapshot.isOpenLoading), + RequestItemViewList(snapshot.inProgressRequests?.requestsDetails ?? [], snapshot.isInProgressLoading), + RequestItemViewList(snapshot.completedRequests?.requestsDetails ?? [], snapshot.isCompleteLoading), + ], + ).expanded, + ], + ), + ).expanded, + ], + ); + }, ); } //