Timer Fixed

main_design2.0
zaid_daoud 3 years ago
parent 0828307518
commit 4997e1e3df

@ -66,7 +66,6 @@ class DeviceTransfer {
startAt: DateTime.tryParse(parsedJson["senderStartDate"] ?? ""), startAt: DateTime.tryParse(parsedJson["senderStartDate"] ?? ""),
endAt: DateTime.tryParse(parsedJson["senderEndDate"] ?? ""), endAt: DateTime.tryParse(parsedJson["senderEndDate"] ?? ""),
durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 * 60).toInt(), durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 * 60).toInt(),
stopped: parsedJson["workingHours"] == null ? null : true,
), ),
// startDate: parsedJson["senderStartDate"] == null ? null : DateTime.parse(parsedJson["senderStartDate"]), // startDate: parsedJson["senderStartDate"] == null ? null : DateTime.parse(parsedJson["senderStartDate"]),
// endDate: parsedJson["senderEndDate"] == null ? null : DateTime.parse(parsedJson["senderEndDate"]), // endDate: parsedJson["senderEndDate"] == null ? null : DateTime.parse(parsedJson["senderEndDate"]),

@ -81,7 +81,6 @@ class DeviceTransferInfo {
startAt: DateTime.tryParse(parsedJson["${key}start_date"] ?? ""), startAt: DateTime.tryParse(parsedJson["${key}start_date"] ?? ""),
endAt: DateTime.tryParse(parsedJson["${key}end_date"] ?? ""), endAt: DateTime.tryParse(parsedJson["${key}end_date"] ?? ""),
durationInSecond: ((parsedJson["${key}working_hours"] ?? 0) * 60 * 60).toInt(), durationInSecond: ((parsedJson["${key}working_hours"] ?? 0) * 60 * 60).toInt(),
stopped: parsedJson["${key}working_hours"] == null || (parsedJson["${key}working_hours"] as String).isEmpty ? null : true,
), ),
travelingHours: parsedJson["${key}travel_hours"], travelingHours: parsedJson["${key}travel_hours"],
userName: parsedJson["${key}name"], userName: parsedJson["${key}name"],

@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/pantry/calibration_tools.dart'; import 'package:test_sa/models/pantry/calibration_tools.dart';
@ -45,12 +46,28 @@ class Pentry {
this.localNurseSignature, this.localNurseSignature,
this.localEngineerSignature}); this.localEngineerSignature});
bool validate() { Future<bool> validate() async {
if (actualVisitDate == null) return false; if (actualVisitDate == null) {
if (expectedVisitDate == null) return false; await Fluttertoast.showToast(msg: "Actual visit date is Required");
if (timer == null && timer.endAt != null) return false; return false;
}
if (expectedVisitDate == null) {
await Fluttertoast.showToast(msg: "expected visit date is Required");
return false;
}
if (timer?.startAt == null) {
await Fluttertoast.showToast(msg: "Working Hours Required");
return false;
}
if (timer?.endAt == null) {
await Fluttertoast.showToast(msg: "Please Stop The Timer");
return false;
}
if (ppmVisitStatus == null) return false; if (ppmVisitStatus == null) return false;
//if(status == null) return false; if (status?.id == null) {
await Fluttertoast.showToast(msg: "Device Status is Required");
return false;
}
return true; return true;
} }
@ -121,7 +138,6 @@ class Pentry {
startAt: DateTime.tryParse(map["startDate"] ?? ""), startAt: DateTime.tryParse(map["startDate"] ?? ""),
endAt: DateTime.tryParse(map["endDate"] ?? ""), endAt: DateTime.tryParse(map["endDate"] ?? ""),
durationInSecond: (int.tryParse(map["workingHours"] ?? "") ?? 0) * 60 * 60, durationInSecond: (int.tryParse(map["workingHours"] ?? "") ?? 0) * 60 * 60,
stopped: map["workingHours"] == null ? null : true,
), ),
// contacts: contacts, // contacts: contacts,
ppmCheckLists: ppmCheckLists, ppmCheckLists: ppmCheckLists,

@ -104,7 +104,7 @@ class ServiceReport {
// "workPerformed":workPreformed // "workPerformed":workPreformed
// }; // };
// } // }
_map["faultDescription"] = faultDescription?.id ==null ? null :{"id": faultDescription?.id ?? 0, "workPerformed": faultDescription?.workPerformed}; _map["faultDescription"] = faultDescription?.id == null ? null : {"id": faultDescription?.id ?? 0, "workPerformed": faultDescription?.workPerformed};
if (travelingHours != null) _map["travelingHours"] = travelingHours; if (travelingHours != null) _map["travelingHours"] = travelingHours;
// if (workingHours != null) _map["workingHours"] = workingHours; // if (workingHours != null) _map["workingHours"] = workingHours;
// if (workPreformed != null && workPreformed.isNotEmpty) { // if (workPreformed != null && workPreformed.isNotEmpty) {
@ -161,6 +161,14 @@ class ServiceReport {
await Fluttertoast.showToast(msg: "Visit Date Required"); await Fluttertoast.showToast(msg: "Visit Date Required");
return false; return false;
} }
if (timer?.startAt == null) {
await Fluttertoast.showToast(msg: "Working Hours Required");
return false;
}
if (timer?.endAt == null) {
await Fluttertoast.showToast(msg: "Please Stop The Timer");
return false;
}
//if(serviceType == null) return false; //if(serviceType == null) return false;
if (equipmentStatus == null) return false; if (equipmentStatus == null) return false;
//if (type == null && assetType == null) return false; //if (type == null && assetType == null) return false;
@ -217,7 +225,6 @@ class ServiceReport {
startAt: DateTime.tryParse(parsedJson["startofWorkTime"] ?? ""), startAt: DateTime.tryParse(parsedJson["startofWorkTime"] ?? ""),
endAt: DateTime.tryParse(parsedJson["endofWorkTime"] ?? ""), endAt: DateTime.tryParse(parsedJson["endofWorkTime"] ?? ""),
durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 * 60).toInt(), durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 * 60).toInt(),
stopped: parsedJson["workingHours"] == null ? null : true,
), ),
//workPreformed: parsedJson["work_performed"], //workPreformed: parsedJson["work_performed"],
device: Device.fromJson(parsedJson["callRequest"]["asset"]), device: Device.fromJson(parsedJson["callRequest"]["asset"]),

