add and update gas refill ui and api integrated

design_3.0_task_module_new
WaseemAbbasi22 8 months ago
parent f06426091b
commit 152a0795c6

@ -167,12 +167,14 @@ class URLs {
static get getGasCylinderSize => "$_baseUrl/Lookups/GetLookup?lookupEnum=608"; // get
static get getGasCylinderType => "$_baseUrl/Lookups/GetLookup?lookupEnum=607"; // get
static get getGasStatus => "$_baseUrl/Lookups/GetLookup?lookupEnum=609"; // get
static get requestGasRefill => "$_baseUrl/GazRefill/AddGazRefill"; // get
static get requestGasRefill => "$_baseUrl/GasRefill/AddGasRefillFromMobile"; // get
static get updateGasRefill => "$_baseUrl/GazRefill/UpdateGazRefill"; // get
static get getGasRefill => "$_baseUrl/GazRefill/GetGazRefills"; // get
static get getGasRefillById => "$_baseUrl/GazRefill/GetGazRefillById"; // get
// static get getGasRefillById => "$_baseUrl/GazRefill/GetGazRefillById"; // get older endpoint..
static get getGasRefillById => "$_baseUrl/GasRefill/GetGasRefillById"; // get
static get getGazRefillComments => "$_baseUrl/GazRefill/GetHistoryComments"; // get
static get addGazRefillComment => "$_baseUrl/GazRefill/AddHistoryComment"; // add
static get updateGasRefillByEngineer => "$_baseUrl/GasRefill/UpdateGasRefillByEngineer"; // update
//device transfer
static get requestDeviceTransfer => "$_baseUrl/AssetTransfer/AddAssetTransfer"; // get

@ -28,6 +28,7 @@ class GasRefillProvider extends ChangeNotifier {
building = null;
floor = null;
department = null;
gasRefillAttachments.clear();
}
// state code of current request to defied error message
@ -58,10 +59,11 @@ class GasRefillProvider extends ChangeNotifier {
Future<GasRefillModel?> getGasRefillObjectById(num id) async {
try {
Response response = await ApiManager.instance.get(URLs.getGasRefillById + "?gazRefillId=$id");
Response response = await ApiManager.instance.get(URLs.getGasRefillById + "?gasRefillId=$id");
if (response.statusCode >= 200 && response.statusCode < 300) {
return GasRefillModel.fromJson(json.decode(response.body)["data"]);
return GasRefillModel.fromJson(json.decode(response.body)["data"]);
} else {
return null;
}
@ -70,14 +72,6 @@ class GasRefillProvider extends ChangeNotifier {
}
}
// void updateRecurrentWoTimer({TimerModel? timer}) {
// recurrentWoData?.recurrentWoTimerModel = timer;
// if (timer?.startAt != null && timer?.endAt != null) {
// recurrentWoData?.timerModelList = recurrentWoData?.timerModelList ?? [];
// recurrentWoData?.timerModelList!.add(timer!);
// }
// notifyListeners();
// }
/// return -2 if request in progress
/// return -1 if error happen when sending request
@ -126,20 +120,14 @@ class GasRefillProvider extends ChangeNotifier {
}
}
Future<void> createModel({
Future<void> addGasRefillRequest({
required BuildContext context,
required User user,
required GasRefillModel model,
}) async {
late Response response;
try {
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
final Map<String, dynamic> body = {
"uid": user.id.toString(),
"token": user.token ?? "",
};
body.addAll(model.toJson());
response = await ApiManager.instance.post(URLs.requestGasRefill, body: body);
response = await ApiManager.instance.post(URLs.requestGasRefill, body: model.toJson());
stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) {
if (items != null) {
@ -158,6 +146,23 @@ class GasRefillProvider extends ChangeNotifier {
}
}
Future<int> updateGasRefill({required int status, required GasRefillModel model}) async {
isLoading = true;
Response response;
try {
response = await ApiManager.instance.post(URLs.updateGasRefillByEngineer, body: model.toUpdateEngineerPayload(status: status));
stateCode = response.statusCode;
isLoading = false;
notifyListeners();
return response.statusCode;
} catch (error) {
isLoading = false;
stateCode = -1;
notifyListeners();
return -1;
}
}
Future<int> updateModel({
required String host,
required User user,
@ -166,7 +171,7 @@ class GasRefillProvider extends ChangeNotifier {
}) async {
Map<String, dynamic> body = {
"id": newModel.id,
"gazRefillNo": newModel.gazRefillNo ?? "",
"gasRefillNo": newModel.gasRefillNo ?? "",
"status": newModel.status?.toJson(),
//"expectedDate": newModel.expectedDate?.toIso8601String(),
"expectedTime": newModel.expectedDate,
@ -185,7 +190,7 @@ class GasRefillProvider extends ChangeNotifier {
"comment": newModel.comment,
};
body["gazRefillDetails"] = newModel.gazRefillDetails!
body["gasRefillDetails"] = newModel.gasRefillDetails!
.map((model) => {
"gasType": model.gasType?.toJson(),
"cylinderSize": model.cylinderSize?.toJson(),

@ -12,42 +12,77 @@ import 'package:test_sa/models/new_models/site.dart';
import 'package:test_sa/models/timer_model.dart';
class GasRefillModel {
GasRefillModel(
{this.id,
this.gazRefillNo,
this.expectedDate,
this.expectedTime,
this.startDate,
this.startTime,
this.endDate,
this.endTime,
this.engSignature,
this.nurseSignature,
this.workingHours,
this.extensionNo,
this.employeeId,
this.name,
this.createdDate,
this.site,
this.building,
this.floor,
this.department,
this.assignedEmployee,
this.status,
this.comment,
this.gazRefillDetails,
this.localEngineerSignature,
this.localNurseSignature,
this.timer,
this.timerModelList,
this.gasRefillTimer,
this.gasRefillAttachments,
GasRefillModel({
this.id,
this.gasRefillNo,
this.expectedDate,
this.expectedTime,
this.startDate,
this.startTime,
this.endDate,
this.endTime,
this.engSignature,
this.nurseSignature,
this.workingHours,
this.extensionNo,
this.employeeId,
this.name,
this.createdDate,
this.site,
this.building,
this.floor,
this.department,
this.assignedEmployee,
this.status,
this.comment,
this.techComment,
this.gasRefillDetails,
this.localEngineerSignature,
this.localNurseSignature,
this.timer,
this.timerModelList,
this.gasRefillTimers,
this.gasRefillAttachments,
this.statusValue,
});
});
num? id; // Now nullable
String? gasRefillNo; // Now nullable
String? expectedDate; // Now nullable
String? expectedTime; // Now nullable
String? startDate; // Now nullable
String? startTime; // Now nullable
String? endDate; // Now nullable
String? endTime; // Now nullable
String? engSignature; // Now nullable
String? nurseSignature; // Now nullable
double? workingHours;
dynamic extensionNo;
String? employeeId;
String? name;
String? createdDate;
Site? site; // Now nullable
Building? building; // Now nullable
Floor? floor; // Now nullable
Department? department; // Now nullable
AssignedEmployee? assignedEmployee; // Now nullable
Lookup? status; // Now nullable
String? comment; // Now nullable
String? techComment; // Now nullable
List<GasRefillDetails>? gasRefillDetails; // Now nullable
Uint8List? localNurseSignature; // Now nullable
Uint8List? localEngineerSignature; // Now nullable
TimerModel? timer;
//TODO need to check when api provided..
List<TimerModel>? timerModelList = [];
List<GasRefillTimer>? gasRefillTimers = [];
List<GasRefillAttachments>? gasRefillAttachments;
int? statusValue;
GasRefillModel.fromJson(dynamic json) {
id = json['id'];
gazRefillNo = json['gazRefillNo'];
gasRefillNo = json['gasRefillNo'];
expectedDate = json['expectedDate'];
expectedTime = json['expectedTime'];
startDate = json['startDate'];
@ -55,18 +90,19 @@ class GasRefillModel {
endDate = json['endDate'];
endTime = json['endTime'];
comment = json['comment'];
techComment = json['techComment'];
workingHours = json['workingHours'];
extensionNo = json['extensionNo'];
employeeId = json['employeeId'];
name = json['name'];
createdDate = json['createdDate'];
//TODO need to use this when added from backend...
if (json['gasRefillTimer'] != null) {
gasRefillTimer = <GasRefillTimer>[];
json['gasRefillTimer'].forEach((v) {
gasRefillTimer?.add(GasRefillTimer.fromJson(v));
if (json['gasRefillTimers'] != null) {
gasRefillTimers = <GasRefillTimer>[];
json['gasRefillTimers'].forEach((v) {
gasRefillTimers?.add(GasRefillTimer.fromJson(v));
});
workingHours = json['gasRefillTimer'].fold(0.0, (sum, item) => (sum ?? 0) + DateTime.parse(item['endDateTime']).difference(DateTime.parse(item['startDateTime'])).inSeconds) ?? 0;
workingHours = json['gasRefillTimers'].fold(0.0, (sum, item) => (sum ?? 0) + DateTime.parse(item['endDate']).difference(DateTime.parse(item['startDate'])).inSeconds) ?? 0;
}
if (json['gasRefillAttachments'] != null) {
gasRefillAttachments = <GasRefillAttachments>[];
@ -75,23 +111,23 @@ class GasRefillModel {
});
}
try {
final DateTime? sd = DateTime.tryParse(startDate ?? "");
final DateTime? st = DateTime.tryParse(startTime ?? "");
final DateTime? ed = DateTime.tryParse(endDate ?? "");
final DateTime? et = DateTime.tryParse(endTime ?? "");
timer = TimerModel(
startAt: st == null ? sd : sd?.add(Duration(hours: st.hour, minutes: st.minute, seconds: st.second)), // Handle potential null 'sd'
endAt: et == null ? ed : ed?.add(Duration(hours: et.hour, minutes: et.minute, seconds: et.second)), // Handle potential null 'ed'
);
if (timer!.endAt != null && timer!.startAt != null) {
// Use '!' since timer could be null after initialization
timer!.durationInSecond = (timer!.endAt!.difference(timer!.startAt!)).inSeconds;
workingHours = (((timer!.durationInSecond ?? 0) / 60) / 60);
}
} catch (e) {
print(e);
}
// try {
// final DateTime? sd = DateTime.tryParse(startDate ?? "");
// final DateTime? st = DateTime.tryParse(startTime ?? "");
// final DateTime? ed = DateTime.tryParse(endDate ?? "");
// final DateTime? et = DateTime.tryParse(endTime ?? "");
// timer = TimerModel(
// startAt: st == null ? sd : sd?.add(Duration(hours: st.hour, minutes: st.minute, seconds: st.second)), // Handle potential null 'sd'
// endAt: et == null ? ed : ed?.add(Duration(hours: et.hour, minutes: et.minute, seconds: et.second)), // Handle potential null 'ed'
// );
// if (timer!.endAt != null && timer!.startAt != null) {
// // Use '!' since timer could be null after initialization
// timer!.durationInSecond = (timer!.endAt!.difference(timer!.startAt!)).inSeconds;
// workingHours = (((timer!.durationInSecond ?? 0) / 60) / 60);
// }
// } catch (e) {
// print(e);
// }
engSignature = json['engSignature'];
nurseSignature = json['nurseSignature'];
site = json['site'] != null ? Site.fromJson(json['site']) : null;
@ -100,96 +136,93 @@ class GasRefillModel {
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;
if (json['gazRefillDetails'] != null) {
gazRefillDetails = [];
json['gazRefillDetails'].forEach((v) {
gazRefillDetails!.add(GasRefillDetails.fromJson(v)); // Use '!' since gazRefillDetails is initialized here
if (json['gasRefillDetails'] != null) {
gasRefillDetails = [];
json['gasRefillDetails'].forEach((v) {
gasRefillDetails!.add(GasRefillDetails.fromJson(v)); // Use '!' since gasRefillDetails is initialized here
});
}
}
num? id; // Now nullable
String? gazRefillNo; // Now nullable
String? expectedDate; // Now nullable
String? expectedTime; // Now nullable
String? startDate; // Now nullable
String? startTime; // Now nullable
String? endDate; // Now nullable
String? endTime; // Now nullable
String? engSignature; // Now nullable
String? nurseSignature; // Now nullable
double? workingHours;
dynamic extensionNo;
String? employeeId;
String? name;
String? createdDate;
Site? site; // Now nullable
Building? building; // Now nullable
Floor? floor; // Now nullable
Department? department; // Now nullable
AssignedEmployee? assignedEmployee; // Now nullable
Lookup? status; // Now nullable
String? comment; // Now nullable
List<GasRefillDetails>? gazRefillDetails; // Now nullable
Uint8List? localNurseSignature; // Now nullable
Uint8List? localEngineerSignature; // Now nullable
TimerModel? timer;
//TODO need to check when api provided..
List<TimerModel>? timerModelList = [];
List<GasRefillTimer>? gasRefillTimer = [];
List<GasRefillAttachments>? gasRefillAttachments;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['id'] = id ?? 0;
map['gazRefillNo'] = "GR-${DateTime.now().toString().split(" ").first}";
map['expectedDate'] = expectedDate;
map['expectedTime'] = expectedTime;
map['startDate'] = startDate;
map['startTime'] = startTime;
map['endDate'] = endDate;
map['endTime'] = endTime;
map['engSignature'] = engSignature;
map['nurseSignature'] = nurseSignature;
map['workingHours'] = workingHours;
map['extensionNo'] = extensionNo;
map['employeeId'] = employeeId;
map['name'] = name;
map['createdDate'] = createdDate;
map['comment'] = comment;
//TODO need to check parameters here ...
if (gasRefillTimer != null) {
map['gasRefillTimer'] = gasRefillTimer?.map((v) => v.toJson()).toList();
}
if (gasRefillAttachments != null) {
map['gasRefillAttachments'] = gasRefillAttachments?.map((v) => v.toJson()).toList();
}
map['gasTypeId'] = gasRefillDetails?[0].gasType?.id;
map['cylinderTypeId'] = gasRefillDetails?[0].cylinderType?.id;
map['cylinderSizeId'] = gasRefillDetails?[0].cylinderSize?.id;
map['requestedQty'] = gasRefillDetails?[0].requestedQty;
if (site != null) {
map['site'] = site?.toJson(addBuildings: false); // Use '?.' for null safety
map['siteId'] = site?.id; // Use '?.' for null safety
}
if (building != null) {
map['building'] = building?.toJson(addFloor: false); // Use '?.' for null safety
map['buildingId'] = building?.id; // Use '?.' for null safety
}
if (floor != null) {
map['floor'] = floor?.toJson(addDepartments: false); // Use '?.' for null safety
map['floorId'] = floor?.id; // Use '?.' for null safety
}
if (department != null) {
map['department'] = department?.toJson(); // Use '?.' for null safety
map['departmentId'] = department?.id; // Use '?.' for null safety
}
if (assignedEmployee != null) {
map['assignedEmployee'] = assignedEmployee?.toJson(); // Use '?.' for null safety
map['comment'] = comment;
if (gasRefillAttachments != null) {
map['gasRefillAttachments'] = gasRefillAttachments?.map((v) => v.toJson()).toList();
}
if (status != null) {
map['status'] = status?.toJson(); // Use '?.' for null safety
//older code.....
// map['gasRefillNo'] = "GR-${DateTime.now().toString().split(" ").first}";
// map['expectedTime'] = expectedTime;
//
// map['startDate'] = startDate;
// map['startTime'] = startTime;
// map['endDate'] = endDate;
// map['endTime'] = endTime;
// map['engSignature'] = engSignature;
// map['nurseSignature'] = nurseSignature;
// map['workingHours'] = workingHours;
// map['extensionNo'] = extensionNo;
// map['employeeId'] = employeeId;
// map['name'] = name;
// map['createdDate'] = createdDate;
// map['comment'] = comment;
// if (site != null) {
// map['site'] = site?.toJson(addBuildings: false); // Use '?.' for null safety
// }
// if (building != null) {
// map['building'] = building?.toJson(addFloor: false); // Use '?.' for null safety
// }
// if (floor != null) {
// map['floor'] = floor?.toJson(addDepartments: false); // Use '?.' for null safety
// }
// if (department != null) {
// map['department'] = department?.toJson(); // Use '?.' for null safety
// }
// if (assignedEmployee != null) {
// map['assignedEmployee'] = assignedEmployee?.toJson(); // Use '?.' for null safety
// }
// if (status != null) {
// map['status'] = status?.toJson(); // Use '?.' for null safety
// }
// if (gasRefillDetails != null) {
// map['gasRefillDetails'] = gasRefillDetails!.map((v) => v.toJson()).toList(); // Use '!' since gasRefillDetails could be null
// }
return map;
}
Map<String, dynamic> toUpdateEngineerPayload({required int status}) {
final map = <String, dynamic>{};
map['id'] = id ?? 0;
map['deliveredQty'] = gasRefillDetails?[0].deliverdQty;
map['statusValue'] = status;
map['techComment'] = techComment;
if (gasRefillTimers != null) {
map['gasRefillTimers'] = gasRefillTimers?.map((v) => v.toJson()).toList();
}
if (gazRefillDetails != null) {
map['gazRefillDetails'] = gazRefillDetails!.map((v) => v.toJson()).toList(); // Use '!' since gazRefillDetails could be null
if (gasRefillAttachments != null) {
map['gasRefillAttachments'] = gasRefillAttachments?.map((v) => v.toJson()).toList();
}
return map;
}
@ -214,9 +247,9 @@ class GasRefillModel {
id = model.id;
//userId = model.userId;
site = model.site;
gazRefillNo = model.gazRefillNo;
gasRefillNo = model.gasRefillNo;
status = Lookup.fromStatus(model.status);
gazRefillDetails = model.gazRefillDetails;
gasRefillDetails = model.gasRefillDetails;
building = model.building;
floor = model.floor;
department = model.department;
@ -233,12 +266,13 @@ class GasRefillModel {
extensionNo = model.extensionNo;
employeeId = model.employeeId;
name = model.name;
techComment = model.techComment;
createdDate = model.createdDate;
}
GasRefillModel copyWith({
num? id, // Parameters are now nullable
String? gazRefillNo,
String? gasRefillNo,
String? expectedDate,
String? expectedTime,
String? startDate,
@ -259,14 +293,13 @@ class GasRefillModel {
AssignedEmployee? assignedEmployee,
Lookup? status,
String? comment,
List<GasRefillDetails>? gazRefillDetails,
List<GasRefillDetails>? gasRefillDetails,
List<GasRefillTimer>? gasRefillTimer,
TimerModel? timer,
}) =>
GasRefillModel(
id: id ?? this.id,
gazRefillNo: gazRefillNo ?? this.gazRefillNo,
gasRefillNo: gasRefillNo ?? this.gasRefillNo,
expectedDate: expectedDate ?? this.expectedDate,
expectedTime: expectedTime ?? this.expectedTime,
startDate: startDate ?? this.startDate,
@ -283,9 +316,9 @@ class GasRefillModel {
assignedEmployee: assignedEmployee ?? this.assignedEmployee,
status: status ?? this.status,
comment: comment ?? this.comment,
gazRefillDetails: gazRefillDetails ?? this.gazRefillDetails,
gasRefillDetails: gasRefillDetails ?? this.gasRefillDetails,
timer: timer ?? this.timer,
gasRefillTimer : gasRefillTimer ?? this.gasRefillTimer,
gasRefillTimers: gasRefillTimer ?? this.gasRefillTimers,
);
}
@ -369,51 +402,51 @@ class GasRefillDetails {
}
return true;
}
}
class GasRefillTimer {
int? id;
String? startTime;
String? endTime;
String? startDate;
String? endDate;
dynamic workingHours;
GasRefillTimer({this.id, this.startTime, this.endTime, this.workingHours});
GasRefillTimer({this.id, this.startDate, this.endDate, this.workingHours});
GasRefillTimer.fromJson(Map<String, dynamic> json) {
id = json['id'];
startTime = json['startDateTime'];
endTime = json['endDateTime'];
workingHours = json['workingHour'];
startDate = json['startDate'];
endDate = json['endDate'];
workingHours = json['workingHours'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['startDateTime'] = startTime;
data['endDateTime'] = endTime;
data['workingHour'] = workingHours;
data['startDate'] = startDate;
data['endDate'] = endDate;
data['workingHours'] = workingHours;
return data;
}
}
class GasRefillAttachments {
int? id;
num? gasRefillId;
String? attachmentName;
GasRefillAttachments({this.id, this.attachmentName});
GasRefillAttachments({this.id, this.attachmentName, this.gasRefillId});
GasRefillAttachments.fromJson(Map<String, dynamic> json) {
id = json['id'];
gasRefillId = json['gasRefillId'];
attachmentName = json['attachmentName'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['gasRefillId'] = gasRefillId;
data['attachmentName'] = attachmentName;
return data;
}
}

@ -1,7 +1,9 @@
import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/providers/api/user_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';
@ -21,9 +23,11 @@ import 'package:test_sa/providers/gas_request_providers/cylinder_type_provider.d
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';
import 'package:test_sa/service_request_latest/utilities/service_request_utils.dart';
import 'package:test_sa/service_request_latest/views/components/action_button/footer_action_button.dart';
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
import '../../controllers/providers/api/gas_refill_provider.dart';
import '../../controllers/validator/validator.dart';
import '../common_widgets/default_app_bar.dart';
class NewGasRefillRequestPage extends StatefulWidget {
@ -39,6 +43,8 @@ class _NewGasRefillRequestPageState extends State<NewGasRefillRequestPage> {
late GasRefillDetails _currentDetails;
late GasRefillModel _gasModel;
Lookup? _requestedQuantity;
final TextEditingController _commentController = TextEditingController();
GasRefillProvider? _gasRefillProvider;
static List<Lookup> gasQuantity = [
Lookup(name: "1", id: 1, value: 1),
@ -51,8 +57,11 @@ class _NewGasRefillRequestPageState extends State<NewGasRefillRequestPage> {
@override
void initState() {
super.initState();
_gasRefillProvider ??= Provider.of<GasRefillProvider>(context, listen: false);
_gasModel =GasRefillModel();
_currentDetails = GasRefillDetails();
_gasModel = GasRefillModel(gazRefillDetails: []);
_gasModel = GasRefillModel(gasRefillDetails: []);
_gasRefillProvider!.gasRefillAttachments.clear();
}
@override
@ -66,35 +75,28 @@ class _NewGasRefillRequestPageState extends State<NewGasRefillRequestPage> {
appBar: DefaultAppBar(title: context.translation.newGasRefillRequest),
body: Column(
children: [
12.height,
SingleChildScrollView(
child: Column(
children: [
16.height,
SingleItemDropDownMenu<Lookup, GasTypesProvider>(
context: context,
title: context.translation.gasType,
initialValue: _currentDetails.gasType,
backgroundColor: AppColor.neutral100,
showShadow: false,
showAsBottomSheet: true,
onSelect: (value) {
_currentDetails.gasType = value;
},
),
8.height,
SingleItemDropDownMenu<Lookup, NullableLoadingProvider>(
context: context,
title: context.translation.quantity,
initialValue: _requestedQuantity,
staticData: gasQuantity,
onSelect: (value) {
_requestedQuantity = value;
_currentDetails.requestedQty = value?.value;
},
),
8.height,
SingleItemDropDownMenu<Lookup, CylinderTypesProvider>(
context: context,
title: context.translation.cylinderType,
initialValue: _currentDetails.cylinderType,
backgroundColor: AppColor.neutral100,
showShadow: false,
onSelect: (value) {
_currentDetails.cylinderType = value;
},
@ -105,136 +107,153 @@ class _NewGasRefillRequestPageState extends State<NewGasRefillRequestPage> {
title: context.translation.cylinderSize,
initialValue: _currentDetails.cylinderSize,
showAsBottomSheet: true,
backgroundColor: AppColor.neutral100,
showShadow: false,
onSelect: (value) {
_currentDetails.cylinderSize = value;
},
),
8.height,
SingleItemDropDownMenu<Site, SiteProvider>(
SingleItemDropDownMenu<Lookup, NullableLoadingProvider>(
context: context,
title: context.translation.site,
initialValue: _gasModel.site,
title: context.translation.quantity,
showAsBottomSheet: true,
initialValue: _requestedQuantity,
staticData: gasQuantity,
backgroundColor: AppColor.neutral100,
showShadow: false,
onSelect: (value) {
setState(() {
_gasModel.site = value;
_gasModel.building = null;
_gasModel.floor = null;
_gasModel.department = null;
});
_requestedQuantity = value;
_currentDetails.requestedQty = value?.value;
},
),
8.height,
SingleItemDropDownMenu<Building, NullableLoadingProvider>(
context: context,
title: context.translation.building,
initialValue: _gasModel.building,
enabled: _gasModel.site?.buildings?.isNotEmpty ?? false,
staticData: _gasModel.site?.buildings ?? [],
showAsBottomSheet: true,
onSelect: (value) {
setState(() {
_gasModel.building = value;
_gasModel.floor = null;
_gasModel.department = null;
});
},
Row(
children: [
SingleItemDropDownMenu<Site, SiteProvider>(
context: context,
title: context.translation.site,
initialValue: _gasModel.site,
showAsBottomSheet: true,
backgroundColor: AppColor.neutral100,
showShadow: false,
onSelect: (value) {
setState(() {
_gasModel.site = value;
_gasModel.building = null;
_gasModel.floor = null;
_gasModel.department = null;
});
},
).expanded,
8.width,
SingleItemDropDownMenu<Building, NullableLoadingProvider>(
context: context,
title: context.translation.building,
initialValue: _gasModel.building,
enabled: _gasModel.site?.buildings?.isNotEmpty ?? false,
staticData: _gasModel.site?.buildings ?? [],
showAsBottomSheet: true,
backgroundColor: AppColor.neutral100,
showShadow: false,
onSelect: (value) {
setState(() {
_gasModel.building = value;
_gasModel.floor = null;
_gasModel.department = null;
});
},
).expanded,
],
),
8.height,
SingleItemDropDownMenu<Floor, NullableLoadingProvider>(
context: context,
title: context.translation.floor,
initialValue: _gasModel.floor,
enabled: _gasModel.building?.floors?.isNotEmpty ?? false,
staticData: _gasModel.building?.floors ?? [],
showAsBottomSheet: true,
onSelect: (value) {
setState(() {
_gasModel.floor = value;
_gasModel.department = null;
});
},
Row(
children: [
SingleItemDropDownMenu<Floor, NullableLoadingProvider>(
context: context,
title: context.translation.floor,
initialValue: _gasModel.floor,
enabled: _gasModel.building?.floors?.isNotEmpty ?? false,
staticData: _gasModel.building?.floors ?? [],
showAsBottomSheet: true,
backgroundColor: AppColor.neutral100,
showShadow: false,
onSelect: (value) {
setState(() {
_gasModel.floor = value;
_gasModel.department = null;
});
},
).expanded,
8.width,
SingleItemDropDownMenu<Department, NullableLoadingProvider>(
context: context,
title: context.translation.department,
initialValue: _gasModel.department,
enabled: _gasModel.floor?.departments?.isNotEmpty ?? false,
staticData: _gasModel.floor?.departments ?? [],
showAsBottomSheet: true,
backgroundColor: AppColor.neutral100,
showShadow: false,
onSelect: (value) {
_gasModel.department = value;
},
).expanded,
],
),
8.height,
SingleItemDropDownMenu<Department, NullableLoadingProvider>(
context: context,
title: context.translation.department,
initialValue: _gasModel.department,
enabled: _gasModel.floor?.departments?.isNotEmpty ?? false,
staticData: _gasModel.floor?.departments ?? [],
showAsBottomSheet: true,
onSelect: (value) {
_gasModel.department = value;
AppTextFormField(
labelText: context.translation.callComments,
labelStyle: AppTextStyles.tinyFont.copyWith(color: AppColor.neutral120),
textInputType: TextInputType.multiline,
alignLabelWithHint: true,
backgroundColor: AppColor.neutral100,
showShadow: false,
controller: _commentController,
onChange: (value){
_gasModel.comment = value;
},
onSaved: (value) {},
),
8.height,
if (_gasModel.gazRefillDetails?.isEmpty ?? true)
AppFilledButton(
label: context.translation.add,
maxWidth: true,
textColor: Colors.white,
buttonColor: context.isDark ? AppColor.neutral60 : AppColor.neutral50,
onPressed: _add,
),
ListView.builder(
shrinkWrap: true,
itemCount: _gasModel.gazRefillDetails?.length,
padding: const EdgeInsets.only(top: 12, bottom: 24),
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
(_gasModel.gazRefillDetails![index].gasType?.name ?? "").heading5(context),
8.height,
("${context.translation.quantity}: ${_gasModel.gazRefillDetails![index].requestedQty}").bodyText(context),
("${context.translation.cylinderSize}: ${_gasModel.gazRefillDetails![index].cylinderSize?.name}").bodyText(context),
("${context.translation.cylinderType}: ${_gasModel.gazRefillDetails![index].cylinderType?.name}").bodyText(context),
],
),
Container(
height: 48.toScreenWidth,
width: 48.toScreenWidth,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(color: context.isDark ? AppColor.neutral50 : AppColor.neutral30),
),
padding: EdgeInsets.symmetric(vertical: 12.toScreenHeight),
child: "trash".toSvgAsset(fit: BoxFit.fitHeight, color: context.isDark ? AppColor.red40 : AppColor.red50),
).onPress(() {
_delete(index);
}),
],
),
const Divider().defaultStyle(context),
("${context.translation.site}: ${_gasModel.site?.custName}").bodyText(context),
("${context.translation.building}: ${_gasModel.building?.name}").bodyText(context),
("${context.translation.floor}: ${_gasModel.floor?.name}").bodyText(context),
("${context.translation.department}: ${_gasModel.department?.departmentName}").bodyText(context),
],
).toShadowContainer(context);
},
MultiFilesPicker(
label: context.translation.attachFiles,
files: _gasRefillProvider!.gasRefillAttachments,
buttonColor: AppColor.black10,
onlyImages: false,
buttonIcon: 'image-plus'.toSvgAsset(color: AppColor.neutral120),
),
],
),
).toShadowContainer(context, padding: 10).paddingOnly(start: 16, end: 16, top: 16),
).expanded,
16.height,
AppFilledButton(label: context.translation.submitRequest, maxWidth: true, onPressed: _submit),
FooterActionButton.footerContainer(child: AppFilledButton(label: context.translation.submitRequest, maxWidth: true, onPressed: _submit)),
],
).paddingOnly(start: 16, end: 16, bottom: 24),
),
);
}
Future<void> _submit() async {
if (_currentDetails.gasType==null) {
Fluttertoast.showToast(msg: context.translation.youHaveToAddRequests);
return;
}
_gasModel.gasRefillDetails=[];
_gasModel.gasRefillDetails?.add(_currentDetails);
_gasModel.gasRefillAttachments = [];
for (var item in _gasRefillProvider!.gasRefillAttachments) {
_gasModel.gasRefillAttachments?.add(GasRefillAttachments(
id: 0, gasRefillId: _gasModel.id ?? 0, attachmentName: ServiceRequestUtils.isLocalUrl(item.path) ? "${item.path.split("/").last}|${base64Encode(item.readAsBytesSync())}" : item.path));
}
await _gasRefillProvider?.addGasRefillRequest(
context: context,
model: _gasModel,
);
}
void _add() async {
if (_currentDetails.validate(context) && _gasModel.validate(context)) {
_gasModel.gazRefillDetails!.add(_currentDetails);
_gasModel.gasRefillDetails!.add(_currentDetails);
_currentDetails = GasRefillDetails();
_requestedQuantity = null;
setState(() {});
@ -242,19 +261,62 @@ class _NewGasRefillRequestPageState extends State<NewGasRefillRequestPage> {
}
void _delete(index) {
_gasModel.gazRefillDetails!.remove(_gasModel.gazRefillDetails![index]);
_gasModel.gasRefillDetails!.remove(_gasModel.gasRefillDetails![index]);
setState(() {});
}
Future<void> _submit() async {
if (_gasModel.gazRefillDetails?.isEmpty ?? true) {
Fluttertoast.showToast(msg: context.translation.youHaveToAddRequests);
return;
}
await Provider.of<GasRefillProvider>(context, listen: false).createModel(
context: context,
user: Provider.of<UserProvider>(context, listen: false).user!,
model: _gasModel,
);
}
//older code....
// if (_gasModel.gasRefillDetails?.isEmpty ?? true)
// AppFilledButton(
// label: context.translation.add,
// maxWidth: true,
// textColor: Colors.white,
// buttonColor: context.isDark ? AppColor.neutral60 : AppColor.neutral50,
// onPressed: _add,
// ),
// ListView.builder(
// shrinkWrap: true,
// itemCount: _gasModel.gasRefillDetails?.length,
// padding: const EdgeInsets.only(top: 12, bottom: 24),
// physics: const NeverScrollableScrollPhysics(),
// itemBuilder: (context, index) {
// return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// (_gasModel.gasRefillDetails![index].gasType?.name ?? "").heading5(context),
// 8.height,
// ("${context.translation.quantity}: ${_gasModel.gasRefillDetails![index].requestedQty}").bodyText(context),
// ("${context.translation.cylinderSize}: ${_gasModel.gasRefillDetails![index].cylinderSize?.name}").bodyText(context),
// ("${context.translation.cylinderType}: ${_gasModel.gasRefillDetails![index].cylinderType?.name}").bodyText(context),
// ],
// ),
// Container(
// height: 48.toScreenWidth,
// width: 48.toScreenWidth,
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(100),
// border: Border.all(color: context.isDark ? AppColor.neutral50 : AppColor.neutral30),
// ),
// padding: EdgeInsets.symmetric(vertical: 12.toScreenHeight),
// child: "trash".toSvgAsset(fit: BoxFit.fitHeight, color: context.isDark ? AppColor.red40 : AppColor.red50),
// ).onPress(() {
// _delete(index);
// }),
// ],
// ),
// const Divider().defaultStyle(context),
// ("${context.translation.site}: ${_gasModel.site?.custName}").bodyText(context),
// ("${context.translation.building}: ${_gasModel.building?.name}").bodyText(context),
// ("${context.translation.floor}: ${_gasModel.floor?.name}").bodyText(context),
// ("${context.translation.department}: ${_gasModel.department?.departmentName}").bodyText(context),
// ],
// ).toShadowContainer(context);
// },
// ),
}

@ -7,6 +7,7 @@ import 'package:test_sa/extensions/context_extension.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/new_views/common_widgets/app_filled_button.dart';
import 'package:test_sa/views/pages/user/gas_refill/gas_refill_form.dart';
import 'package:test_sa/views/pages/user/gas_refill/request_gas_refill.dart';
import 'package:test_sa/views/widgets/loaders/app_loading.dart';
@ -31,7 +32,7 @@ class GasRefillDetailsPage extends StatefulWidget {
}
class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
GasRefillModel _model = GasRefillModel(gazRefillDetails: []);
GasRefillModel _model = GasRefillModel(gasRefillDetails: []);
late UserProvider _userProvider;
late GasRefillProvider gasRefillProvider;
final bool _isLoading = false;
@ -69,6 +70,14 @@ class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
padding: const EdgeInsets.all(16),
child: informationCard(_model),
).expanded,
if (_userProvider.user!.type == UsersTypes.engineer && (_model.status!.id! != 5833))//TODO need to check this value for complete status.
AppFilledButton(
onPressed: () async {
await Navigator.of(context).push(MaterialPageRoute(builder: (_) => GasRefillForm(gasRefillModel: _model)));
// getVisitData();
},
label: context.translation.updateRequest,
).paddingAll(16)
],
);
}
@ -110,21 +119,21 @@ class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
context.translation.gasRefillRequest.heading5(context),
8.height,
'${context.translation.gasRequest}: ${gasRefillModel.gazRefillDetails![0].gasType?.name}'.bodyText(context),
'${context.translation.cylinderType}: ${gasRefillModel.gazRefillDetails![0].cylinderType?.name}'.bodyText(context),
'${context.translation.cylinderSize}: ${gasRefillModel.gazRefillDetails![0].cylinderSize?.name}'.bodyText(context),
'${context.translation.gasRequest}: ${gasRefillModel.gasRefillDetails![0].gasType?.name}'.bodyText(context),
'${context.translation.cylinderType}: ${gasRefillModel.gasRefillDetails![0].cylinderType?.name}'.bodyText(context),
'${context.translation.cylinderSize}: ${gasRefillModel.gasRefillDetails![0].cylinderSize?.name}'.bodyText(context),
'${context.translation.site}: ${gasRefillModel.site?.name?.cleanupWhitespace.capitalizeFirstOfEach}'.bodyText(context),
'${context.translation.department}: ${gasRefillModel.department?.name?.cleanupWhitespace.capitalizeFirstOfEach}'.bodyText(context),
'${context.translation.requestNo}: ${gasRefillModel.gazRefillNo}'.bodyText(context),
'${context.translation.requestNo}: ${gasRefillModel.gasRefillNo}'.bodyText(context),
//TODO need to confirm where to display this new data...
infoText(label:context.translation.gasRequest ,value:gasRefillModel.extensionNo ),
infoText(label:context.translation.employeeId ,value:gasRefillModel.employeeId ),
infoText(label:context.translation.name ,value:gasRefillModel.name ),
infoText(label:context.translation.createdDate ,value:gasRefillModel.createdDate?.toInitialVisitCardFormat),
infoText(label: context.translation.gasRequest, value: gasRefillModel.extensionNo),
infoText(label: context.translation.employeeId, value: gasRefillModel.employeeId),
infoText(label: context.translation.name, value: gasRefillModel.name),
infoText(label: context.translation.createdDate, value: gasRefillModel.createdDate?.toInitialVisitCardFormat),
const Divider().defaultStyle(context),
'${context.translation.requestedQuantity}: ${gasRefillModel.gazRefillDetails![0].requestedQty ?? 0}'.bodyText(context),
'${context.translation.deliveredQuantity}: ${gasRefillModel.gazRefillDetails![0].deliverdQty ?? 0}'.bodyText(context),
'${context.translation.requestedQuantity}: ${gasRefillModel.gasRefillDetails![0].requestedQty ?? 0}'.bodyText(context),
'${context.translation.deliveredQuantity}: ${gasRefillModel.gasRefillDetails![0].deliverdQty ?? 0}'.bodyText(context),
8.height,
if (gasRefillModel.comment?.isNotEmpty ?? false) ...[
const Divider().defaultStyle(context),
@ -133,34 +142,11 @@ class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
]
],
).expanded,
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (_userProvider.user!.type == UsersTypes.engineer && (gasRefillModel.status?.value ?? 0) != 2)
"edit".toSvgAsset(height: 48, width: 48).onPress(
() async {
_model.fromGasRefillModel(gasRefillModel);
// setState(() {});
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => GasRefillForm(gasRefillModel: gasRefillModel),
),
).then((value) {
if (value != null) {
_model = value;
setState(() {});
}
});
},
),
if (_userProvider.user!.type == UsersTypes.engineer && (gasRefillModel.status?.value ?? 0) != 2) 8.height,
Text(
(widget.date ?? gasRefillModel.expectedDate)?.toServiceRequestCardFormat ?? "",
textAlign: TextAlign.end,
style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50),
),
],
if (_userProvider.user!.type == UsersTypes.engineer && (gasRefillModel.status?.value ?? 0) != 2) 8.height,
Text(
(widget.date ?? gasRefillModel.expectedDate)?.toServiceRequestCardFormat ?? "",
textAlign: TextAlign.end,
style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50),
),
],
).paddingOnly(top: 16, start: 16, end: 16),
@ -230,16 +216,14 @@ class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
).toShadowContainer(context, padding: 0);
}
Widget infoText({String ?label,String ?value,}){
if(value==null||value.isEmpty){
return const SizedBox();
}
else {
Widget infoText({
String? label,
String? value,
}) {
if (value == null || value.isEmpty) {
return const SizedBox();
} else {
return '$label: $value'.bodyText(context);
}
}
}

@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:flutter/material.dart';
@ -6,6 +7,7 @@ import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/api_routes/http_status_manger.dart';
import 'package:test_sa/controllers/providers/api/all_requests_provider.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';
@ -18,8 +20,10 @@ import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/timer_model.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart';
import 'package:test_sa/providers/loading_list_notifier.dart';
import 'package:test_sa/service_request_latest/utilities/service_request_utils.dart';
import 'package:test_sa/service_request_latest/views/components/action_button/footer_action_button.dart';
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
@ -58,7 +62,7 @@ class _GasRefillFormState extends State<GasRefillForm> {
final TextEditingController _commentController = TextEditingController();
final TextEditingController _workingHoursController = TextEditingController();
final GasRefillModel _formModel = GasRefillModel(gazRefillDetails: []);
final GasRefillModel _formModel = GasRefillModel(gasRefillDetails: []);
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final GlobalKey _DetailsKey = GlobalKey<FormState>();
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
@ -85,9 +89,9 @@ class _GasRefillFormState extends State<GasRefillForm> {
// totalWorkingHours =
// _formModel?.fold(0.0, (sum, item) => (sum ?? 0) + DateTime.parse(item.endDateTime!).difference(DateTime.parse(item.startDateTime!)).inSeconds) ?? 0;
_commentController.text = _formModel.comment ?? "";
_commentController.text = _formModel.techComment ?? "";
try {
_deliveredQuantity = deliveredQuantity.singleWhere((element) => element.value == _formModel.gazRefillDetails![0].deliverdQty);
_deliveredQuantity = deliveredQuantity.singleWhere((element) => element.value == _formModel.gasRefillDetails![0].deliverdQty);
_currentDetails.deliverdQty = _deliveredQuantity!.value;
} catch (ex) {}
}
@ -102,11 +106,8 @@ class _GasRefillFormState extends State<GasRefillForm> {
if (mounted) super.setState(() {});
}
_onSubmit(BuildContext context) async {
if (_formModel.status == null) {
await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.status}");
return false;
}
_onSubmit(BuildContext context,int status) async {
if (_formModel.timer?.startAt == null) {
await Fluttertoast.showToast(msg: "Working Hours Required");
return false;
@ -115,92 +116,50 @@ class _GasRefillFormState extends State<GasRefillForm> {
await Fluttertoast.showToast(msg: "Please Stop The Timer");
return false;
}
if (_formModel.gazRefillDetails?.isNotEmpty ?? false) {
if (!(await _addNewModel(context))) return;
if(_currentDetails.deliverdQty==null){
await Fluttertoast.showToast(msg: "Delivered Quantity is Required");
return false;
}
_formModel.gasRefillDetails=[];
_formModel.gasRefillDetails?.add(_currentDetails);
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
_formModel.gasRefillTimers = _formModel.gasRefillTimers ?? [];
//TODO need to check when added in backend....
_formModel.gasRefillTimer = _formModel.gasRefillTimer ?? [];
_formModel.timerModelList?.forEach((timer) {
int durationInSecond = timer.endAt!.difference(timer.startAt!).inSeconds;
_formModel.gasRefillTimer?.add(
_formModel.gasRefillTimers?.add(
GasRefillTimer(
id: 0,
startTime: timer.startAt!.toIso8601String(), // Handle potential null
endTime: timer.endAt?.toIso8601String(), // Handle potential null
startDate: timer.startAt!.toIso8601String(), // Handle potential null
endDate: timer.endAt?.toIso8601String(), // Handle potential null
workingHours: ((durationInSecond) / 60 / 60),
),
);
});
_formModel.gasRefillAttachments = [];
for (var item in _gasRefillProvider!.gasRefillAttachments) {
_formModel.gasRefillAttachments
?.add(GasRefillAttachments(id: 0, attachmentName: ServiceRequestUtils.isLocalUrl(item.path) ? "${item.path.split("/").last}|${base64Encode(item.readAsBytesSync())}" : item.path));
?.add(GasRefillAttachments(id: 0,gasRefillId: _formModel.id??0, attachmentName: ServiceRequestUtils.isLocalUrl(item.path) ? "${item.path.split("/").last}|${base64Encode(item.readAsBytesSync())}" : item.path));
}
await _gasRefillProvider
?.updateGasRefill(
status: status,
model: _formModel
)
.whenComplete(() {
if (status == 1) {
AllRequestsProvider allRequestsProvider = Provider.of<AllRequestsProvider>(context,listen: false);
// when click complete then this request remove from the list and status changes to closed..
_gasRefillProvider?.reset();
allRequestsProvider.getAllRequests(context, typeTransaction: 2);
}
Navigator.pop(context);
Navigator.pop(context);
});
//..till here...
setState(() {});
_formKey.currentState!.save();
_formModel.comment = _commentController.text;
int? status = widget.gasRefillModel == null
? 0 /*await _gasRefillProvider.createModel(
user: _userProvider.user,
model: _formModel,
)*/
: await _gasRefillProvider!.updateModel(
user: _userProvider.user!,
host: _settingProvider.host!,
oldModel: widget.gasRefillModel!,
newModel: _formModel,
);
//_isLoading = false;
setState(() {});
if (status >= 200 && status < 300) {
Fluttertoast.showToast(
msg: context.translation.successfulRequestMessage,
);
Navigator.of(context).pop(_formModel);
setState(() {});
} else {
String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: context.translation);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(errorMessage),
));
}
}
bool _addNewModel(BuildContext context) {
_validate = true;
if (_currentDetails.deliverdQty == null) {
Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.quantity}");
setState(() {});
return false;
}
// if (!_formKey.currentState!.validate()) {
// setState(() {});
// return false;
// }
_formKey.currentState!.save();
_currentDetails.gasType = _formModel.gazRefillDetails![0].gasType;
_currentDetails.cylinderSize = _formModel.gazRefillDetails![0].cylinderSize;
_currentDetails.cylinderType = _formModel.gazRefillDetails![0].cylinderType;
_currentDetails.requestedQty = _formModel.gazRefillDetails![0].requestedQty;
if (!(_currentDetails.validate(context))) {
setState(() {});
return false;
}
_formModel.gazRefillDetails![0].deliverdQty = _currentDetails.deliverdQty;
_validate = false;
// Scrollable.ensureVisible(_DetailsKey.currentContext);
_deliveredQuantityController.clear();
_workingHoursController.clear();
//_commentController.clear();
_currentDetails = GasRefillDetails();
setState(() {});
return true;
}
@override
void dispose() {
@ -235,14 +194,14 @@ class _GasRefillFormState extends State<GasRefillForm> {
clientName = _userProvider.user?.clientName;
}
HospitalsProvider().getHospitalsListByVal(searchVal: clientName ?? '').then((value) {
_gasRefillProvider!.hospital = value.firstWhere((element) => element.name == clientName, orElse: null);
_gasRefillProvider!.building = _gasRefillProvider!.hospital?.buildings?.firstWhere((element) => element.name == widget.gasRefillModel?.building?.name, orElse: null);
_gasRefillProvider!.floor = _gasRefillProvider!.building?.floors?.firstWhere((element) => element.name == widget.gasRefillModel?.floor?.name, orElse: null);
_gasRefillProvider!.department = _gasRefillProvider!.floor?.departments?.firstWhere((element) => element.name == widget.gasRefillModel?.department?.departmentName, orElse: null);
_firstTime = false;
setState(() {});
});
// HospitalsProvider().getHospitalsListByVal(searchVal: clientName ?? '').then((value) {
// _gasRefillProvider!.hospital = value.firstWhere((element) => element.name == clientName, orElse: null);
// _gasRefillProvider!.building = _gasRefillProvider!.hospital?.buildings?.firstWhere((element) => element.name == widget.gasRefillModel?.building?.name, orElse: null);
// _gasRefillProvider!.floor = _gasRefillProvider!.building?.floors?.firstWhere((element) => element.name == widget.gasRefillModel?.floor?.name, orElse: null);
// _gasRefillProvider!.department = _gasRefillProvider!.floor?.departments?.firstWhere((element) => element.name == widget.gasRefillModel?.department?.departmentName, orElse: null);
// _firstTime = false;
// setState(() {});
// });
}
return Scaffold(
appBar: DefaultAppBar(title: context.translation.gasRefill),
@ -268,10 +227,10 @@ class _GasRefillFormState extends State<GasRefillForm> {
// children: [
// context.translation.gasRefill.heading5(context),
// 8.height,
// '${context.translation.gasRequest}: ${widget.gasRefillModel!.gazRefillDetails![0].gasType!.name}'.bodyText(context),
// '${context.translation.cylinderType}: ${widget.gasRefillModel!.gazRefillDetails![0].cylinderType!.name}'.bodyText(context),
// '${context.translation.cylinderSize}: ${widget.gasRefillModel!.gazRefillDetails![0].cylinderSize!.name}'.bodyText(context),
// '${context.translation.quantity}: ${widget.gasRefillModel!.gazRefillDetails![0].requestedQty ?? 0}'.bodyText(context),
// '${context.translation.gasRequest}: ${widget.gasRefillModel!.gasRefillDetails![0].gasType!.name}'.bodyText(context),
// '${context.translation.cylinderType}: ${widget.gasRefillModel!.gasRefillDetails![0].cylinderType!.name}'.bodyText(context),
// '${context.translation.cylinderSize}: ${widget.gasRefillModel!.gasRefillDetails![0].cylinderSize!.name}'.bodyText(context),
// '${context.translation.quantity}: ${widget.gasRefillModel!.gasRefillDetails![0].requestedQty ?? 0}'.bodyText(context),
// '${context.translation.site}: ${widget.gasRefillModel!.site?.name}'.bodyText(context),
// ],
// ).toShadowContainer(context),
@ -289,6 +248,21 @@ class _GasRefillFormState extends State<GasRefillForm> {
},
),
8.height,
// AppTextFormField(
// initialValue: _formModel.gasRefillDetails?[0].deliverdQty?.toString() ?? "",
// labelText: context.translation.deliveredQuantity,
// onSaved: (value) {
// _currentDetails.deliverdQty = double.tryParse(value);
// },
// textInputType: TextInputType.number,
// controller: _deliveredQuantityController,
// validator: (value) => value == null || value.isEmpty
// ? context.translation.requiredField
// : Validator.isNumeric(value)
// ? null
// : context.translation.onlyNumbers,
// ),
// 8.height,
_timerWidget(context, _formModel.workingHours ?? 0),
8.height,
// SingleItemDropDownMenu<Lookup, GasStatusProvider>(
@ -309,21 +283,7 @@ class _GasRefillFormState extends State<GasRefillForm> {
// 8.height,
// 8.height,
// AppTextFormField(
// initialValue: _formModel.gazRefillDetails?[0].deliverdQty?.toString() ?? "",
// labelText: context.translation.deliveredQuantity,
// onSaved: (value) {
// _currentDetails.deliverdQty = double.tryParse(value);
// },
// textInputType: TextInputType.number,
// controller: _deliveredQuantityController,
// validator: (value) => value == null || value.isEmpty
// ? context.translation.requiredField
// : Validator.isNumeric(value)
// ? null
// : context.translation.onlyNumbers,
// ),
8.height,
/// TBD
AppTextFormField(
@ -333,6 +293,9 @@ class _GasRefillFormState extends State<GasRefillForm> {
backgroundColor: AppColor.neutral100,
showShadow: false,
controller: _commentController,
onChange: (value){
_formModel.techComment = value;
},
onSaved: (value) {},
),
16.height,
@ -370,12 +333,26 @@ class _GasRefillFormState extends State<GasRefillForm> {
],
).toShadowContainer(context),
).expanded,
AppFilledButton(
label: widget.gasRefillModel == null ? context.translation.submit : context.translation.update,
onPressed: () async {
_onSubmit.call(context);
},
).paddingAll(16),
FooterActionButton.footerContainer(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
AppFilledButton(
label: context.translation.save,
buttonColor: AppColor.white60,
textColor: AppColor.black10,
onPressed: () => _onSubmit(context, 0),
).expanded,
12.width,
AppFilledButton(
label: context.translation.complete,
buttonColor: AppColor.primary10,
onPressed: () => _onSubmit(context, 1),
).expanded,
],
),
),
],
)),
),

@ -53,7 +53,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
final TextEditingController _commentController = TextEditingController();
final TextEditingController _workingHoursController = TextEditingController();
final GasRefillModel _formModel = GasRefillModel(gazRefillDetails: []);
final GasRefillModel _formModel = GasRefillModel(gasRefillDetails: []);
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final GlobalKey _DetailsKey = GlobalKey<FormState>();
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
@ -77,7 +77,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
_formModel.fromGasRefillModel(widget.gasRefillModel!);
_commentController.text = _formModel.comment ?? "";
try {
_deliveredQuantity = deliveredQuantity.singleWhere((element) => element.value == _formModel.gazRefillDetails![0].deliverdQty);
_deliveredQuantity = deliveredQuantity.singleWhere((element) => element.value == _formModel.gasRefillDetails![0].deliverdQty);
_currentDetails.deliverdQty = _deliveredQuantity!.value;
} catch (ex) {}
}
@ -101,7 +101,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
await Fluttertoast.showToast(msg: "Please Stop The Timer");
return false;
}
if (_formModel.gazRefillDetails?.isNotEmpty ?? false) {
if (_formModel.gasRefillDetails?.isNotEmpty ?? false) {
if (!(await _addNewModel(context))) return;
}
@ -147,15 +147,15 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
// return false;
// }
_formKey.currentState!.save();
_currentDetails.gasType = _formModel.gazRefillDetails![0].gasType;
_currentDetails.cylinderSize = _formModel.gazRefillDetails![0].cylinderSize;
_currentDetails.cylinderType = _formModel.gazRefillDetails![0].cylinderType;
_currentDetails.requestedQty = _formModel.gazRefillDetails![0].requestedQty;
_currentDetails.gasType = _formModel.gasRefillDetails![0].gasType;
_currentDetails.cylinderSize = _formModel.gasRefillDetails![0].cylinderSize;
_currentDetails.cylinderType = _formModel.gasRefillDetails![0].cylinderType;
_currentDetails.requestedQty = _formModel.gasRefillDetails![0].requestedQty;
if (!( _currentDetails.validate(context))) {
setState(() {});
return false;
}
_formModel.gazRefillDetails![0].deliverdQty = _currentDetails.deliverdQty;
_formModel.gasRefillDetails![0].deliverdQty = _currentDetails.deliverdQty;
_validate = false;
// Scrollable.ensureVisible(_DetailsKey.currentContext);
_deliveredQuantityController.clear();
@ -225,10 +225,10 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
children: [
context.translation.gasRefill.heading5(context),
8.height,
'${context.translation.gasRequest}: ${widget.gasRefillModel!.gazRefillDetails![0].gasType!.name}'.bodyText(context),
'${context.translation.cylinderType}: ${widget.gasRefillModel!.gazRefillDetails![0].cylinderType!.name}'.bodyText(context),
'${context.translation.cylinderSize}: ${widget.gasRefillModel!.gazRefillDetails![0].cylinderSize!.name}'.bodyText(context),
'${context.translation.quantity}: ${widget.gasRefillModel!.gazRefillDetails![0].requestedQty ?? 0}'.bodyText(context),
'${context.translation.gasRequest}: ${widget.gasRefillModel!.gasRefillDetails![0].gasType!.name}'.bodyText(context),
'${context.translation.cylinderType}: ${widget.gasRefillModel!.gasRefillDetails![0].cylinderType!.name}'.bodyText(context),
'${context.translation.cylinderSize}: ${widget.gasRefillModel!.gasRefillDetails![0].cylinderSize!.name}'.bodyText(context),
'${context.translation.quantity}: ${widget.gasRefillModel!.gasRefillDetails![0].requestedQty ?? 0}'.bodyText(context),
'${context.translation.site}: ${widget.gasRefillModel!.site?.name}'.bodyText(context),
],
).toShadowContainer(context),

@ -41,7 +41,7 @@ class GasRefillItem extends StatelessWidget {
),
8.height,
context.translation.gasRefillRequest.heading5(context),
'${context.translation.gasType}: ${item.gazRefillDetails![0].gasType!.name}'.bodyText(context),
'${context.translation.gasType}: ${item.gasRefillDetails![0].gasType!.name}'.bodyText(context),
'${context.translation.site}: ${item.site!.name}'.bodyText(context),
8.height,
Row(

Loading…
Cancel
Save