changed to new apis

merge-requests/18/head
nextwo 3 years ago
parent a3439c3192
commit d2cf147acd

@ -98,7 +98,7 @@ class ApiClient {
}
Future<Response> postJsonForResponse<T>(String url, T jsonObject,
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = true}) async {
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
int currentRetryTime = retryTimes;
String? requestBody;
late Map<String, String> 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<String, dynamic>).map((key, value) => MapEntry(key, value?.toString() ?? ""));

@ -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<GasRefillModel> createModel({
required GasRefillModel model,
}) async {
Map<String, dynamic> 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<String> generateGazRefillNo() async {
final reponse = await ApiClient().getJsonForResponse("${URLs.host1}${URLs.generateGazRefillNo}");
var data = json.decode(reponse.body);
return data['data'];
}
}

@ -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

@ -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<Lookup>((item) => Lookup.fromJson(item)).toList();
}
_loading = false;
notifyListeners();

@ -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<RequestGasRefill> {
},
),
// 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,
),

@ -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!);

Loading…
Cancel
Save