diff --git a/assets/images/update.svg b/assets/images/update.svg new file mode 100644 index 0000000..a77d186 --- /dev/null +++ b/assets/images/update.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/assets/translations/ar.json b/assets/translations/ar.json index b444f4c..6727200 100644 --- a/assets/translations/ar.json +++ b/assets/translations/ar.json @@ -18,6 +18,8 @@ "transferRequest" : "طلب نقل", "serviceRequest" : "طلب خدمة", "newServiceRequest" : "طلب خدمة جديدة", + "search": "بحث", + "filter" : "تصنيف", "newGasRefillRequest" : "طلب إعادة تعبئة غاز جديد", "newTransferRequest" : "طلب نقل جديد", "submitRequest" : "تأكيد الطلب", diff --git a/assets/translations/en.json b/assets/translations/en.json index 49c1ed5..7034422 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -18,6 +18,8 @@ "transferRequest" : "Transfer Request", "serviceRequest" : "Service Request", "newServiceRequest" : "New Service Request", + "search": "Search", + "filter": "Filter", "newGasRefillRequest" : "New Gas Refill Request", "newTransferRequest" : "New Transfer Request", "submitRequest" : "Submit Request", diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index ffa4278..4e20959 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -39,7 +39,7 @@ class GasRefillProvider extends ChangeNotifier { bool nextPage = true; // list of user requests - List items; + List items; // when requests in-process _loading = true // done _loading = true @@ -71,7 +71,7 @@ class GasRefillProvider extends ChangeNotifier { if (stateCode >= 200 && stateCode < 300) { // client's request was successfully received List requestsListJson = json.decode(response.body)["data"]; - List itemsPage = requestsListJson.map((request) => GasRefillModel.fromJson(request)).toList(); + List itemsPage = requestsListJson.map((request) => gasModel.GasRefillModel.fromJson(request)).toList(); items ??= []; items.addAll(itemsPage); notifyListeners(); @@ -128,15 +128,15 @@ class GasRefillProvider extends ChangeNotifier { Future updateModel({ @required String host, @required User user, - @required GasRefillModel oldModel, - @required GasRefillModel newModel, + @required gasModel.GasRefillModel oldModel, + @required gasModel.GasRefillModel newModel, }) async { Map body = { "id": newModel.id, - "gazRefillNo": newModel.title ?? "", + "gazRefillNo": newModel.gazRefillNo ?? "", "status": newModel.status.toJson(), //"expectedDate": newModel.expectedDate?.toIso8601String(), - "expectedTime": newModel.expectedDate?.toIso8601String(), + "expectedTime": newModel.expectedDate, if (timer?.startAt != null) "startDate": timer.startAt.toIso8601String(), if (timer?.startAt != null) "startTime": timer.startAt.toIso8601String(), if (timer?.endAt != null) "endDate": timer.endAt.toIso8601String(), @@ -148,17 +148,17 @@ class GasRefillProvider extends ChangeNotifier { "building": building?.toJson(includeFloors: false), "floor": floor?.toJson(includeDepartments: false), "department": department?.toJson(), - "engSignature": newModel.signatureEngineer, - "nurseSignature": newModel.signatureNurse, + "engSignature": newModel.engSignature, + "nurseSignature": newModel.nurseSignature, }; - body["gazRefillDetails"] = newModel.details + body["gazRefillDetails"] = newModel.gazRefillDetails .map((model) => { - "gasType": model.type.toJson(), + "gasType": model.gasType.toJson(), "cylinderSize": model.cylinderSize.toJson(), "cylinderType": model.cylinderType.toJson(), - "requestedQty": model.requestedQuantity, - "deliverdQty": model.deliveredQuantity, + "requestedQty": model.requestedQty, + "deliverdQty": model.deliverdQty, }) .toList(); log(body.toString()); diff --git a/lib/l10n/app_ar.arb b/lib/l10n/app_ar.arb index 3606f06..72c589b 100644 --- a/lib/l10n/app_ar.arb +++ b/lib/l10n/app_ar.arb @@ -253,6 +253,8 @@ "Serial No" : "الرقم التسلسلي", "device" : "الجهاز", "pickAsset" : "إختر جهاز", + "filter" : "تصنيف", + "pickAsset" : "إختر جهاز", "firstAction" : "First Action", "priority" : "الأولوية", "equipmentStatus" : "حالة المعدات", @@ -260,6 +262,10 @@ "callComments" : "تعليقات الطلب", "comments" : "تعليقات", "recordVoice" : "تسجيل صوت", + "gasRefillDetails" : "تفاصيل اعادة تعبئة غاز", + "updateRequest" : "تعديل الطلب", + "gasRefill" : "اعادة تعبئة غاز", + "recordVoice" : "تسجيل صوت", "receiverName" : "اسم المستلم", "receiverDetails" : "تفاصيل المستلم", "requestedThrough" : "الطلب عبر", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index cf293de..ac81461 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -253,6 +253,8 @@ "serialNo" : "Serial No", "device" : "Device", "pickAsset" : "Pick Asset", + "filter" : "Filter", + "pickAsset" : "Pick Asset", "firstAction" : "First Action", "workOrder" : "Work Orders", "viewWorkOrder" : "View All Work Order", @@ -265,6 +267,10 @@ "callComments" : "Call Comments", "comments": "Comments", "recordVoice" : "Record Voice", + "gasRefillDetails" : "Gas Refill Details", + "updateRequest" : "Update Request", + "gasRefill" : "Gas Refill", + "recordVoice" : "Record Voice", "assetDetails" : "Asset Details", "receiverName" : "Receiver Name", "receiverDetails" : "Receiver Details", diff --git a/lib/main.dart b/lib/main.dart index ec11a2d..2a015b4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,7 +20,6 @@ import 'package:test_sa/controllers/providers/api/status_drop_down/employee/assi import 'package:test_sa/controllers/providers/api/status_drop_down/employee/engineers_provider.dart'; import 'package:test_sa/controllers/providers/api/status_drop_down/gas_refill/gas_cylinder_size_provider.dart'; import 'package:test_sa/controllers/providers/api/status_drop_down/gas_refill/gas_cylinder_type_provider.dart'; -import 'package:test_sa/controllers/providers/api/status_drop_down/gas_refill/gas_status_provider.dart'; import 'package:test_sa/controllers/providers/api/status_drop_down/pentry/pentry_status_provider.dart'; import 'package:test_sa/controllers/providers/api/status_drop_down/pentry/pentry_task_status_provider.dart'; import 'package:test_sa/controllers/providers/api/status_drop_down/pentry/pentry_visit_status_provider.dart'; @@ -50,6 +49,7 @@ import 'package:test_sa/new_views/pages/splash_page.dart'; import 'package:test_sa/providers/department_provider.dart'; import 'package:test_sa/providers/gas_request_providers/cylinder_size_provider.dart'; import 'package:test_sa/providers/gas_request_providers/cylinder_type_provider.dart'; +import 'package:test_sa/providers/gas_request_providers/gas_status_provider.dart'; import 'package:test_sa/providers/gas_request_providers/gas_types_provider.dart'; import 'package:test_sa/providers/gas_request_providers/site_provider.dart'; import 'package:test_sa/providers/loading_list_notifier.dart'; diff --git a/lib/models/enums/translation_keys.dart b/lib/models/enums/translation_keys.dart index 12108d5..d72de1f 100644 --- a/lib/models/enums/translation_keys.dart +++ b/lib/models/enums/translation_keys.dart @@ -18,6 +18,8 @@ enum TranslationKeys { transferRequest, serviceRequest, newServiceRequest, + search, + filter, newGasRefillRequest, newTransferRequest, submitRequest, diff --git a/lib/models/new_models/gas_refill_model.dart b/lib/models/new_models/gas_refill_model.dart index 270beb1..55c9601 100644 --- a/lib/models/new_models/gas_refill_model.dart +++ b/lib/models/new_models/gas_refill_model.dart @@ -1,4 +1,5 @@ import 'dart:developer'; +import 'dart:typed_data'; import 'package:flutter/cupertino.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -30,6 +31,8 @@ class GasRefillModel { this.assignedEmployee, this.status, this.gazRefillDetails, + this.localEngineerSignature, + this.localNurseSignature }); GasRefillModel.fromJson(dynamic json) { @@ -47,7 +50,6 @@ class GasRefillModel { site = json['site'] != null ? Site.fromJson(json['site']) : null; building = json['building'] != null ? Building.fromJson(json['building']) : null; floor = json['floor'] != null ? Floor.fromJson(json['floor']) : null; - log(json['department']); department = json['department'] != null ? Department.fromJson(json['department']) : null; assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null; status = json['status'] != null ? Lookup.fromJson(json['status']) : null; @@ -77,6 +79,8 @@ class GasRefillModel { AssignedEmployee assignedEmployee; Lookup status; List gazRefillDetails; + Uint8List localNurseSignature; + Uint8List localEngineerSignature; GasRefillModel copyWith({ num id, @@ -172,6 +176,27 @@ class GasRefillModel { } return true; } + + fromGasRefillModel(GasRefillModel model) { + id = model.id; + //userId = model.userId; + site = model.site; + gazRefillNo = model.gazRefillNo; + status = Lookup.fromStatus(model.status); + gazRefillDetails = model.gazRefillDetails; + building = model.building; + floor = model.floor; + department = model.department; + startDate = model.startDate; + endDate = model.endDate; + expectedDate = model.expectedDate; + assignedEmployee = model.assignedEmployee; + localEngineerSignature = model.localEngineerSignature; + localNurseSignature = model.localNurseSignature; + engSignature = model.engSignature; + nurseSignature = model.nurseSignature; + workingHours = model.workingHours; + } } class GasRefillDetails { @@ -182,6 +207,7 @@ class GasRefillDetails { this.cylinderSize, this.requestedQty, this.deliverdQty, + this.selectedForEditing }); GasRefillDetails.fromJson(dynamic json) { @@ -199,6 +225,7 @@ class GasRefillDetails { Lookup cylinderSize; num requestedQty; num deliverdQty; + bool selectedForEditing; GasRefillDetails copyWith({ num id, diff --git a/lib/new_views/common_widgets/app_search_field.dart b/lib/new_views/common_widgets/app_search_field.dart new file mode 100644 index 0000000..09286d5 --- /dev/null +++ b/lib/new_views/common_widgets/app_search_field.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; +import 'package:test_sa/extensions/context_extension.dart'; +import 'package:test_sa/new_views/app_style/app_color.dart'; + +import '../../models/enums/translation_keys.dart'; + +class AppSearchField extends StatefulWidget { + final Function(String) onChanged; + final Function(String) onSubmitted; + const AppSearchField({Key key, this.onChanged, this.onSubmitted}) : super(key: key); + + @override + State createState() => _AppSearchFieldState(); +} + +class _AppSearchFieldState extends State { + @override + Widget build(BuildContext context) { + return TextField( + onChanged: widget.onChanged, + onSubmitted: widget.onSubmitted, + decoration: InputDecoration( + prefixIcon: const Icon(Icons.search, color: AppColor.neutral20,), + hintText: context.translation.search, + hintStyle: TextStyle( + fontSize: Theme.of(context).textTheme.bodySmall.fontSize + ), + filled: true, + fillColor: AppColor.neutral30, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(15), + borderSide: BorderSide.none, + )), + ); + } +} diff --git a/lib/new_views/common_widgets/app_tab_bar.dart b/lib/new_views/common_widgets/app_tab_bar.dart new file mode 100644 index 0000000..4aab61f --- /dev/null +++ b/lib/new_views/common_widgets/app_tab_bar.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class AppTabBar extends StatelessWidget { + + const AppTabBar({Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return TabBar( + tabs:[ + Tab( + icon: Icon(Icons.cloud_outlined), + ), + Tab( + icon: Icon(Icons.beach_access_sharp), + ), + Tab( + icon: Icon(Icons.brightness_5_sharp), + ), + ], + ); + } +} diff --git a/lib/new_views/common_widgets/app_text_form_field.dart b/lib/new_views/common_widgets/app_text_form_field.dart index cfa71a3..2e1af84 100644 --- a/lib/new_views/common_widgets/app_text_form_field.dart +++ b/lib/new_views/common_widgets/app_text_form_field.dart @@ -26,6 +26,7 @@ class AppTextFormField extends StatefulWidget { final TextInputAction textInputAction; final VoidCallback onAction; final Color backgroundColor; + final bool alignLabelWithHint; const AppTextFormField({ Key key, @@ -50,6 +51,7 @@ class AppTextFormField extends StatefulWidget { this.textInputAction, this.onAction, this.backgroundColor, + this.alignLabelWithHint }) : super(key: key); @override @@ -80,13 +82,14 @@ class _AppTextFormFieldState extends State { onChanged: widget.onChange, obscureText: widget.obscureText ?? false, keyboardType: widget.textInputType, - maxLines: widget.textInputType == TextInputType.multiline ? null : 1, + maxLines: widget.textInputType == TextInputType.multiline ? 4 : 1, obscuringCharacter: "*", controller: widget.controller, textInputAction: widget.textInputType == TextInputType.multiline ? null : widget.textInputAction ?? TextInputAction.next, onEditingComplete: widget.onAction ?? () => FocusScope.of(context).nextFocus(), style: AppTextStyle.body1?.copyWith(fontWeight: FontWeight.w500), decoration: InputDecoration( + alignLabelWithHint: widget.alignLabelWithHint, border: border, disabledBorder: border, focusedBorder: border, diff --git a/lib/new_views/common_widgets/single_item_drop_down_menu.dart b/lib/new_views/common_widgets/single_item_drop_down_menu.dart index 85ed7b9..b126ec7 100644 --- a/lib/new_views/common_widgets/single_item_drop_down_menu.dart +++ b/lib/new_views/common_widgets/single_item_drop_down_menu.dart @@ -45,7 +45,7 @@ class _SingleItemDropDownMenuState { final GlobalKey _scaffoldKey = GlobalKey(); int currentPageIndex = 0; + bool showAppbar =true; final List _pages = const [ DashboardPage(), MyRequestsPage(), @@ -53,11 +54,8 @@ class _LandPageState extends State { }, child: Scaffold( key: _scaffoldKey, - appBar: HomeAppBar(scaffoldKey: _scaffoldKey), - body: Padding( - padding: EdgeInsetsDirectional.only(start: 16.toScreenWidth, end: 11.toScreenHeight), - child: _pages[currentPageIndex], - ), + appBar: showAppbar?HomeAppBar(scaffoldKey: _scaffoldKey): null, + body: _pages[currentPageIndex], drawer: const AppDrawer(), floatingActionButton: const AppFloatingActionButton(), bottomNavigationBar: AppBottomNavigationBar( @@ -74,6 +72,16 @@ class _LandPageState extends State { setState(() { currentPageIndex = index; }); + + if(index == 1){ + setState(() { + showAppbar =false; + }); + }else{ + setState(() { + showAppbar =true; + }); + } } }, ), diff --git a/lib/new_views/pages/land_page/my_request/my_requests_page.dart b/lib/new_views/pages/land_page/my_request/my_requests_page.dart new file mode 100644 index 0000000..c40406d --- /dev/null +++ b/lib/new_views/pages/land_page/my_request/my_requests_page.dart @@ -0,0 +1,52 @@ +import 'package:flutter/material.dart'; +import 'package:test_sa/extensions/context_extension.dart'; +import 'package:test_sa/models/enums/translation_keys.dart'; + +import '../../../app_style/app_color.dart'; +import '../../../common_widgets/app_search_field.dart'; + +class MyRequestsPage extends StatelessWidget { + const MyRequestsPage({Key key}) : super(key: key); + + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + + leadingWidth: 0, + title: Padding( + padding: const EdgeInsets.only(bottom: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded(child: SizedBox( + height: 50, + child: AppSearchField())), + SizedBox(width: 20,), + Text(context.translation.filter, style: TextStyle( + color: AppColor.primary50, + fontSize: Theme.of(context).textTheme.bodySmall.fontSize, + fontWeight: FontWeight.w500 + ),) + ], + ), + ), + ), + + body: TabBarView( + children: const [ + Center( + child: Text(""), + ), + Center( + child: Text(""), + ), + Center( + child: Text(""), + ), + ], + ), + ); + } +} diff --git a/lib/new_views/pages/land_page/my_requests_page.dart b/lib/new_views/pages/land_page/my_requests_page.dart deleted file mode 100644 index ccccada..0000000 --- a/lib/new_views/pages/land_page/my_requests_page.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:flutter/material.dart'; - -class MyRequestsPage extends StatelessWidget { - const MyRequestsPage({Key key}) : super(key: key); - - @override - Widget build(BuildContext context) { - return const Scaffold( - body: Center( - child: Text("My Requests"), - ), - ); - } -} diff --git a/lib/providers/gas_request_providers/gas_status_provider.dart b/lib/providers/gas_request_providers/gas_status_provider.dart new file mode 100644 index 0000000..1b5458d --- /dev/null +++ b/lib/providers/gas_request_providers/gas_status_provider.dart @@ -0,0 +1,34 @@ +import 'dart:convert'; + +import 'package:http/http.dart'; + +import '../../controllers/api_routes/api_manager.dart'; +import '../../controllers/api_routes/urls.dart'; +import '../../models/lookup.dart'; +import '../loading_list_notifier.dart'; + +class GasStatusProvider extends LoadingListNotifier { + @override + Future getDate() async { + if (loading ?? false) return -2; + loading = true; + notifyListeners(); + try { + Response response = await ApiManager.instance.get(URLs.getGasStatus); + stateCode = response.statusCode; + if (response.statusCode >= 200 && response.statusCode < 300) { + // client's request was successfully received + List categoriesListJson = json.decode(response.body)["data"]; + items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList(); + } + loading = false; + notifyListeners(); + return response.statusCode; + } catch (error) { + loading = false; + stateCode = -1; + notifyListeners(); + return -1; + } + } +} diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index 226d1c4..1739af7 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -1,82 +1,46 @@ import 'package:flutter/material.dart'; -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:intl/intl.dart'; +import 'package:flutter_svg/svg.dart'; import 'package:provider/provider.dart'; -import 'package:test_sa/controllers/api_routes/http_status_manger.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/providers/api/gas_refill_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/models/gas_refill/gas_refill_model.dart'; -import 'package:test_sa/models/subtitle.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/string_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/pages/user/gas_refill/request_gas_refill.dart'; -import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; -import 'package:test_sa/views/widgets/buttons/app_button.dart'; -import 'package:test_sa/views/widgets/buttons/app_icon_button.dart'; -import 'package:test_sa/views/widgets/gas_refill/gas_refill_update_details_item.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; -import 'package:test_sa/views/widgets/requests/info_row.dart'; import 'package:test_sa/views/widgets/requests/request_status.dart'; -import 'package:test_sa/views/widgets/status/gas_refill/gas_status.dart'; -import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; +import '../../../../extensions/text_extensions.dart'; import '../../../../models/enums/user_types.dart'; +import '../../../../models/new_models/gas_refill_model.dart'; +import '../../../../new_views/app_style/app_color.dart'; +import '../../../../new_views/common_widgets/default_app_bar.dart'; import '../../../app_style/colors.dart'; -class GasRefillDetails extends StatefulWidget { +class GasRefillDetailsPage extends StatefulWidget { GasRefillModel model; - GasRefillDetails({Key key, this.model}) : super(key: key); + GasRefillDetailsPage({Key key, this.model}) : super(key: key); @override - State createState() => _GasRefillDetailsState(); + State createState() => _GasRefillDetailsPageState(); } -class _GasRefillDetailsState extends State { - GasRefillModel _model = GasRefillModel(); +class _GasRefillDetailsPageState extends State { + GasRefillModel _model = GasRefillModel(gazRefillDetails: []); bool _enableEdit = false; - bool _validate = false; UserProvider _userProvider; - SettingProvider _settingProvider; - GasRefillProvider _gasRefillProvider; bool _isLoading = false; final GlobalKey _formKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); - _update() async { - _validate = true; - if (!_formKey.currentState.validate()) { - setState(() {}); - return false; - } - _formKey.currentState.save(); - - _isLoading = true; - setState(() {}); - int status = await _gasRefillProvider.updateModel(user: _userProvider.user, host: _settingProvider.host, newModel: _model, oldModel: widget.model); - _isLoading = false; - setState(() {}); - if (status >= 200 && status < 300) { - Fluttertoast.showToast( - msg: context.translation.successfulRequestMessage, - ); - _enableEdit = false; - _validate = false; - //Navigator.of(context).pop(); - } else { - String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: context.translation); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(errorMessage), - )); - } - } - @override void initState() { - _model?.fromGasRefillModel(widget.model); + _model.fromGasRefillModel(widget.model); super.initState(); } @@ -84,9 +48,9 @@ class _GasRefillDetailsState extends State { Widget build(BuildContext context) { _userProvider = Provider.of(context); - _settingProvider = Provider.of(context); - _gasRefillProvider = Provider.of(context); + return Scaffold( + appBar: DefaultAppBar(title: context.translation.gasRefillDetails), key: _scaffoldKey, body: SafeArea( child: Form( @@ -98,167 +62,183 @@ class _GasRefillDetailsState extends State { onRefresh: () async {}, child: Column( children: [ - Container( - color: Theme.of(context).colorScheme.primary, - padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 4), - child: Row( + informationCard() + ], + ), + ), + ), + ), + ); + } + + Widget informationCard() { + return 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: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - ABackButton( - onPressed: () { - Navigator.of(context).pop(_model); - }, + /// TBD + //StatusLabel( + //label: item.priority.name, + //id: serviceRequest.priority.id, + //textColor: AColors.getPriorityStatusTextColor(serviceRequest.priority.id), + //backgroundColor: AColors.getPriorityStatusColor(serviceRequest.priority.id) + //), + 8.width, + StatusLabel( + label: widget.model.status?.name??"", + textColor: AColors.getRequestStatusTextColor(widget.model.status?.value??0), + backgroundColor: AColors.getRequestStatusColor(widget.model.status?.value??0)), + 8.height, + Text(context.translation.gasRefillRequest, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), + ], + ), + 1.width.expanded, + if (_userProvider.user.type == UsersTypes.engineer) + CircleAvatar( + radius: 25, + backgroundColor: AppColor.neutral30, + child: CircleAvatar( + radius: 24, + backgroundColor: Colors.white, + child: Padding( + padding: const EdgeInsets.only(left: 3.0), + child: SvgPicture.asset('assets/images/update.svg'), + ), ), - Expanded( - child: Center( - child: Text( - "Gas Refill Request", - style: Theme.of(context).textTheme.headline6.copyWith(color: AColors.white, fontStyle: FontStyle.italic), + ).onPress( + (widget.model.status?.value ?? 0) == 2 + ? null + : + () async { + _enableEdit = !_enableEdit; + _model?.fromGasRefillModel(widget.model); + // setState(() {}); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => RequestGasRefill( + gasRefillModel: widget.model, ), ), + ).then((value) { + if (value != null) { + _model = value; + } + }); + setState(() {}); + },), + ], + ), + 8.height, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Gas Request:', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Cylinder Size: ${widget.model.gazRefillDetails[0].cylinderSize.value}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Site: ${widget.model.site.name}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), ), - if (_userProvider.user.type == UsersTypes.engineer) - AIconButton( - iconData: /*_enableEdit ? Icons.cancel :*/ Icons.edit, - color: Theme.of(context).colorScheme.onPrimary, - buttonSize: 42, - backgroundColor: AColors.green, - onPressed: (widget.model.status?.value ?? 0) == 2 - ? null - : () async { - // _enableEdit = !_enableEdit; - _model?.fromGasRefillModel(widget.model); - // setState(() {}); - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => RequestGasRefill( - gasRefillModel: widget.model, - ), - ), - ).then((value) { - if (value != null) { - _model = value; - } - }); - setState(() {}); - }, - ), - const SizedBox( - width: 16, - ) ], ), + Text(widget.model.startDate?.toServiceRequestCardFormat??"", textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), + ], + ), + 8.height, + const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), + 8.height, + Text( + 'Request Quantity: ${widget.model.gazRefillDetails[0].requestedQty}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Delivered Quantity: ${widget.model.gazRefillDetails[0].deliverdQty}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + 8.height, + ], + ).paddingAll(16), + /// TBD + (_userProvider.user.type == UsersTypes.normal_user + ? Container( + height: 50, + padding: const EdgeInsets.only(left: 16, right: 16), + alignment: Alignment.center, + width: double.infinity, + decoration: const ShapeDecoration( + color: Color(0xFFEAF1F4), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(20), + bottomRight: Radius.circular(20), ), - Expanded( - child: SingleChildScrollView( - padding: EdgeInsets.all(16 * AppStyle.getScaleFactor(context)), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - RequestInfoRow( - title: "Gas Refill No", - info: _model.title, - ), - RequestInfoRow( - title: context.translation.hospital, - info: _model.clientName, - ), - RequestInfoRow( - title: "Building", - info: _model.building?.name, - ), - RequestInfoRow( - title: "Floor", - info: _model.floor?.name, - ), - RequestInfoRow( - title: "Department", - info: _model.department?.departmentName, - ), - RequestInfoRow( - title: context.translation.startDate, - info: _model.startDate == null ? null : "${DateFormat.yMd().format(_model.startDate)} ${DateFormat.Hms().format(_model.startDate)}", - ), - RequestInfoRow( - title: context.translation.endDate, - info: _model.endDate == null ? null : "${DateFormat.yMd().format(_model.endDate)} ${DateFormat.Hms().format(_model.endDate)}", - ), - _enableEdit - ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 8, - ), - ASubTitle(context.translation.status), - if (_validate && _model.status == null) - ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ), - const SizedBox( - height: 4, - ), - GasStatusMenu( - initialValue: _model.status, - onSelect: (status) { - _model.status = status; - }, - ) - ], - ) - : Row( - children: [ - Expanded( - child: Text( - "${context.translation.status} : ", - style: Theme.of(context).textTheme.subtitle2, - textScaleFactor: AppStyle.getScaleFactor(context), - ), - ), - if (_model.status?.id != null) StatusLabel(label: _model.status.name, backgroundColor: AColors.getGasStatusColor(_model.status.id)), - ], - ), - const SizedBox( - height: 8, - ), - const ASubTitle("Gas Requests"), - const SizedBox( - height: 8, - ), - ListView.builder( - shrinkWrap: true, - physics: const ClampingScrollPhysics(), - itemCount: _model.details.length, - itemBuilder: (context, index) { - final details = _model.details[index]; - return GasRefillUpdateDetailsItem( - details: details, - validate: _validate, - enableEdit: _enableEdit, - ); - }), - if (_enableEdit) - Column( - children: [ - const SizedBox( - height: 16, - ), - AButton( - text: context.translation.update, - onPressed: _update, - ), - ], - ), - ], - ), + ), + ), + child: Row( + children: [ + Text( + 'Comment here...', + style: AppTextStyles.heading6.copyWith( + color: AppColor.neutral50.withOpacity(.6), ), - ), + ).expanded, + SvgPicture.asset("assets/images/comment_send.svg", width: 24 * AppStyle.getScaleFactor(context), height: 24 * AppStyle.getScaleFactor(context), color: AppColor.primary70), ], ), - ), - ), + ) + : Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), + 16.height, + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'View Comments', + style: AppTextStyles.bodyText.copyWith(color: const Color(0xFF4A8DB7)), + ), + 4.width, + const Icon( + Icons.arrow_forward, + color: Color(0xFF4A8DB7), + size: 14, + ) + ], + ), + ], + ).paddingOnly(bottom: 16, start: 16, end: 16)) + .onPress(() { + }), + ], ), - ); + ).paddingAll(16); } } diff --git a/lib/views/pages/user/gas_refill/request_gas_refill.dart b/lib/views/pages/user/gas_refill/request_gas_refill.dart index 47ed324..3815108 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -9,10 +9,9 @@ import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/controllers/validator/validator.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/gas_refill/gas_refill_details.dart'; -import 'package:test_sa/models/gas_refill/gas_refill_model.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/models/timer_model.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart'; @@ -29,10 +28,14 @@ import 'package:test_sa/views/widgets/status/gas_refill/gas_status.dart'; import 'package:test_sa/views/widgets/status/gas_refill/gas_type.dart'; import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; -import '../../../../controllers/localization/localization.dart'; import '../../../../controllers/providers/api/hospitals_provider.dart'; -import '../../../widgets/e_signature/e_signature.dart'; -import '../../../widgets/timer/app_timer.dart'; +import '../../../../extensions/text_extensions.dart'; +import '../../../../models/new_models/gas_refill_model.dart'; +import '../../../../new_views/common_widgets/app_text_form_field.dart'; +import '../../../../new_views/common_widgets/default_app_bar.dart'; +import '../../../../new_views/common_widgets/single_item_drop_down_menu.dart'; +import '../../../../providers/gas_request_providers/gas_status_provider.dart'; + class RequestGasRefill extends StatefulWidget { static const String id = "/request-gas-refill"; @@ -52,9 +55,11 @@ class _RequestGasRefillState extends State { SettingProvider _settingProvider; GasRefillProvider _gasRefillProvider; GasRefillDetails _currentDetails = GasRefillDetails(); - final TextEditingController _requestedQuantityController = TextEditingController(); final TextEditingController _deliveredQuantityController = TextEditingController(); - GasRefillModel _formModel = GasRefillModel(details: []); + final TextEditingController _commentController = TextEditingController(); + final TextEditingController _workingHoursController = TextEditingController(); + + GasRefillModel _formModel = GasRefillModel(gazRefillDetails: []); final GlobalKey _formKey = GlobalKey(); final GlobalKey _DetailsKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); @@ -73,26 +78,27 @@ class _RequestGasRefillState extends State { if (mounted) super.setState(() {}); } - _onSubmit() async { - if (_formModel.details.isEmpty) { - if (!_addNewModel()) return; + _onSubmit(BuildContext context) async { + if (_formModel.gazRefillDetails.isEmpty) { + if (!(await _addNewModel(context))) return; } - _isLoading = true; + //_isLoading = true; setState(() {}); - if (widget.gasRefillModel != null) { - if (!_formModel.validate()) { - _isLoading = false; - setState(() {}); - return; - } - } - if (_gasRefillProvider.department?.name == null) { - ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Select department"))); - _isLoading = false; - setState(() {}); - return; - } + // if (widget.gasRefillModel != null) { + // if (!(await _formModel.validate(context))) { + // _isLoading = false; + // setState(() {}); + // return; + // } + // } + //if(!(_formKey.currentState.validate())) return; + // if (_gasRefillProvider.department?.name == null) { + // ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Select department"))); + // _isLoading = false; + // setState(() {}); + // return; + // } int status = widget.gasRefillModel == null ? null /*await _gasRefillProvider.createModel( @@ -105,7 +111,7 @@ class _RequestGasRefillState extends State { oldModel: widget.gasRefillModel, newModel: _formModel, ); - _isLoading = false; + //_isLoading = false; setState(() {}); if (status >= 200 && status < 300) { Fluttertoast.showToast( @@ -121,23 +127,24 @@ class _RequestGasRefillState extends State { } } - bool _addNewModel() { + Future _addNewModel(BuildContext context) async { _validate = true; if (!_formKey.currentState.validate()) { setState(() {}); return false; } _formKey.currentState.save(); - if (!_currentDetails.validate()) { + if (!(await _currentDetails.validate(context))) { setState(() {}); return false; } - _formModel.details.insert(0, _currentDetails); + _formModel.gazRefillDetails.insert(0, _currentDetails); _validate = false; Scrollable.ensureVisible(_DetailsKey.currentContext); - _requestedQuantityController.clear(); _deliveredQuantityController.clear(); + _workingHoursController.clear(); + _commentController.clear(); _currentDetails = GasRefillDetails(); setState(() {}); return true; @@ -145,8 +152,9 @@ class _RequestGasRefillState extends State { @override void dispose() { - _requestedQuantityController.dispose(); _deliveredQuantityController.dispose(); + _commentController.dispose(); + _workingHoursController.dispose(); super.dispose(); } @@ -162,10 +170,10 @@ class _RequestGasRefillState extends State { if (_firstTime) { String _clientName; if (widget.gasRefillModel != null) { - _formModel.status = widget.gasRefillModel?.status ?? Lookup(value: 0); - _gasRefillProvider.expectedDateTime = _formModel.expectedDate; - _gasRefillProvider.timer = TimerModel(startAt: widget.gasRefillModel?.startDate, endAt: widget.gasRefillModel?.endDate); - _clientName = _formModel.clientName; + //_formModel.status = widget.gasRefillModel?.status ?? Lookup(value: 0); + _gasRefillProvider.expectedDateTime = DateTime.tryParse(_formModel.expectedDate??""); + _gasRefillProvider.timer = TimerModel(startAt: DateTime.tryParse(widget.gasRefillModel?.startDate??""), endAt: DateTime.tryParse(widget.gasRefillModel?.endDate??"")); + _clientName = _formModel.site.custName; } else { _gasRefillProvider.timer = null; _clientName = _userProvider.user?.clientName; @@ -181,6 +189,7 @@ class _RequestGasRefillState extends State { }); } return Scaffold( + appBar: DefaultAppBar(title: context.translation.updateRequest), key: _scaffoldKey, body: Form( key: _formKey, @@ -191,380 +200,93 @@ class _RequestGasRefillState extends State { stateCode: 200, onRefresh: () async {}, child: SingleChildScrollView( - padding: EdgeInsets.all(12 * AppStyle.getScaleFactor(context)), child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Center( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - "${widget.gasRefillModel == null ? "Request" : "Update"} Gas Refill", - style: Theme.of(context).textTheme.headline5.copyWith(color: Theme.of(context).primaryColor, fontSize: 28, fontWeight: FontWeight.bold), - ), - ), - ), - // const SizedBox(height: 4,), - // ASubTitle(context.translation.title), - // if(_validate && _formModel.title == null) - // ASubTitle(context.translation.requiredWord,color: Colors.red,), - // SizedBox(height: 4,), - // ATextFormField( - // initialValue: _formModel?.title, - // textAlign: TextAlign.center, - // style: Theme.of(context).textTheme.subtitle1, - // textInputType: TextInputType.text, - // onSaved: (value){ - // _formModel.title = value; - // }, - // ), - // const SizedBox(height: 8,), - ASubTitle(context.translation.status), - if (_validate && _formModel.status == null) - ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ), - const SizedBox( - height: 4, - ), - GasStatusMenu( - initialValue: _formModel.status ?? Lookup(value: 0), - enabled: widget.gasRefillModel != null, - onSelect: (status) { - _formModel.status = status; - }, - ), - const SizedBox( - height: 8, - ), - Divider( - color: Theme.of(context).colorScheme.primary, - ), - const SizedBox( - height: 4, - ), - HospitalAutoCompleteField( - enabled: false, - initialValue: _gasRefillProvider.hospital?.name, - // onSave: (value){ - // _search.hospital = value; - // }, - onSearch: (value) { - _gasRefillProvider.hospital = value; - _gasRefillProvider.building = null; - _gasRefillProvider.floor = null; - _gasRefillProvider.department = null; - setState(() {}); - }, - ), - const SizedBox( - height: 8, - ), - BuildingTypeMenu( - initialValue: _gasRefillProvider?.building, - building: _gasRefillProvider?.hospital?.buildings, - loading: _firstTime, - enabled: widget.gasRefillModel == null, - onSelect: (status) { - _gasRefillProvider.building = status; - setState(() {}); - }, - ), - const SizedBox(height: 8), - FloorTypeMenu( - initialValue: _gasRefillProvider?.floor, - floors: _gasRefillProvider?.building?.floors, - enabled: widget.gasRefillModel == null, - loading: _firstTime, - onSelect: (status) { - _gasRefillProvider.floor = status; - setState(() {}); - }, - ), - const SizedBox(height: 8), - DepartmentTypeMenu( - initialValue: _gasRefillProvider?.department, - departments: _gasRefillProvider?.floor?.departments, - loading: _firstTime, - enabled: widget.gasRefillModel == null, - onSelect: (status) { - _gasRefillProvider.department = status; - setState(() {}); - }, - ), - const SizedBox(height: 8), - if (widget.gasRefillModel != null) ASubTitle(context.translation.workingHours), - if (widget.gasRefillModel != null) const SizedBox(height: 8), - if (widget.gasRefillModel != null) - Row( - children: [ - Expanded( - child: AppTimer( - timer: _gasRefillProvider.timer, - onChange: (timer) async { - _gasRefillProvider.timer = timer; - _formModel.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); - _formModel.startDate = timer.startAt; - _formModel.endDate = timer.endAt; - return true; - }, - ), - ), - ], - ), - //const SizedBox(height: 8), - // if (_userProvider.user?.type == UsersTypes.normal_user || widget.gasRefillModel != null) - // Column( - // crossAxisAlignment: CrossAxisAlignment.stretch, - // children: [ - // const ASubTitle("Expected Date"), - // SizedBox( - // height: 8 * AppStyle.getScaleFactor(context), - // ), - // ADateTimePicker( - // date: _gasRefillProvider.expectedDateTime, - // from: DateTime.now().subtract(const Duration(days: 365)), - // to: DateTime.now().add(const Duration(days: 365)), - // onDateTimePicker: (date) { - // _gasRefillProvider.expectedDateTime = date; - // _formModel.expectedDate = _gasRefillProvider.expectedDateTime; - // setState(() {}); - // }, - // ), - // ], - // ), - // if (_userProvider.user?.type == UsersTypes.engineer) - // Column( - // children: [ - // Row( - // children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.stretch, - // children: [ - // const ASubTitle("Start of Work"), - // SizedBox( - // height: 8 * AppStyle.getScaleFactor(context), - // ), - // ADateTimePicker( - // date: _gasRefillProvider.startDate, - // from: DateTime.now().subtract(const Duration(days: 365)), - // to: DateTime.now().add(const Duration(days: 365)), - // onDateTimePicker: (date) { - // _gasRefillProvider.startDate = date; - // setState(() {}); - // }, - // ), - // ], - // ), - // ), - // const SizedBox(width: 8), - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.stretch, - // children: [ - // const ASubTitle("End of Work"), - // SizedBox( - // height: 8 * AppStyle.getScaleFactor(context), - // ), - // ADateTimePicker( - // date: _gasRefillProvider.endDate, - // from: DateTime.now().subtract(const Duration(days: 365)), - // to: DateTime.now().add(const Duration(days: 365)), - // onDateTimePicker: (date) { - // _gasRefillProvider.endDate = date; - // setState(() {}); - // }, - // ), - // ], - // ), - // ), - // ], - // ), - // const SizedBox(height: 8), - // ASubTitle(context.translation.workingHours), - // const SizedBox(height: 4), - // ATextFormField( - // initialValue: null, - // textAlign: TextAlign.center, - // hintText: _gasRefillProvider.startDate == null - // ? "0" - // : ((_gasRefillProvider.endDate?.difference(_gasRefillProvider.startDate)?.inMinutes ?? 0) / 60)?.toStringAsFixed(2)?.toString() ?? "0", - // enable: false, - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => Validator.isNumeric(value) ? null : context.translation.requiredWord, - // textInputType: TextInputType.number, - // onSaved: (value) { - // // _serviceReport.workHours = value; - // }, - // ), - // ], - // ), - if (widget.gasRefillModel == null) - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox(height: 8), - Divider(color: Theme.of(context).colorScheme.primary), - const SizedBox(height: 4), - const ASubTitle("Gas Type"), - if (_validate && _currentDetails.type == null) ASubTitle(context.translation.requiredWord, color: Colors.red), - const SizedBox(height: 4), - GasTypeMenu( - initialValue: _currentDetails.type, - onSelect: (status) { - _currentDetails.type = status; - }, - ), - const SizedBox(height: 8), - const ASubTitle("Cylinder Size"), - if (_validate && _currentDetails.cylinderSize == null) - ASubTitle( - context.translation.requiredWord, - color: Colors.red, + Column( + children: [ + Container( + width: MediaQuery.of(context).size.width, + decoration: ShapeDecoration( + color: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), ), - const SizedBox( - height: 4, + shadows: const [BoxShadow(color: Color(0x07000000), blurRadius: 14, offset: Offset(0, 0), spreadRadius: 0)], ), - GasCylinderSizeMenu( - initialValue: _currentDetails.cylinderSize, - onSelect: (status) { - _currentDetails.cylinderSize = status; - }, - ), - const SizedBox( - height: 8, - ), - const ASubTitle("Cylinder Type"), - if (_validate && _currentDetails.cylinderSize == null) - ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ), - const SizedBox( - height: 4, - ), - GasCylinderTypesMenu( - initialValue: _currentDetails.cylinderType, - onSelect: (status) { - _currentDetails.cylinderType = status; - }, - ), - const SizedBox( - height: 8, - ), - ASubTitle(context.translation.requestedQuantity), - if (_validate && _currentDetails?.requestedQuantity == null) - ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ), - SizedBox( - height: 4, - ), - ATextFormField( - initialValue: (_currentDetails?.requestedQuantity ?? "").toString(), - textAlign: TextAlign.center, - controller: _requestedQuantityController, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", - textInputType: TextInputType.number, - onChange: (value) { - _currentDetails?.requestedQuantity = double.tryParse(value); - }, - ), - if (widget.gasRefillModel != null) const SizedBox(height: 16), - if (widget.gasRefillModel != null) ASubTitle(context.translation.deliveredQuantity), - if (widget.gasRefillModel != null && _validate && _currentDetails?.deliveredQuantity == null) - ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ), - if (widget.gasRefillModel != null) const SizedBox(height: 4), - if (widget.gasRefillModel != null) - ATextFormField( - initialValue: (_currentDetails?.deliveredQuantity ?? "").toString(), - textAlign: TextAlign.center, - controller: _deliveredQuantityController, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", - textInputType: TextInputType.number, - onChange: (value) { - _currentDetails?.deliveredQuantity = double.tryParse(value); - }, - ), - const SizedBox(height: 16), - AButton( - text: context.translation.add, - onPressed: _addNewModel, - ), - ], - ), - const SizedBox(height: 16), - if (_formModel.details.isNotEmpty) const ASubTitle("Gas Requests"), - ListView.builder( - key: _DetailsKey, - shrinkWrap: true, - physics: const ClampingScrollPhysics(), - itemCount: _formModel.details.length, - itemBuilder: (context, index) { - final model = _formModel.details[index]; - return GasRefillCreateDetailsItem( - isUpdate: widget.gasRefillModel != null, - model: model, - onPressed: () { - if (widget.gasRefillModel != null) { - model.selectedForEditing = !(model.selectedForEditing ?? false); - } - if (widget.gasRefillModel == null) { - _formModel.details.remove(model); - } - setState(() {}); - }, - ); - }), - if (widget.gasRefillModel != null) const SizedBox(height: 16), - if (widget.gasRefillModel != null) const ASubTitle("Nurse Signature"), - if (widget.gasRefillModel != null) - ESignature( - oldSignature: _formModel.signatureNurse, - newSignature: _formModel.localNurseSignature, - onChange: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _formModel.localNurseSignature = signature; - _formModel.signatureNurse = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), - if (widget.gasRefillModel != null) - const SizedBox( - height: 8, - ), - if (widget.gasRefillModel != null) const ASubTitle("Engineer Signature"), - if (widget.gasRefillModel != null) - ESignature( - oldSignature: _formModel.signatureEngineer, - newSignature: _formModel.localEngineerSignature, - onChange: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _formModel.localEngineerSignature = signature; - _formModel.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), - const SizedBox(height: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(context.translation.gasRefill, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), + 8.height, + Text( + 'Gas Request:', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Cylinder Size: ${widget.gasRefillModel.gazRefillDetails[0].cylinderSize.value}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Request Quantity: ${widget.gasRefillModel.gazRefillDetails[0].requestedQty}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Site: ${widget.gasRefillModel.site.name}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + ], + ).paddingAll(16), + ), + 12.height, + AppTextFormField( + labelText: context.translation.workingHours, + onSaved:(value){ + _formModel?.workingHours = double.tryParse(value); + }, + textInputType: TextInputType.number, + controller: _workingHoursController, + validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", + ), + 12.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.reportStatus, + initialValue: _formModel.status, + onSelect: (value) { + _formModel.status=value; + }, + ), + 12.height, + AppTextFormField( + labelText: context.translation.deliveredQuantity, + onSaved:(value){ + _currentDetails?.deliverdQty = double.tryParse(value); + }, + textInputType: TextInputType.number, + controller: _deliveredQuantityController, + validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", + ), + 12.height, + /// TBD + AppTextFormField( + labelText: context.translation.comments, + textInputType: TextInputType.multiline, + alignLabelWithHint: true, + controller: _commentController, + onSaved: (value){ + }, + ), + ], + ).paddingAll(16), AButton( text: widget.gasRefillModel == null ? context.translation.submit : context.translation.update, - onPressed: _onSubmit, - ), - const SizedBox(height: 100) + onPressed:()async{_onSubmit.call(context);}, + ).paddingAll(16), ], ), - ), - ), + ) + ), ), ), ); diff --git a/lib/views/pages/user/gas_refill/track_gas_refill.dart b/lib/views/pages/user/gas_refill/track_gas_refill.dart index cd7df4e..3a7ba6d 100644 --- a/lib/views/pages/user/gas_refill/track_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/track_gas_refill.dart @@ -1,16 +1,15 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/providers/api/gas_refill_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/subtitle.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/extensions/context_extension.dart'; + + import 'package:test_sa/views/widgets/gas_refill/gas_refill_list.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; -import '../../../widgets/switch_button.dart'; +import '../../../../new_views/common_widgets/default_app_bar.dart'; class TrackGasRefillPage extends StatefulWidget { static const String id = "/track-gas-refill"; @@ -31,13 +30,13 @@ class _TrackGasRefillPageState extends State with TickerProv Widget build(BuildContext context) { if (_gasRefillProvider == null) { _gasRefillProvider = Provider.of(context); - //_gasRefillProvider?.isLoading = false; _gasRefillProvider.reset(); } _userProvider = Provider.of(context); _settingProvider = Provider.of(context); return Scaffold( + appBar: DefaultAppBar(title: context.translation.gasRefillRequest), body: SafeArea( child: LoadingManager( isLoading: _gasRefillProvider.isLoading, @@ -55,46 +54,6 @@ class _TrackGasRefillPageState extends State with TickerProv children: [ Column( children: [ - Container( - color: AColors.white, - padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 4), - child: Column( - children: [ - Row( - children: [ - const ABackButton(), - Expanded( - child: Center( - child: Text( - "Gas Refill Requests", - style: Theme.of(context).textTheme.headline6.copyWith(color: AColors.grey3A, fontStyle: FontStyle.italic), - ), - ), - ), - const SizedBox( - width: 48, - ) - ], - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0), - child: ASwitchButton( - title: "Most Recent", - value: mostRecent, - onChange: (value) async { - mostRecent = value; - _gasRefillProvider.reset(); - await _gasRefillProvider.getRequests( - user: _userProvider.user, - host: _settingProvider.host, - mostRecent: mostRecent, - ); - }, - ), - ), Expanded( child: GasRefillList( nextPage: _gasRefillProvider.nextPage, diff --git a/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart b/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart index 8825f45..708fea5 100644 --- a/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart +++ b/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart @@ -1,10 +1,9 @@ import 'package:flutter/material.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/gas_refill/gas_refill_details.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart'; -import '../../../controllers/localization/localization.dart'; +import '../../../models/new_models/gas_refill_model.dart'; import '../buttons/app_button.dart'; import '../titles/app_sub_title.dart'; @@ -38,23 +37,23 @@ class _GasRefillCreateDetailsItemState extends State children: [ Row( children: [ - Expanded(child: Text(widget.model.type.name)), + Expanded(child: Text(widget.model.gasType.name)), IconButton(onPressed: widget.onPressed, color: widget.isUpdate ? AColors.cyan : AColors.red, icon: Icon(widget.isUpdate ? Icons.edit : Icons.delete)) ], ), Wrap( spacing: 10, children: [ - Text("Quantity: ${widget.model.requestedQuantity.toStringAsFixed(0)}"), + Text("Quantity: ${widget.model.requestedQty.toStringAsFixed(0)}"), Text("Cylinder Size: ${widget.model.cylinderSize.name}"), Text("Cylinder Type: ${widget.model.cylinderType.name}"), ], ), - if (widget.model.deliveredQuantity != null) + if (widget.model.deliverdQty != null) Row( children: [ const Text("Delivered Quantity: "), - Text(widget.model.deliveredQuantity.toStringAsFixed(0)), + Text(widget.model.deliverdQty.toStringAsFixed(0)), ], ), if (startEditing) const SizedBox(height: 16), @@ -62,16 +61,16 @@ class _GasRefillCreateDetailsItemState extends State if (startEditing) const SizedBox(height: 4), if (startEditing) ATextFormField( - initialValue: widget.model.deliveredQuantity?.toString() ?? "0", + initialValue: widget.model.deliverdQty?.toString() ?? "0", textAlign: TextAlign.center, style: Theme.of(context).textTheme.titleMedium, // validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", textInputType: TextInputType.number, onSaved: (value) { if (value.isNotEmpty) { - widget.model.deliveredQuantity = double.tryParse(value); + widget.model.deliverdQty = double.tryParse(value); } else { - widget.model.deliveredQuantity = 0; + widget.model.deliverdQty = 0; } }, ), diff --git a/lib/views/widgets/gas_refill/gas_refill_item.dart b/lib/views/widgets/gas_refill/gas_refill_item.dart index 8686180..f9abe4f 100644 --- a/lib/views/widgets/gas_refill/gas_refill_item.dart +++ b/lib/views/widgets/gas_refill/gas_refill_item.dart @@ -1,10 +1,14 @@ import 'package:flutter/material.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/gas_refill/gas_refill_model.dart'; -import 'package:test_sa/views/app_style/colors.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/string_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/views/app_style/sizing.dart'; -import 'package:test_sa/views/widgets/requests/request_status.dart'; + +import '../../../extensions/text_extensions.dart'; +import '../../../models/new_models/gas_refill_model.dart'; +import '../../app_style/colors.dart'; +import '../requests/request_status.dart'; class GasRefillItem extends StatelessWidget { final int index; @@ -15,20 +19,17 @@ class GasRefillItem extends StatelessWidget { @override Widget build(BuildContext context) { - 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: const EdgeInsets.symmetric(vertical: 8, horizontal: 8), - backgroundColor: itemColor, + backgroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), ), ), - //padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8), onPressed: () { onPressed(item); }, @@ -36,75 +37,116 @@ class GasRefillItem extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + /// TBD + // StatusLabel( + // label: , + // id: , + // textColor: AColors.getPriorityStatusTextColor(), + // backgroundColor: AColors.getPriorityStatusColor()), + 8.width, + StatusLabel(label: item.status.name, textColor: AColors.getRequestStatusTextColor(item.status.value), backgroundColor: AColors.getRequestStatusColor(item.status.value)), + 1.width.expanded, + Text(item.startDate != null ?item.startDate.toServiceRequestCardFormat:"", textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), + ], + ), + 8.height, + Text(context.translation.gasRefillRequest, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), + Text( + 'Gas Type: ${item.gazRefillDetails[0].gasType.name}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + '${context.translation.site}: ${item.site.name}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + 8.height, + Row( + mainAxisSize: MainAxisSize.min, children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - item.title ?? "-----", - style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold), - ), - Row( - children: [ - Expanded( - child: Text( - context.translation.hospital, - style: Theme.of(context).textTheme.titleSmall.copyWith( - color: onItemColor, - ), - ), - ), - if (item.clientName != null) - Text( - item.clientName, - style: Theme.of(context).textTheme.titleSmall.copyWith( - color: onItemColor, - ), - ), - ], - ), - Divider(color: onItemColor), - Row( - children: [ - Expanded( - child: Text(context.translation.status, style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), - ), - if (item.status?.id != null) StatusLabel(label: item.status.name, backgroundColor: AColors.getGasStatusColor(item.status.id)), - ], - ), - if (item?.expectedDate != null) Divider(color: onItemColor), - if (item?.expectedDate != null) - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text("Expected Date", style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), - Text(item.expectedDate.toIso8601String().split("T").first, style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), - ], - ), - if (item?.details?.isNotEmpty ?? false) Divider(color: onItemColor), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (item?.details?.isNotEmpty ?? false) Text("Gas Type", style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), - Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: item.details - .map( - (gas) => gas?.type?.name?.isNotEmpty ?? false - ? Text(gas?.type?.name, style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)) - : const SizedBox.shrink(), - ) - .toList(), - ) - ], - ), - ], - ), + Text( + 'View Details', + style: AppTextStyles.bodyText.copyWith(color: const Color(0xFF4A8DB7)), ), + 4.width, + const Icon( + Icons.arrow_forward, + color: Color(0xFF4A8DB7), + size: 14, + ) ], ), + // Row( + // children: [ + // Expanded( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Text( + // item.title ?? "-----", + // style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold), + // ), + // Row( + // children: [ + // Expanded( + // child: Text( + // subtitle.hospital, + // style: Theme.of(context).textTheme.titleSmall.copyWith( + // color: onItemColor, + // ), + // ), + // ), + // if (item.clientName != null) + // Text( + // item.clientName, + // style: Theme.of(context).textTheme.titleSmall.copyWith( + // color: onItemColor, + // ), + // ), + // ], + // ), + // Divider(color: onItemColor), + // Row( + // children: [ + // Expanded( + // child: Text(subtitle.status, style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), + // ), + // if (item.status?.id != null) StatusLabel(label: item.status.name, color: AColors.getGasStatusColor(item.status.id)), + // ], + // ), + // if (item?.expectedDate != null) Divider(color: onItemColor), + // if (item?.expectedDate != null) + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // children: [ + // Text("Expected Date", style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), + // Text(item.expectedDate.toIso8601String().split("T").first, style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), + // ], + // ), + // if (item?.details?.isNotEmpty ?? false) Divider(color: onItemColor), + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // if (item?.details?.isNotEmpty ?? false) Text("Gas Type", style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), + // Column( + // crossAxisAlignment: CrossAxisAlignment.end, + // children: item.details + // .map( + // (gas) => gas?.type?.name?.isNotEmpty ?? false + // ? Text(gas?.type?.name, style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)) + // : const SizedBox.shrink(), + // ) + // .toList(), + // ) + // ], + // ), + // ], + // ), + // ), + // ], + // ), ], ), ), diff --git a/lib/views/widgets/gas_refill/gas_refill_list.dart b/lib/views/widgets/gas_refill/gas_refill_list.dart index 519cb0b..d7718f7 100644 --- a/lib/views/widgets/gas_refill/gas_refill_list.dart +++ b/lib/views/widgets/gas_refill/gas_refill_list.dart @@ -1,13 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/gas_refill/gas_refill_model.dart'; -import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/pages/user/gas_refill/gas_refill_details.dart'; import 'package:test_sa/views/widgets/gas_refill/gas_refill_item.dart'; import 'package:test_sa/views/widgets/loaders/lazy_loading.dart'; import 'package:test_sa/views/widgets/loaders/no_item_found.dart'; +import '../../../models/new_models/gas_refill_model.dart'; + class GasRefillList extends StatefulWidget { final List items; final bool nextPage; @@ -22,7 +21,7 @@ class GasRefillList extends StatefulWidget { class _GasRefillListState extends State { @override Widget build(BuildContext context) { - if (widget.items.length == 0) { + if (widget.items.isEmpty) { return NoItemFound( message: context.translation.noServiceRequestFound, ); @@ -40,7 +39,7 @@ class _GasRefillListState extends State { item: widget.items[itemIndex], onPressed: (model) { Navigator.of(context).push(MaterialPageRoute( - builder: (_) => GasRefillDetails( + builder: (_) => GasRefillDetailsPage( model: model, ))).then((value) { model=value; diff --git a/lib/views/widgets/gas_refill/gas_refill_update_details_item.dart b/lib/views/widgets/gas_refill/gas_refill_update_details_item.dart index b0399a9..b13cdd5 100644 --- a/lib/views/widgets/gas_refill/gas_refill_update_details_item.dart +++ b/lib/views/widgets/gas_refill/gas_refill_update_details_item.dart @@ -1,14 +1,13 @@ import 'package:flutter/material.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/validator/validator.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/gas_refill/gas_refill_details.dart'; -import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/requests/info_row.dart'; import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; import 'package:test_sa/views/widgets/titles/app_title.dart'; +import '../../../models/new_models/gas_refill_model.dart'; + class GasRefillUpdateDetailsItem extends StatelessWidget { final GasRefillDetails details; final bool enableEdit; @@ -22,21 +21,21 @@ class GasRefillUpdateDetailsItem extends StatelessWidget { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ATitle(details.type.name), + ATitle(details.gasType.name), RequestInfoRow( title: "Cylinder Size", info: details.cylinderSize.name, ), RequestInfoRow( title: "Requested Quantity", - info: details.requestedQuantity.toStringAsFixed(0), + info: details.deliverdQty?.toStringAsFixed(0)??"", ), enableEdit ? Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ ASubTitle(context.translation.quantity), - if (validate && details.deliveredQuantity == null) + if (validate && details.deliverdQty == null) ASubTitle( context.translation.requiredWord, color: Colors.red, @@ -45,20 +44,20 @@ class GasRefillUpdateDetailsItem extends StatelessWidget { height: 4, ), ATextFormField( - initialValue: (details.deliveredQuantity ?? "").toString(), + initialValue: (details.deliverdQty ?? "").toString(), textAlign: TextAlign.center, style: Theme.of(context).textTheme.subtitle1, validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", textInputType: TextInputType.number, onSaved: (value) { - details.deliveredQuantity = double.tryParse(value); + details.deliverdQty = double.tryParse(value); }, ), ], ) : RequestInfoRow( title: "Delivered Quantity", - info: details.deliveredQuantity?.toStringAsFixed(0), + info: details.deliverdQty?.toStringAsFixed(0), ), //SizedBox(height: 16,) ],