From 150ad60de6f2d421d37690dbe05f93a2bff09851 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Tue, 17 Oct 2023 14:22:49 +0300 Subject: [PATCH] track service request --- lib/extensions/widget_extensions.dart | 2 +- .../common_widgets/default_app_bar.dart | 24 +- .../pages/user/requests/requests_page.dart | 72 +-- .../requests/service_request_item.dart | 439 ++++++++++-------- .../requests/service_request_list.dart | 6 +- 5 files changed, 277 insertions(+), 266 deletions(-) diff --git a/lib/extensions/widget_extensions.dart b/lib/extensions/widget_extensions.dart index 78fba845..54f92475 100644 --- a/lib/extensions/widget_extensions.dart +++ b/lib/extensions/widget_extensions.dart @@ -5,7 +5,7 @@ import 'package:test_sa/extensions/int_extensions.dart'; import '../new_views/app_style/app_color.dart'; extension WidgetExtensions on Widget { - Widget onPress(VoidCallback onTap) => InkWell(onTap: onTap, child: this); + Widget onPress(VoidCallback onTap) => InkWell(onTap: onTap, child: this, highlightColor: Colors.transparent, splashColor: Colors.transparent); Widget get expanded => Expanded(child: this); diff --git a/lib/new_views/common_widgets/default_app_bar.dart b/lib/new_views/common_widgets/default_app_bar.dart index 6f9cd991..e839eedb 100644 --- a/lib/new_views/common_widgets/default_app_bar.dart +++ b/lib/new_views/common_widgets/default_app_bar.dart @@ -1,27 +1,33 @@ import 'package:flutter/material.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/text_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import '../../models/enums/translation_keys.dart'; import '../app_style/app_color.dart'; class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget { final TranslationKeys title; + const DefaultAppBar({@required this.title, Key key}) : super(key: key); @override Widget build(BuildContext context) { return AppBar( - leading: InkWell( - onTap: () { - Navigator.of(context).pop(); - }, - child: const Icon(Icons.arrow_back_ios), + automaticallyImplyLeading: false, + titleSpacing: 16, + title: Row( + children: [ + const Icon(Icons.arrow_back_ios).onPress(() { + Navigator.of(context).pop(); + }), + Text( + context.translate(title), + style: AppTextStyles.heading3?.copyWith(fontWeight: FontWeight.w600, color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), + ).expanded, + ], ), - titleSpacing: 0, - leadingWidth: 50.toScreenWidth, - titleTextStyle: Theme.of(context).textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.w600, color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), - title: Text(context.translate(title)), ); } diff --git a/lib/views/pages/user/requests/requests_page.dart b/lib/views/pages/user/requests/requests_page.dart index 65f00cdb..98a205d3 100644 --- a/lib/views/pages/user/requests/requests_page.dart +++ b/lib/views/pages/user/requests/requests_page.dart @@ -4,8 +4,10 @@ import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/providers/api/service_requests_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; +import 'package:test_sa/models/enums/translation_keys.dart'; import 'package:test_sa/models/service_request/service_request_search.dart'; import 'package:test_sa/models/subtitle.dart'; +import 'package:test_sa/new_views/common_widgets/default_app_bar.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; import 'package:test_sa/views/widgets/buttons/app_icon_button.dart'; @@ -39,6 +41,8 @@ class _ServiceRequestsPageState extends State with TickerPr } return Scaffold( + appBar: const DefaultAppBar(title: TranslationKeys.serviceRequest), + backgroundColor: const Color(0xfff8f9fb), body: SafeArea( child: LoadingManager( isLoading: _serviceRequestsProvider.isLoading, @@ -48,68 +52,12 @@ class _ServiceRequestsPageState extends State with TickerPr _serviceRequestsProvider.reset(); await _serviceRequestsProvider.getRequests(hospitalId: _userProvider.user.clientId); }, - child: Stack( - children: [ - Column( - children: [ - Container( - color: AColors.primaryColor, - padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 4), - child: Column( - children: [ - Row( - children: [ - ABackButton(), - Expanded( - child: Center( - child: Text( - _subtitle.serviceRequests, - style: Theme.of(context).textTheme.headline6.copyWith(color: AColors.white, fontStyle: FontStyle.italic), - ), - ), - ), - AIconButton( - key: ValueKey(_expandedSearch), - iconData: Icons.search, - color: AColors.secondaryColor, - buttonSize: 42, - backgroundColor: AColors.white, - onPressed: () async { - ServiceRequestSearch _temp = await showModalBottomSheet( - context: context, - isScrollControlled: true, - builder: (context) { - return ServiceRequestsSearchDialog( - initialSearchValue: _serviceRequestsProvider.search, - ); - }); - if (_temp != null) { - _serviceRequestsProvider.search = _temp; - _serviceRequestsProvider.reset(); - setState(() {}); - } - }, - ), - SizedBox( - width: 16, - ) - ], - ), - ], - ), - ), - Expanded( - child: ServiceRequestsList( - nextPage: _serviceRequestsProvider.nextPage, - onLazyLoad: () async { - await _serviceRequestsProvider.getRequests(hospitalId: _userProvider.user.clientId); - }, - requests: _serviceRequestsProvider.serviceRequests, - ), - ), - ], - ), - ], + child: ServiceRequestsList( + nextPage: _serviceRequestsProvider.nextPage, + onLazyLoad: () async { + await _serviceRequestsProvider.getRequests(hospitalId: _userProvider.user.clientId); + }, + requests: _serviceRequestsProvider.serviceRequests, ), ), ), diff --git a/lib/views/widgets/requests/service_request_item.dart b/lib/views/widgets/requests/service_request_item.dart index 25dd7c79..30fe3768 100644 --- a/lib/views/widgets/requests/service_request_item.dart +++ b/lib/views/widgets/requests/service_request_item.dart @@ -5,6 +5,11 @@ import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/providers/api/service_requests_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; +import 'package:test_sa/extensions/context_extension.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/text_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/models/enums/translation_keys.dart'; import 'package:test_sa/models/enums/user_types.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/models/subtitle.dart'; @@ -31,219 +36,269 @@ class ServiceRequestItem extends StatelessWidget { Color itemColor = index % 2 == 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; Color onItemColor = index % 2 != 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8), - primary: itemColor, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), - ), - ), - //padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8), - onPressed: () { - onPressed(request); - }, - child: Row( - children: [ - //Placeholder(color: onItemColor,fallbackWidth: 80,fallbackHeight: 80,), - _user.type == UsersTypes.normal_user && request.devicePhotos.isEmpty - ? SizedBox.shrink() - : SizedBox( - width: 80, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + return index % 2 == 0 + ? Container( + decoration: ShapeDecoration( + color: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + shadows: const [BoxShadow(color: Color(0x07000000), blurRadius: 14, offset: Offset(0, 0), spreadRadius: 0)], + ), + child: Column( + children: [ + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - request.devicePhotos?.isEmpty != false - ? SizedBox.shrink() - : Column( - children: [ - SizedBox( - height: 80, - width: 80, - child: ImageLoader( - url: request.devicePhotos.first, - boxFit: BoxFit.cover, - ), - ), - SizedBox( - height: 24, - ), - ], - ), - - _user.type == UsersTypes.engineer - ? Material( - color: onItemColor, - elevation: 6, - shape: CircleBorder(), - child: IconButton( - icon: Icon( - Icons.description, - color: itemColor, - size: 32, - ), - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => CreateServiceReport( - request: request, - )), - ); - }, - ), - ) - : SizedBox.shrink(), - //SizedBox(height: 8,), + Container( + padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10), + decoration: ShapeDecoration( + color: const Color(0xFFFFDBDC), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + ), + child: Text('HIGH PRIORITY', style: AppTextStyles.overline.copyWith(color: const Color(0xFF8C0409))), + ), + 8.width, + Container( + padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10), + decoration: ShapeDecoration( + color: const Color(0xFFFFEDBC), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + ), + child: Text('IN PROGRESS', style: AppTextStyles.overline.copyWith(color: const Color(0xFF886300))), + ), + 1.width.expanded, + Text('05 Dec, 2022\n09:30 AM', textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), ], ), - ), - SizedBox( - width: 8, + 8.height, + Text(context.translate(TranslationKeys.serviceRequest), style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), + ], + ).paddingAll(16), + ], ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + ) + : Padding( + padding: const EdgeInsets.symmetric(vertical: 4), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8), + primary: itemColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), + ), + ), + //padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8), + onPressed: () { + onPressed(request); + }, + child: Row( children: [ - Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: request.requestCode == null - ? SizedBox.shrink() - : Text( - request.requestCode ?? "-----", - style: Theme.of(context).textTheme.headline6.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold), + //Placeholder(color: onItemColor,fallbackWidth: 80,fallbackHeight: 80,), + _user.type == UsersTypes.normal_user && request.devicePhotos.isEmpty + ? SizedBox.shrink() + : SizedBox( + width: 80, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + request.devicePhotos?.isEmpty != false + ? SizedBox.shrink() + : Column( + children: [ + SizedBox( + height: 80, + width: 80, + child: ImageLoader( + url: request.devicePhotos.first, + boxFit: BoxFit.cover, + ), ), - ), - request.engineerName == null - ? SizedBox.shrink() - : Text( - request.engineerName ?? "", - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - ], - ), - Divider( - color: onItemColor, - ), - Text( - request.deviceNumber, - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - Divider( - color: onItemColor, - ), - Row( - children: [ - Expanded( - child: request.deviceModel == null - ? SizedBox.shrink() - : Text( - request.deviceModel ?? "Model not available", - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + SizedBox( + height: 24, ), - ), - request.engineerMobile == null - ? SizedBox.shrink() - : Text( - request.engineerMobile, - style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - ], - ), - Divider( - color: onItemColor, - ), - Row( - children: [ - Expanded( - child: request.deviceSerialNumber == null - ? SizedBox.shrink() - : Text( - request.deviceSerialNumber, - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + ], + ), + + _user.type == UsersTypes.engineer + ? Material( + color: onItemColor, + elevation: 6, + shape: CircleBorder(), + child: IconButton( + icon: Icon( + Icons.description, + color: itemColor, + size: 32, ), - ), - ], - ), - request.deviceEnName == null - ? SizedBox.shrink() - : Row( + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => CreateServiceReport( + request: request, + )), + ); + }, + ), + ) + : SizedBox.shrink(), + //SizedBox(height: 8,), + ], + ), + ), + SizedBox( + width: 8, + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( children: [ Expanded( - child: Text( - request.deviceEnName, - style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), + child: request.requestCode == null + ? SizedBox.shrink() + : Text( + request.requestCode ?? "-----", + style: Theme.of(context).textTheme.headline6.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold), + ), + ), + request.engineerName == null + ? SizedBox.shrink() + : Text( + request.engineerName ?? "", + style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + ), + ], + ), + Divider( + color: onItemColor, + ), + Text( + request.deviceNumber, + style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + ), + Divider( + color: onItemColor, + ), + Row( + children: [ + Expanded( + child: request.deviceModel == null + ? SizedBox.shrink() + : Text( + request.deviceModel ?? "Model not available", + style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + ), ), + request.engineerMobile == null + ? SizedBox.shrink() + : Text( + request.engineerMobile, + style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + ), ], ), + Divider( + color: onItemColor, + ), + Row( + children: [ + Expanded( + child: request.deviceSerialNumber == null + ? SizedBox.shrink() + : Text( + request.deviceSerialNumber, + style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + ), + ), + ], + ), + request.deviceEnName == null + ? SizedBox.shrink() + : Row( + children: [ + Expanded( + child: Text( + request.deviceEnName, + style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), + ), + ), + ], + ), + ], + ), + ), ], ), - ), - ], - ), - Divider( - color: onItemColor, - ), - Center( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Text( - request.callComments ?? "No maintenance issue found", - style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor), - textAlign: TextAlign.center, - ), - ), - ), - Divider( - color: onItemColor, - ), - Row( - children: [ - Text( - request.date ?? "Date not available", - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), - ), - Spacer(), - StatusLabel(label: request.statusLabel, color: AColors.getRequestStatusColor(request.statusValue)), - ], - ), - request.nextVisitDate == null - ? SizedBox.shrink() - : Column( - children: [ - Divider( - color: onItemColor, + Divider( + color: onItemColor, + ), + Center( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Text( + request.callComments ?? "No maintenance issue found", + style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor), + textAlign: TextAlign.center, ), - Row( - children: [ - Text( - _subtitle.nextVisitDate, - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), - ), - Spacer(), - Text( - DateFormat('EE dd/MM/yyyy').format(request.nextVisitDate), - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), - ), - ], + ), + ), + Divider( + color: onItemColor, + ), + Row( + children: [ + Text( + request.date ?? "Date not available", + style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), ), + Spacer(), + StatusLabel(label: request.statusLabel, color: AColors.getRequestStatusColor(request.statusValue)), ], ), + request.nextVisitDate == null + ? SizedBox.shrink() + : Column( + children: [ + Divider( + color: onItemColor, + ), + Row( + children: [ + Text( + _subtitle.nextVisitDate, + style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), + ), + Spacer(), + Text( + DateFormat('EE dd/MM/yyyy').format(request.nextVisitDate), + style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), + ), + ], + ), + ], + ), + ], + ), + ), ], ), ), - ], - ), - ), - ); + ); } } diff --git a/lib/views/widgets/requests/service_request_list.dart b/lib/views/widgets/requests/service_request_list.dart index 29fa65e1..ffb12374 100644 --- a/lib/views/widgets/requests/service_request_list.dart +++ b/lib/views/widgets/requests/service_request_list.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:test_sa/controllers/localization/localization.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/pages/user/requests/request_details.dart'; @@ -25,10 +26,11 @@ class ServiceRequestsList extends StatelessWidget { return LazyLoading( nextPage: nextPage, onLazyLoad: onLazyLoad, - child: ListView.builder( + child: ListView.separated( //physics: BouncingScrollPhysics(), itemCount: requests.length, - padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8), + padding: const EdgeInsets.all(16), + separatorBuilder: (cxt, index) => 8.height, itemBuilder: (context, itemIndex) { return ServiceRequestItem( index: itemIndex,