From dcad9560dacf63539a60fcf4637784aea6fc58f0 Mon Sep 17 00:00:00 2001 From: Uttkarsh-raj Date: Sat, 4 Nov 2023 23:01:31 +0530 Subject: [PATCH] urgents page done --- .../plannerly/lib/bloc/home/home_bloc.dart | 21 +- Frontend/plannerly/lib/screens/home/home.dart | 823 +++++++++--------- .../urgent_tasks/urgent_tasks_page.dart | 298 ++++--- .../plannerly/lib/screens/widgets/task.dart | 2 +- 4 files changed, 607 insertions(+), 537 deletions(-) diff --git a/Frontend/plannerly/lib/bloc/home/home_bloc.dart b/Frontend/plannerly/lib/bloc/home/home_bloc.dart index 1c26c4d..4ef7355 100644 --- a/Frontend/plannerly/lib/bloc/home/home_bloc.dart +++ b/Frontend/plannerly/lib/bloc/home/home_bloc.dart @@ -89,6 +89,16 @@ class HomeBloc extends Bloc { urgent: task["urgent"], ); }).toList(); + emit( + HomeLoadedSuccessState( + regualarTasks, + urgentTasks, + totalUrgentTasks, + totalRegularTasks, + urgentTasksCompleted, + regularTasksCompleted, + ), + ); } else { emit(HomeUnableTofetchTasks(message: response["error"])); } @@ -96,17 +106,6 @@ class HomeBloc extends Bloc { emit(HomeUnableTofetchTasks(message: "Unable to get the data.")); log(e.toString()); } - - emit( - HomeLoadedSuccessState( - regualarTasks, - urgentTasks, - totalUrgentTasks, - totalRegularTasks, - urgentTasksCompleted, - regularTasksCompleted, - ), - ); } FutureOr homeUrgentTasksViewAllClickedEvent( diff --git a/Frontend/plannerly/lib/screens/home/home.dart b/Frontend/plannerly/lib/screens/home/home.dart index 7e0085d..214a9e0 100644 --- a/Frontend/plannerly/lib/screens/home/home.dart +++ b/Frontend/plannerly/lib/screens/home/home.dart @@ -93,21 +93,7 @@ class _HomeScreenState extends State { ), ); ScaffoldMessenger.of(context).showSnackBar(snackBar); - } - // else if (state is HomeNewTaskAddedState) { - // var snackBar = SnackBar( - // backgroundColor: Colors.red[500], - // content: Text( - // "state.message", - // style: const TextStyle( - // fontSize: 16, - // color: AppColors.white, - // ), - // ), - // ); - // ScaffoldMessenger.of(context).showSnackBar(snackBar); - // } - else if (state is HomeNewTaskAddedState) { + } else if (state is HomeNewTaskAddedState) { showDialog( context: context, builder: (BuildContext context) { @@ -238,450 +224,459 @@ class _HomeScreenState extends State { padding: const EdgeInsets.all(14.0), child: Stack( children: [ - SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox(height: size.height * 0.03), - const Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Icon( - Icons.menu_outlined, - size: 28, - color: AppColors.white, - ), - Icon( - Icons.notifications_outlined, - size: 28, - color: AppColors.white, - ), - ], - ), - SizedBox(height: size.height * 0.03), - const Text( - "Hi, Jason", - style: TextStyle( - color: AppColors.white, - fontSize: 18, - fontWeight: FontWeight.w300, + RefreshIndicator( + onRefresh: () async { + homeBloc.add(HomeInitialEvent()); + }, + child: SingleChildScrollView( + physics: const AlwaysScrollableScrollPhysics(), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox(height: size.height * 0.03), + const Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon( + Icons.menu_outlined, + size: 28, + color: AppColors.white, + ), + Icon( + Icons.notifications_outlined, + size: 28, + color: AppColors.white, + ), + ], ), - ), - SizedBox(height: size.height * 0.01), - const Text( - "Be productivity today", - style: TextStyle( - color: AppColors.white, - fontSize: 24, - fontWeight: FontWeight.w500, - ), - ), - SizedBox(height: size.height * 0.038), - Center( - child: Container( - decoration: BoxDecoration( - color: AppColors.backgroundLight, - borderRadius: BorderRadius.circular(18), + SizedBox(height: size.height * 0.03), + const Text( + "Hi, Jason", + style: TextStyle( + color: AppColors.white, + fontSize: 18, + fontWeight: FontWeight.w300, ), - child: Padding( - padding: const EdgeInsets.all(5.0), - child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - const Expanded( - child: TextField( - decoration: InputDecoration( - border: InputBorder.none, - hintText: 'Search task', - hintStyle: TextStyle( - color: AppColors.grey, - fontSize: 18, + ), + SizedBox(height: size.height * 0.01), + const Text( + "Be productivity today", + style: TextStyle( + color: AppColors.white, + fontSize: 24, + fontWeight: FontWeight.w500, + ), + ), + SizedBox(height: size.height * 0.038), + Center( + child: Container( + decoration: BoxDecoration( + color: AppColors.backgroundLight, + borderRadius: BorderRadius.circular(18), + ), + child: Padding( + padding: const EdgeInsets.all(5.0), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + const Expanded( + child: TextField( + decoration: InputDecoration( + border: InputBorder.none, + hintText: 'Search task', + hintStyle: TextStyle( + color: AppColors.grey, + fontSize: 18, + ), + contentPadding: EdgeInsets.all(10), ), - contentPadding: EdgeInsets.all(10), ), ), - ), - IconButton( - onPressed: () {}, - icon: Icon( - Icons.search_outlined, - size: 28, - color: AppColors.white.withOpacity(0.6), + IconButton( + onPressed: () {}, + icon: Icon( + Icons.search_outlined, + size: 28, + color: + AppColors.white.withOpacity(0.6), + ), ), - ), - ], + ], + ), ), ), ), - ), - SizedBox(height: size.height * 0.025), - Center( - child: Container( - decoration: BoxDecoration( - color: AppColors.backgroundLight, - borderRadius: BorderRadius.circular(18), - ), - child: Padding( - padding: const EdgeInsets.all(18.0), - child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - const Text( - "Task Progress", - style: TextStyle( - color: AppColors.white, - fontSize: 20, - fontWeight: FontWeight.w400, + SizedBox(height: size.height * 0.025), + Center( + child: Container( + decoration: BoxDecoration( + color: AppColors.backgroundLight, + borderRadius: BorderRadius.circular(18), + ), + child: Padding( + padding: const EdgeInsets.all(18.0), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + const Text( + "Task Progress", + style: TextStyle( + color: AppColors.white, + fontSize: 20, + fontWeight: FontWeight.w400, + ), ), - ), - const SizedBox(height: 8), - Text( - "${state.totalRegularTasksCompleted + state.totalUrgentTasksCompleted}/${state.totalRegularTasks + state.totalUrgentTasks} task completed.", - style: TextStyle( - color: AppColors.white - .withOpacity(0.4), - fontSize: 14, - fontWeight: FontWeight.w400, + const SizedBox(height: 8), + Text( + "${state.totalRegularTasksCompleted + state.totalUrgentTasksCompleted}/${state.totalRegularTasks + state.totalUrgentTasks} task completed.", + style: TextStyle( + color: AppColors.white + .withOpacity(0.4), + fontSize: 14, + fontWeight: FontWeight.w400, + ), ), - ), - ], - ), - ), - Stack( - children: [ - SizedBox( - height: size.height * 0.07, - width: size.height * 0.07, - child: CircularProgressIndicator( - value: ((state.totalRegularTasksCompleted + - state - .totalUrgentTasksCompleted) == - 0) - ? 0 - : (state.totalRegularTasksCompleted + - state - .totalUrgentTasksCompleted) / - (state.totalRegularTasks + - state.totalUrgentTasks), - strokeWidth: 7, - valueColor: - const AlwaysStoppedAnimation( - AppColors.buttonBlue), - backgroundColor: AppColors.white - .withOpacity(0.2), - color: AppColors.white, - ), + ], ), - SizedBox( - height: size.height * 0.07, - width: size.height * 0.07, - child: Center( - child: Text( - ((state.totalRegularTasksCompleted + + ), + Stack( + children: [ + SizedBox( + height: size.height * 0.07, + width: size.height * 0.07, + child: CircularProgressIndicator( + value: ((state.totalRegularTasksCompleted + state .totalUrgentTasksCompleted) == 0) - ? "0%" - : "${((state.totalRegularTasksCompleted + state.totalUrgentTasksCompleted) / (state.totalRegularTasks + state.totalUrgentTasks) * 100).toStringAsFixed(1)}%", - style: TextStyle( - color: AppColors.white - .withOpacity(0.8), - fontSize: 18, - fontWeight: FontWeight.w600, + ? 0 + : (state.totalRegularTasksCompleted + + state + .totalUrgentTasksCompleted) / + (state.totalRegularTasks + + state + .totalUrgentTasks), + strokeWidth: 7, + valueColor: + const AlwaysStoppedAnimation( + AppColors.buttonBlue), + backgroundColor: AppColors.white + .withOpacity(0.2), + color: AppColors.white, + ), + ), + SizedBox( + height: size.height * 0.07, + width: size.height * 0.07, + child: Center( + child: Text( + ((state.totalRegularTasksCompleted + + state + .totalUrgentTasksCompleted) == + 0) + ? "0%" + : "${((state.totalRegularTasksCompleted + state.totalUrgentTasksCompleted) / (state.totalRegularTasks + state.totalUrgentTasks) * 100).toStringAsFixed(1)}%", + style: TextStyle( + color: AppColors.white + .withOpacity(0.8), + fontSize: 18, + fontWeight: FontWeight.w600, + ), ), ), ), + ], + ), + ], + ), + ), + ), + ), + SizedBox(height: size.height * 0.04), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Container( + height: size.height * 0.25, + width: size.width * 0.45, + decoration: BoxDecoration( + color: AppColors.backgroundLight, + borderRadius: BorderRadius.circular(18), + ), + child: Padding( + padding: const EdgeInsets.all(5.0) + .copyWith(top: 12, bottom: 12), + child: Column( + children: [ + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + const Text( + "Urgent Tasks Progress", + textAlign: TextAlign.center, + style: TextStyle( + color: AppColors.white, + fontSize: 18, + fontWeight: FontWeight.w500, + ), + ), + const SizedBox(height: 20), + Center( + child: Stack( + children: [ + SizedBox( + height: size.height * 0.1, + width: size.height * 0.1, + child: + CircularProgressIndicator( + value: (state + .totalUrgentTasksCompleted == + 0) + ? 0 + : (state.totalUrgentTasksCompleted / + state + .totalUrgentTasks), + strokeWidth: 7, + valueColor: + AlwaysStoppedAnimation( + Colors.red[400]), + backgroundColor: AppColors + .white + .withOpacity(0.2), + color: AppColors.white, + ), + ), + SizedBox( + height: size.height * 0.1, + width: size.height * 0.1, + child: Center( + child: Text( + (state.totalUrgentTasksCompleted == + 0) + ? "0%" + : "${((state.totalUrgentTasksCompleted / state.totalUrgentTasks) * 100).toStringAsFixed(1)}%", + style: TextStyle( + color: AppColors.white + .withOpacity(0.8), + fontSize: 22, + fontWeight: + FontWeight.w600, + ), + ), + ), + ), + ], + ), + ), + const SizedBox(height: 16), + Center( + child: Text( + "${state.totalUrgentTasksCompleted}/${state.totalUrgentTasks}", + style: TextStyle( + color: AppColors.white + .withOpacity(0.4), + fontSize: 22, + fontWeight: FontWeight.w400, + ), + ), + ), + ], ), ], ), - ], + ), ), - ), - ), - ), - SizedBox(height: size.height * 0.04), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - height: size.height * 0.25, - width: size.width * 0.45, - decoration: BoxDecoration( - color: AppColors.backgroundLight, - borderRadius: BorderRadius.circular(18), - ), - child: Padding( - padding: const EdgeInsets.all(5.0) - .copyWith(top: 12, bottom: 12), - child: Column( - children: [ - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - const Text( - "Urgent Tasks Progress", - textAlign: TextAlign.center, - style: TextStyle( - color: AppColors.white, - fontSize: 18, - fontWeight: FontWeight.w500, + Container( + height: size.height * 0.25, + width: size.width * 0.45, + decoration: BoxDecoration( + color: AppColors.backgroundLight, + borderRadius: BorderRadius.circular(18), + ), + child: Padding( + padding: const EdgeInsets.all(5.0) + .copyWith(top: 12, bottom: 12), + child: Column( + children: [ + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + const Text( + "Regular Tasks Progress", + textAlign: TextAlign.center, + style: TextStyle( + color: AppColors.white, + fontSize: 18, + fontWeight: FontWeight.w500, + ), ), - ), - const SizedBox(height: 20), - Center( - child: Stack( - children: [ - SizedBox( - height: size.height * 0.1, - width: size.height * 0.1, - child: - CircularProgressIndicator( - value: (state - .totalUrgentTasksCompleted == - 0) - ? 0 - : (state.totalUrgentTasksCompleted / - state - .totalUrgentTasks), - strokeWidth: 7, - valueColor: - AlwaysStoppedAnimation( - Colors.red[400]), - backgroundColor: AppColors - .white - .withOpacity(0.2), - color: AppColors.white, - ), - ), - SizedBox( - height: size.height * 0.1, - width: size.height * 0.1, - child: Center( - child: Text( - (state.totalUrgentTasksCompleted == + const SizedBox(height: 20), + Center( + child: Stack( + children: [ + SizedBox( + height: size.height * 0.1, + width: size.height * 0.1, + child: + CircularProgressIndicator( + value: (state + .totalRegularTasksCompleted == 0) - ? "0%" - : "${((state.totalUrgentTasksCompleted / state.totalUrgentTasks) * 100).toStringAsFixed(1)}%", - style: TextStyle( - color: AppColors.white - .withOpacity(0.8), - fontSize: 22, - fontWeight: - FontWeight.w600, + ? 0 + : (state.totalRegularTasksCompleted / + state + .totalRegularTasks), + strokeWidth: 7, + valueColor: + AlwaysStoppedAnimation( + Colors + .green[400]), + backgroundColor: AppColors + .white + .withOpacity(0.2), + color: AppColors.white, + ), + ), + SizedBox( + height: size.height * 0.1, + width: size.height * 0.1, + child: Center( + child: Text( + (state.totalRegularTasksCompleted == + 0) + ? "0%" + : "${((state.totalRegularTasksCompleted / state.totalRegularTasks) * 100).toStringAsFixed(1)}%", + style: TextStyle( + color: AppColors.white + .withOpacity(0.8), + fontSize: 22, + fontWeight: + FontWeight.w600, + ), ), ), ), - ), - ], - ), - ), - const SizedBox(height: 16), - Center( - child: Text( - "${state.totalUrgentTasksCompleted}/${state.totalUrgentTasks}", - style: TextStyle( - color: AppColors.white - .withOpacity(0.4), - fontSize: 22, - fontWeight: FontWeight.w400, + ], ), ), - ), - ], - ), - ], - ), - ), - ), - Container( - height: size.height * 0.25, - width: size.width * 0.45, - decoration: BoxDecoration( - color: AppColors.backgroundLight, - borderRadius: BorderRadius.circular(18), - ), - child: Padding( - padding: const EdgeInsets.all(5.0) - .copyWith(top: 12, bottom: 12), - child: Column( - children: [ - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - const Text( - "Regular Tasks Progress", - textAlign: TextAlign.center, - style: TextStyle( - color: AppColors.white, - fontSize: 18, - fontWeight: FontWeight.w500, - ), - ), - const SizedBox(height: 20), - Center( - child: Stack( - children: [ - SizedBox( - height: size.height * 0.1, - width: size.height * 0.1, - child: - CircularProgressIndicator( - value: (state - .totalRegularTasksCompleted == - 0) - ? 0 - : (state.totalRegularTasksCompleted / - state - .totalRegularTasks), - strokeWidth: 7, - valueColor: - AlwaysStoppedAnimation( - Colors.green[400]), - backgroundColor: AppColors - .white - .withOpacity(0.2), - color: AppColors.white, - ), + const SizedBox(height: 16), + Center( + child: Text( + "${state.totalRegularTasksCompleted}/${state.totalRegularTasks}", + style: TextStyle( + color: AppColors.white + .withOpacity(0.4), + fontSize: 22, + fontWeight: FontWeight.w400, ), - SizedBox( - height: size.height * 0.1, - width: size.height * 0.1, - child: Center( - child: Text( - (state.totalRegularTasksCompleted == - 0) - ? "0%" - : "${((state.totalRegularTasksCompleted / state.totalRegularTasks) * 100).toStringAsFixed(1)}%", - style: TextStyle( - color: AppColors.white - .withOpacity(0.8), - fontSize: 22, - fontWeight: - FontWeight.w600, - ), - ), - ), - ), - ], - ), - ), - const SizedBox(height: 16), - Center( - child: Text( - "${state.totalRegularTasksCompleted}/${state.totalRegularTasks}", - style: TextStyle( - color: AppColors.white - .withOpacity(0.4), - fontSize: 22, - fontWeight: FontWeight.w400, ), ), - ), - ], - ), - ], + ], + ), + ], + ), ), ), - ), - ], - ), - SizedBox(height: size.height * 0.045), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - "Urgent Tasks", - style: TextStyle( - color: AppColors.white, - fontSize: 24, - fontWeight: FontWeight.w500, - ), - ), - TextButton( - onPressed: () { - homeBloc.add( - HomeUrgentTasksViewAllClickedEvent()); - }, - child: const Text( - 'View all', + ], + ), + SizedBox(height: size.height * 0.045), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Urgent Tasks", style: TextStyle( - color: AppColors.buttonBlue, - fontSize: 14, + color: AppColors.white, + fontSize: 24, fontWeight: FontWeight.w500, ), ), - ), - ], - ), - ListView.separated( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) => Task( - bloc: homeBloc, - task: successState.urgentTasks[index], - ), - itemCount: (successState.urgentTasks.length < 2) - ? successState.urgentTasks.length - : 2, - separatorBuilder: - (BuildContext context, int index) { - return const SizedBox(height: 15); - }, - ), - SizedBox(height: size.height * 0.04), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - "Regular Tasks", - style: TextStyle( - color: AppColors.white, - fontSize: 24, - fontWeight: FontWeight.w500, + TextButton( + onPressed: () { + homeBloc.add( + HomeUrgentTasksViewAllClickedEvent()); + }, + child: const Text( + 'View all', + style: TextStyle( + color: AppColors.buttonBlue, + fontSize: 14, + fontWeight: FontWeight.w500, + ), + ), ), + ], + ), + ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) => Task( + bloc: homeBloc, + task: successState.urgentTasks[index], ), - TextButton( - onPressed: () { - homeBloc.add( - HomeRegularTasksViewAllClickedEvent()); - }, - child: const Text( - 'View all', + itemCount: (successState.urgentTasks.length < 2) + ? successState.urgentTasks.length + : 2, + separatorBuilder: + (BuildContext context, int index) { + return const SizedBox(height: 15); + }, + ), + SizedBox(height: size.height * 0.04), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Regular Tasks", style: TextStyle( - color: AppColors.buttonBlue, - fontSize: 14, + color: AppColors.white, + fontSize: 24, fontWeight: FontWeight.w500, ), ), - ), - ], - ), - ListView.separated( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) => Task( - bloc: homeBloc, - task: successState.regularTasks[index], + TextButton( + onPressed: () { + homeBloc.add( + HomeRegularTasksViewAllClickedEvent()); + }, + child: const Text( + 'View all', + style: TextStyle( + color: AppColors.buttonBlue, + fontSize: 14, + fontWeight: FontWeight.w500, + ), + ), + ), + ], ), - itemCount: (successState.regularTasks.length < 2) - ? successState.regularTasks.length - : 2, - separatorBuilder: - (BuildContext context, int index) { - return const SizedBox(height: 15); - }, - ), - SizedBox(height: size.height * 0.1), - ], + ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) => Task( + bloc: homeBloc, + task: successState.regularTasks[index], + ), + itemCount: (successState.regularTasks.length < 2) + ? successState.regularTasks.length + : 2, + separatorBuilder: + (BuildContext context, int index) { + return const SizedBox(height: 15); + }, + ), + SizedBox(height: size.height * 0.1), + ], + ), ), ), Positioned( diff --git a/Frontend/plannerly/lib/screens/urgent_tasks/urgent_tasks_page.dart b/Frontend/plannerly/lib/screens/urgent_tasks/urgent_tasks_page.dart index 2fd72f2..59fa710 100644 --- a/Frontend/plannerly/lib/screens/urgent_tasks/urgent_tasks_page.dart +++ b/Frontend/plannerly/lib/screens/urgent_tasks/urgent_tasks_page.dart @@ -1,140 +1,216 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:plannerly/bloc/home/home_bloc.dart'; import 'package:plannerly/screens/widgets/task.dart'; import 'package:plannerly/utils/colors/colors.dart'; -class UrgentTasks extends StatelessWidget { +class UrgentTasks extends StatefulWidget { const UrgentTasks({super.key}); + @override + State createState() => _UrgentTasksState(); +} + +class _UrgentTasksState extends State { + final HomeBloc homeBloc = HomeBloc(); + @override + void initState() { + homeBloc.add(HomeInitialEvent()); + super.initState(); + } + @override Widget build(BuildContext context) { Size size = MediaQuery.of(context).size; - return Scaffold( - backgroundColor: AppColors.backgroundDark, - body: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.all(14.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox(height: size.height * 0.03), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - IconButton( - onPressed: () {}, - icon: const Icon( - Icons.arrow_back_outlined, - color: AppColors.white, - size: 30, - ), - ), - SizedBox(width: size.width * 0.2), - const Text( - "Urgent Tasks", - style: TextStyle( - color: AppColors.white, - fontSize: 24, - fontWeight: FontWeight.w500, - ), - ), - ], - ), - SizedBox(height: size.height * 0.045), - Center( - child: Container( - decoration: BoxDecoration( - color: AppColors.backgroundLight, - borderRadius: BorderRadius.circular(18), - ), + return BlocConsumer( + bloc: homeBloc, + listenWhen: (previous, current) => current is HomeActionState, + buildWhen: (previous, current) => current is! HomeActionState, + listener: (context, state) { + if (state is HomePopState) { + Navigator.of(context).pop(); + } + }, + builder: (context, state) { + switch (state.runtimeType) { + case HomeLoadingState: + return const Scaffold( + backgroundColor: AppColors.backgroundDark, + body: Center(child: CircularProgressIndicator()), + ); + case HomeLoadedSuccessState: + final successState = state as HomeLoadedSuccessState; + return Scaffold( + backgroundColor: AppColors.backgroundDark, + body: RefreshIndicator( + onRefresh: () async { + homeBloc.add(HomeInitialEvent()); + }, + child: SingleChildScrollView( + physics: const AlwaysScrollableScrollPhysics(), child: Padding( - padding: const EdgeInsets.all(18.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + padding: const EdgeInsets.all(14.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - "Urgent Task Progress", - style: TextStyle( - color: AppColors.white, - fontSize: 20, - fontWeight: FontWeight.w400, - ), - ), - const SizedBox(height: 8), - Text( - "30/40 task completed.", - style: TextStyle( - color: AppColors.white.withOpacity(0.4), - fontSize: 14, - fontWeight: FontWeight.w400, - ), - ), - ], - ), - ), - Stack( + SizedBox(height: size.height * 0.03), + Row( + mainAxisAlignment: MainAxisAlignment.start, children: [ - SizedBox( - height: size.height * 0.07, - width: size.height * 0.07, - child: CircularProgressIndicator( - value: 0.8, - strokeWidth: 7, - valueColor: - AlwaysStoppedAnimation(Colors.red[400]), - backgroundColor: - AppColors.white.withOpacity(0.2), + IconButton( + onPressed: () { + homeBloc.add( + HomeAddNewTaskCloseButtonClickedEvent()); + }, + icon: const Icon( + Icons.arrow_back_outlined, color: AppColors.white, - semanticsValue: "80%", + size: 30, ), ), - SizedBox( - height: size.height * 0.07, - width: size.height * 0.07, - child: Center( - child: Text( - "80%", - style: TextStyle( - color: AppColors.white.withOpacity(0.8), - fontSize: 18, - fontWeight: FontWeight.w600, - ), - ), + SizedBox(width: size.width * 0.2), + const Text( + "Urgent Tasks", + style: TextStyle( + color: AppColors.white, + fontSize: 24, + fontWeight: FontWeight.w500, ), ), ], ), + SizedBox(height: size.height * 0.045), + Center( + child: Container( + decoration: BoxDecoration( + color: AppColors.backgroundLight, + borderRadius: BorderRadius.circular(18), + ), + child: Padding( + padding: const EdgeInsets.all(18.0), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + const Text( + "Urgent Task Progress", + style: TextStyle( + color: AppColors.white, + fontSize: 20, + fontWeight: FontWeight.w400, + ), + ), + const SizedBox(height: 8), + Text( + "${successState.totalUrgentTasksCompleted}/${successState.totalUrgentTasks} task completed.", + style: TextStyle( + color: AppColors.white + .withOpacity(0.4), + fontSize: 14, + fontWeight: FontWeight.w400, + ), + ), + ], + ), + ), + Stack( + children: [ + SizedBox( + height: size.height * 0.073, + width: size.height * 0.073, + child: CircularProgressIndicator( + value: (successState + .totalUrgentTasksCompleted == + 0) + ? 0 + : (successState + .totalUrgentTasksCompleted / + successState + .totalUrgentTasks), + strokeWidth: 7, + valueColor: AlwaysStoppedAnimation( + Colors.red[400]), + backgroundColor: + AppColors.white.withOpacity(0.2), + color: AppColors.white, + ), + ), + SizedBox( + height: size.height * 0.073, + width: size.height * 0.073, + child: Center( + child: Text( + (successState + .totalUrgentTasksCompleted == + 0) + ? "0%" + : "${((successState.totalUrgentTasksCompleted / successState.totalUrgentTasks) * 100).toStringAsFixed(1)}%", + style: TextStyle( + color: AppColors.white + .withOpacity(0.8), + fontSize: 18, + fontWeight: FontWeight.w600, + ), + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), + SizedBox(height: size.height * 0.03), + const Text( + "Urgent Tasks", + style: TextStyle( + color: AppColors.white, + fontSize: 24, + fontWeight: FontWeight.w500, + ), + ), + ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) => Task( + task: successState.urgentTasks[index], + bloc: homeBloc, + ), + itemCount: successState.totalUrgentTasks, + separatorBuilder: (BuildContext context, int index) { + return const SizedBox(height: 15); + }, + ), + SizedBox(height: size.height * 0.04), ], ), ), ), ), - SizedBox(height: size.height * 0.03), - const Text( - "Urgent Tasks", - style: TextStyle( - color: AppColors.white, - fontSize: 24, - fontWeight: FontWeight.w500, + ); + case HomeLoadedErrorState: + return Scaffold( + backgroundColor: AppColors.backgroundDark, + body: Center( + child: Text( + 'Some error ocurred!', + style: TextStyle( + fontSize: 20, + color: AppColors.white.withOpacity(0.3), + ), ), ), - // ListView.separated( - // shrinkWrap: true, - // physics: const NeverScrollableScrollPhysics(), - // itemBuilder: (context, index) => Task(), - // itemCount: 5, - // separatorBuilder: (BuildContext context, int index) { - // return SizedBox(height: 15); - // }, - // ), - SizedBox(height: size.height * 0.04), - ], - ), - ), - ), + ); + default: + return SizedBox(); + } + }, ); } } diff --git a/Frontend/plannerly/lib/screens/widgets/task.dart b/Frontend/plannerly/lib/screens/widgets/task.dart index fe51115..783e73e 100644 --- a/Frontend/plannerly/lib/screens/widgets/task.dart +++ b/Frontend/plannerly/lib/screens/widgets/task.dart @@ -87,7 +87,7 @@ class _TaskState extends State { ), ), IconButton( - onPressed: () { + onPressed: () async { widget.bloc.add( HomeTasksDeleteButtonClicked( taskDeleted: widget.task,