@ -2,7 +2,7 @@ class TimerModel {
DateTime startAt; DateTime startAt;
DateTime endAt; DateTime endAt;
int durationInSecond; int durationInSecond;
bool stopped; // bool stopped;
TimerModel({this.startAt, this.endAt, this.durationInSecond, this.stopped}); TimerModel({this.startAt, this.endAt, this.durationInSecond});
} }

@ -45,12 +45,13 @@ class _UpdateDeviceTransferState extends State<UpdateDeviceTransfer> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
_update() async { _update() async {
if (_formModel?.workingHours == null || _formModel.workingHours.isEmpty) { if (_formModel?.timer?.startAt == null) {
await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started"); await Fluttertoast.showToast(msg: "Working Hours Required");
return; return false;
} else if ((_formModel?.timer?.stopped ?? false) == false) { }
await Fluttertoast.showToast(msg: "Stop The Timer"); if (_formModel?.timer?.endAt == null) {
return; await Fluttertoast.showToast(msg: "Please Stop The Timer");
return false;
} }
_validate = true; _validate = true;
if (!_formKey.currentState.validate()) { if (!_formKey.currentState.validate()) {
@ -202,9 +203,8 @@ class _UpdateDeviceTransferState extends State<UpdateDeviceTransfer> {
onSaved: (signature) { onSaved: (signature) {
_signature = signature; _signature = signature;
if (signature == null || signature.isEmpty) return; if (signature == null || signature.isEmpty) return;
_formModel.signature = _formModel.signature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}";
"${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; // base64Encode(signature);
// base64Encode(signature);
}, },
), ),
Padding( Padding(

@ -157,9 +157,6 @@ class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomShee
if (_workOrder?.workingHours == null) { if (_workOrder?.workingHours == null) {
await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started"); await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started");
return; return;
} else if ((_workOrder?.timer?.stopped ?? false) == false) {
await Fluttertoast.showToast(msg: "Stop The Timer");
return;
} }
_formKey.currentState.save(); _formKey.currentState.save();
widget.subWorkOrder.copyFrom(_workOrder); widget.subWorkOrder.copyFrom(_workOrder);

@ -1009,9 +1009,6 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
if (_serviceReport?.workingHours == null) { if (_serviceReport?.workingHours == null) {
await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started"); await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started");
return; return;
} else if ((_serviceReport?.timer?.stopped ?? false) == false) {
await Fluttertoast.showToast(msg: "Stop The Timer");
return;
} }
_validate = true; _validate = true;
print("jere1245"); print("jere1245");

@ -42,7 +42,7 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
_onSubmit() async { _onSubmit() async {
_validate = true; _validate = true;
if (!_pentry.validate()) { if (!(await _pentry.validate())) {
setState(() {}); setState(() {});
return; return;
} }

@ -72,6 +72,7 @@ class _PentryInfoFormState extends State<PentryInfoForm> {
), ),
AppTimer( AppTimer(
timer: widget.model.timer, timer: widget.model.timer,
enabled: widget.model.timer.endAt == null,
onChange: (timer) async { onChange: (timer) async {
widget.model.timer = timer; widget.model.timer = timer;
return true; return true;

@ -34,7 +34,7 @@ class _AppTimerState extends State<AppTimer> {
_startTimer() async { _startTimer() async {
if (!_running) { if (!_running) {
final time = DateTime.now(); final time = DateTime.now();
bool result = await widget.onChange(TimerModel(startAt: time, endAt: null, durationInSecond: _delay, stopped: false)); bool result = await widget.onChange(TimerModel(startAt: time, endAt: null, durationInSecond: _delay));
if (!result) return; if (!result) return;
_running = true; _running = true;
@ -54,7 +54,7 @@ class _AppTimerState extends State<AppTimer> {
_stopTimer() async { _stopTimer() async {
final time = DateTime.now(); final time = DateTime.now();
final tempStartAt = _startAt.add(Duration(seconds: _delay)); final tempStartAt = _startAt.add(Duration(seconds: _delay));
bool result = await widget.onChange(TimerModel(startAt: tempStartAt, endAt: time, durationInSecond: _delay, stopped: true)); bool result = await widget.onChange(TimerModel(startAt: tempStartAt, endAt: time, durationInSecond: _delay));
if (!result) return; if (!result) return;
_running = false; _running = false;
_endAt = time; _endAt = time;

Loading…
Cancel
Save