diff --git a/Frontend/plannerly/lib/screens/regular_tasks/regular_tasks_page.dart b/Frontend/plannerly/lib/screens/regular_tasks/regular_tasks_page.dart index f039988..545bc9a 100644 --- a/Frontend/plannerly/lib/screens/regular_tasks/regular_tasks_page.dart +++ b/Frontend/plannerly/lib/screens/regular_tasks/regular_tasks_page.dart @@ -1,139 +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 RegularTasks extends StatelessWidget { +class RegularTasks extends StatefulWidget { const RegularTasks({super.key}); + @override + State createState() => _RegularTasksState(); +} + +class _RegularTasksState 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( - "Regular 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( - "REgular Task Progress", - style: TextStyle( - color: AppColors.white, - fontSize: 20, - fontWeight: FontWeight.w400, - ), - ), - const SizedBox(height: 8), - Text( - "5/10 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.5, - strokeWidth: 7, - valueColor: - AlwaysStoppedAnimation(Colors.green[400]), - backgroundColor: - AppColors.white.withOpacity(0.2), + IconButton( + onPressed: () { + homeBloc.add( + HomeAddNewTaskCloseButtonClickedEvent()); + }, + icon: const Icon( + Icons.arrow_back_outlined, color: AppColors.white, + size: 30, ), ), - SizedBox( - height: size.height * 0.07, - width: size.height * 0.07, - child: Center( - child: Text( - "50%", - 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.totalRegularTasksCompleted}/${successState.totalRegularTasks} 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 + .totalRegularTasksCompleted == + 0) + ? 0 + : (successState + .totalRegularTasksCompleted / + successState + .totalRegularTasks), + strokeWidth: 7, + valueColor: AlwaysStoppedAnimation( + Colors.green[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.totalRegularTasksCompleted / successState.totalRegularTasks) * 100).toStringAsFixed(1)}%", + style: TextStyle( + color: AppColors.white + .withOpacity(0.8), + fontSize: 18, + fontWeight: FontWeight.w600, + ), + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), + SizedBox(height: size.height * 0.03), + const Text( + "Regular Tasks", + style: TextStyle( + color: AppColors.white, + fontSize: 24, + fontWeight: FontWeight.w500, + ), + ), + ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) => Task( + task: successState.regularTasks[index], + bloc: homeBloc, + ), + itemCount: successState.totalRegularTasks, + 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/utils/server/server_constants.dart b/Frontend/plannerly/lib/utils/server/server_constants.dart index 0b9dd5a..d82d6a6 100644 --- a/Frontend/plannerly/lib/utils/server/server_constants.dart +++ b/Frontend/plannerly/lib/utils/server/server_constants.dart @@ -2,4 +2,4 @@ var userId = "653a2f71e2330ac369e93c9b"; var baseUrl = "http://192.168.2.52:8000"; var token = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6ImpvaG4uZG9lQGdtYWlsLmNvbSIsIkZpcnN0X25hbWUiOiJKb2huIiwiTGFzdF9uYW1lIjoiRG9lIiwiVWlkIjoiNjUzYTJmNzFlMjMzMGFjMzY5ZTkzYzliIiwiZXhwIjoxNjk5MTg5MDUyfQ.bcAWrdZ4xBsXyZEIXz9ubjJVh_oImom45PPRBM3tRHY"; + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6ImpvaG4uZG9lQGdtYWlsLmNvbSIsIkZpcnN0X25hbWUiOiJKb2huIiwiTGFzdF9uYW1lIjoiRG9lIiwiVWlkIjoiNjUzYTJmNzFlMjMzMGFjMzY5ZTkzYzliIiwiZXhwIjoxNjk5Mjc3MTYwfQ.xvzZ3bdzAagcorXju4cR8o3M51ZC0ZILbMxQmnYG4DE";