diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index 1ac91bfa..3d206471 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -98,7 +98,7 @@ class ApiClient { } Future postJsonForResponse(String url, T jsonObject, - {String? token, Map? queryParameters, Map? headers, int retryTimes = 0, bool isFormData = true}) async { + {String? token, Map? queryParameters, Map? headers, int retryTimes = 0, bool isFormData = false}) async { int currentRetryTime = retryTimes; String? requestBody; late Map stringObj; @@ -111,6 +111,11 @@ class ApiClient { } } + if(!kReleaseMode) + { print("url:$url"); + print("requestBody:$requestBody"); + } + if (isFormData) { headers = {'Content-Type': 'application/x-www-form-urlencoded'}; stringObj = ((jsonObject ?? {}) as Map).map((key, value) => MapEntry(key, value?.toString() ?? "")); diff --git a/lib/api/gas_refill_api_client.dart b/lib/api/gas_refill_api_client.dart index d3e27343..87d6c631 100644 --- a/lib/api/gas_refill_api_client.dart +++ b/lib/api/gas_refill_api_client.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:http/http.dart'; import 'package:test_sa/api/user_api_client.dart'; import '../controllers/api_routes/urls.dart'; @@ -37,20 +38,45 @@ class GasRefillApiClient { Future createModel({ required GasRefillModel model, }) async { + + Map body = { - "uid": UserApiClient().user?.id.toString(), - "token": UserApiClient().user?.token ?? "", - "title": model.title ?? "", - "status": "0", //model.status.value.toString(), + "gazRefillNo": await generateGazRefillNo(), + "assignedEmployee": { + "id": UserApiClient().user?.id.toString(), + "name": UserApiClient().user?.username.toString() + }, + "status": { + "id": 0, + "name": "", + "value": 0 + }, }; - body["gazRefillDetails"] = jsonEncode(model.details + body["gazRefillDetails"] = model.details ?.map((model) => { - "gasType": model.type?.id.toString(), - "cylinderSize": model.cylinderSize?.id.toString(), - "requestedQty": model.requestedQuantity.toString(), + "gasType": { + "id": model.type?.id, + "name": model.type?.label.toString(), + "value": model.type?.id + }, + "cylinderType": { + "id": 0, + "name": "", + "value": 0 + }, + "cylinderSize": { + "id": model.cylinderSize?.id, + "name": model.cylinderSize?.label.toString(), + "value": model.cylinderSize?.id, + }, + "requestedQty": model.requestedQuantity, + "deliverdQty": 0 + }) - .toList()); + .toList(); + + print(body); final response = await ApiClient().postJsonForResponse( "${URLs.host1}${URLs.requestGasRefill}", @@ -85,4 +111,13 @@ class GasRefillApiClient { oldModel?.fromGasRefillModel(newModel); } + + + Future generateGazRefillNo() async { + + final reponse = await ApiClient().getJsonForResponse("${URLs.host1}${URLs.generateGazRefillNo}"); + var data = json.decode(reponse.body); + return data['data']; + + } } diff --git a/lib/controllers/api_routes/urls.dart b/lib/controllers/api_routes/urls.dart index fa4ed214..8795ecb9 100644 --- a/lib/controllers/api_routes/urls.dart +++ b/lib/controllers/api_routes/urls.dart @@ -2,7 +2,7 @@ class URLs{ URLs._(); static const host2 = "http://194.163.164.213/atoms/api"; // static const host1 = "https://atoms.hmg.com/api"; // production url - static const host1 = "https://atomsdev.hmg.com/api"; // uat url + static const host1 = "https://atomsuat.hmg.com"; // uat url // API Routes static const login = "/mobile/MobileAuth/Login"; // post @@ -48,6 +48,7 @@ class URLs{ static const requestGasRefill = "/mobile/GazRefill/AddGazRefill"; // get static const updateGasRefill = "/mobile/GazRefill/UpdateGazRefill"; // get static const getGasRefill = "/mobile/GazRefill/GetGazRefills"; // get + static const generateGazRefillNo= "/mobile/GazRefill/GenerateGazRefillNumber"; //device transfer static const requestDeviceTransfer = "/mobile/AssetTransfer/AddAssetTransfer"; // get diff --git a/lib/controllers/providers/api/status_drop_down/gas_refill/gas_cylinder_size_provider.dart b/lib/controllers/providers/api/status_drop_down/gas_refill/gas_cylinder_size_provider.dart index 6a1c53f9..cc767b86 100644 --- a/lib/controllers/providers/api/status_drop_down/gas_refill/gas_cylinder_size_provider.dart +++ b/lib/controllers/providers/api/status_drop_down/gas_refill/gas_cylinder_size_provider.dart @@ -57,14 +57,16 @@ class GasCylinderSizesProvider extends ChangeNotifier { notifyListeners(); Response response; try { + response = await get( Uri.parse((host ?? '') + URLs.getGasCylinderSize), ); _stateCode = response.statusCode; if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received - List categoriesListJson = json.decode(utf8.decode(response.bodyBytes)); - _items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList(); + + var categoriesListJson = json.decode(response.body); + _items = categoriesListJson['data'].map((item) => Lookup.fromJson(item)).toList(); } _loading = false; notifyListeners(); 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 a0d2aed0..3ea104b6 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -18,6 +18,7 @@ import '../../../widgets/app_text_form_field.dart'; import '../../../widgets/buttons/app_button.dart'; import '../../../widgets/gas_refill/gas_refill_create_details_item.dart'; import '../../../widgets/loaders/loading_manager.dart'; +import '../../../widgets/status/gas_refill/gas_cylinder_size.dart'; import '../../../widgets/status/gas_refill/gas_type.dart'; import '../../../widgets/titles/app_sub_title.dart'; @@ -147,17 +148,17 @@ class _RequestGasRefillState extends State { }, ), - // const SizedBox(height: 8,), - // const ASubTitle("Cylinder Size"), - // if(_validate && _currentDetails.cylinderSize == null) - // ASubTitle(_subtitle.requiredWord,color: Colors.red,), - // const SizedBox(height: 4,), - // GasCylinderSizeMenu( - // initialValue: _currentDetails.cylinderSize, - // onSelect: (status){ - // _currentDetails.cylinderSize = status; - // }, - // ), + const SizedBox(height: 8,), + const ASubTitle("Cylinder Size"), + if(_validate && _currentDetails.cylinderSize == null) + ASubTitle(_subtitle?.requiredWord??"",color: Colors.red,), + const SizedBox(height: 4,), + GasCylinderSizeMenu( + initialValue: _currentDetails.cylinderSize, + onSelect: (status){ + _currentDetails.cylinderSize = status; + }, + ), const SizedBox( height: 8, ), 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 699ffd9b..2f9104e4 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 @@ -48,7 +48,7 @@ class GasRefillUpdateDetailsItem extends StatelessWidget { initialValue: (details.deliveredQuantity ?? "").toString(), textAlign: TextAlign.center, style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.isNumeric(value!) ? "" : "allow numbers only", + validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", textInputType: TextInputType.number, onSaved: (value) { details.deliveredQuantity = int.tryParse(value!);