EditPentry Screen & It's Pages

merge-requests/8/head
zaid_daoud 3 years ago
parent 0e87b0fbf9
commit 76969ea01b

@ -147,22 +147,22 @@ class RegularVisitsProvider extends ChangeNotifier {
}
Future<int> updatePentry({
required String host,
required User user,
required Pentry pentry,
required Visit visit,
required String? host,
required User? user,
required Pentry? pentry,
required Visit? visit,
}) async {
try {
Response response;
Map<String, String> body = pentry.toMap();
body["uid"] = user.id ?? "";
body["token"] = user.token ?? "";
Map<String, String>? body = pentry?.toMap();
body?["uid"] = user?.id ?? "";
body?["token"] = user?.token ?? "";
response = await post(
Uri.parse("$host${URLs.updatePentry}/${visit.id}"),
Uri.parse("$host${URLs.updatePentry}/${visit?.id}"),
body: body,
);
if (response.statusCode >= 200 && response.statusCode < 300) {
visit.status = pentry.ppmVisitStatus;
visit?.status = pentry?.ppmVisitStatus;
notifyListeners();
}
return response.statusCode;

@ -44,21 +44,15 @@ class Pentry {
Map<String, String> toMap() {
Map<String, String> map = {};
if (ppmVisitStatus != null)
map["visit_status"] = ppmVisitStatus!.id.toString();
if (ppmVisitStatus != null) map["visit_status"] = ppmVisitStatus!.id.toString();
if (status != null) map["pentry_status"] = status!.id.toString();
if (travelingHours != null) map["traveling_hours"] = travelingHours!;
if (imageFile != null)
map["file_attachement"] = base64Encode(imageFile!.readAsBytesSync());
map["actual_date"] = ((actualVisitDate?.millisecondsSinceEpoch ?? 0) / 1000)
.toStringAsFixed(0);
if (imageFile != null) map["file_attachement"] = base64Encode(imageFile!.readAsBytesSync());
map["actual_date"] = ((actualVisitDate?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
if (timer != null) {
map["start_date"] =
((timer!.startAt?.millisecondsSinceEpoch??0) / 1000).toStringAsFixed(0);
map["end_date"] =
(((timer!.endAt)?.millisecondsSinceEpoch??0) / 1000).toStringAsFixed(0);
map["working_hours"] =
((timer!.durationInSecond??0) / 60 / 60).toStringAsFixed(5);
map["start_date"] = ((timer!.startAt?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
map["end_date"] = (((timer!.endAt)?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
map["working_hours"] = ((timer!.durationInSecond ?? 0) / 60 / 60).toStringAsFixed(5);
}
// if(contacts?.isNotEmpty == true) {
// for(int i = 0;i<contacts.length;i++){
@ -67,10 +61,8 @@ class Pentry {
// });
// }
// }
map["ppmCheckLists"] =
jsonEncode(ppmCheckLists?.map((e) => e.toMap()).toList());
map["calibrationTools"] =
jsonEncode(calibrationTools?.map((e) => e.toMap()).toList());
map["ppmCheckLists"] = jsonEncode(ppmCheckLists?.map((e) => e.toMap()).toList());
map["calibrationTools"] = jsonEncode(calibrationTools?.map((e) => e.toMap()).toList());
map["pmKits"] = jsonEncode(pmKits?.map((e) => e.toMap()).toList());
return map;
}
@ -85,34 +77,24 @@ class Pentry {
List<PMKit> pmKits = [];
if (map['pmKits'] != null) {
pmKits = (map['pmKits'] as List<dynamic>)
.map((e) => PMKit.fromMap(e as Map<String, dynamic>))
.toList();
pmKits = (map['pmKits'] as List<dynamic>).map((e) => PMKit.fromMap(e as Map<String, dynamic>)).toList();
}
List<PPMCheckList> ppmCheckLists = [];
if (map['ppmCheckLists'] != null) {
ppmCheckLists = (map['ppmCheckLists'] as List<dynamic>)
.map((e) => PPMCheckList.fromMap(e as Map<String, dynamic>))
.toList();
ppmCheckLists = (map['ppmCheckLists'] as List<dynamic>).map((e) => PPMCheckList.fromMap(e as Map<String, dynamic>)).toList();
}
List<CalibrationTool> calibrationTools = [];
if (map['calibrationTools'] != null) {
calibrationTools = (map['calibrationTools'] as List<dynamic>)
.map((e) => CalibrationTool.fromMap(e as Map<String, dynamic>))
.toList();
calibrationTools = (map['calibrationTools'] as List<dynamic>).map((e) => CalibrationTool.fromMap(e as Map<String, dynamic>)).toList();
}
return Pentry(
status: Lookup.fromJson(map["pentry_status"]),
ppmVisitStatus: Lookup.fromJson(map["visit_status"]),
actualVisitDate: getDate(map["actual_date"]),
travelingHours: map["traveling_hours"],
timer: TimerModel(
startAt: getDate(map["start_date"]),
endAt: getDate(map["end_date"]),
durationInSecond:
(int.tryParse(map["working_hours"] ?? "") ?? 0) * 60 * 60),
timer: TimerModel(startAt: getDate(map["start_date"]), endAt: getDate(map["end_date"]), durationInSecond: (int.tryParse(map["working_hours"] ?? "") ?? 0) * 60 * 60),
// contacts: contacts,
ppmCheckLists: ppmCheckLists,
calibrationTools: calibrationTools,
@ -120,9 +102,7 @@ class Pentry {
);
}
static getDate(String date) {
return date.isEmpty
? null
: DateTime.fromMillisecondsSinceEpoch((int.tryParse(date) ?? 0) * 1000);
static getDate(String? date) {
return date == null || date.isEmpty ? null : DateTime.fromMillisecondsSinceEpoch((int.tryParse(date) ?? 0) * 1000);
}
}

@ -1,7 +1,6 @@
import '../lookup.dart';
class PMKit{
class PMKit {
Lookup? itemCode;
String? itemName;
String? preparationTimeFrame;
@ -10,37 +9,29 @@ class PMKit{
String? quantityNeeded;
String? quantityReserved;
PMKit({
this.itemCode,
this.itemName,
this.preparationTimeFrame,
this.kitFrequencyDemand,
this.availability,
this.quantityNeeded,
this.quantityReserved
});
PMKit({this.itemCode, this.itemName, this.preparationTimeFrame, this.kitFrequencyDemand, this.availability, this.quantityNeeded, this.quantityReserved});
Map<String, String> toMap() {
return {
if(itemCode != null) 'itemCode': (itemCode?.id).toString(),
if(itemName != null) 'itemName': itemName!,
if(preparationTimeFrame != null) 'preparationTimeFrame': preparationTimeFrame!,
if(kitFrequencyDemand != null) 'kitFrequencyDemand': kitFrequencyDemand!,
if(availability != null) 'availability': availability!,
if(quantityNeeded != null) 'quantityNeeded': quantityNeeded!,
if(quantityReserved != null) 'quantityReserved': quantityReserved!,
if (itemCode != null) 'itemCode': (itemCode?.id).toString(),
if (itemName != null) 'itemName': itemName!,
if (preparationTimeFrame != null) 'preparationTimeFrame': preparationTimeFrame!,
if (kitFrequencyDemand != null) 'kitFrequencyDemand': kitFrequencyDemand!,
if (availability != null) 'availability': availability!,
if (quantityNeeded != null) 'quantityNeeded': quantityNeeded!,
if (quantityReserved != null) 'quantityReserved': quantityReserved!,
};
}
factory PMKit.fromMap(Map<String, dynamic> map) {
return PMKit(
itemCode: Lookup.fromJson(map['itemCode']),
itemName: map['itemName'] as String,
preparationTimeFrame: map['preparationTimeFrame'] as String,
kitFrequencyDemand: map['kitFrequencyDemand'] as String,
availability: map['availability'] as String,
quantityNeeded: map['quantityNeeded'] as String,
quantityReserved: map['quantityReserved'] as String,
itemName: map['itemName'] as String?,
preparationTimeFrame: map['preparationTimeFrame'] as String?,
kitFrequencyDemand: map['kitFrequencyDemand'] as String?,
availability: map['availability'] as String?,
quantityNeeded: map['quantityNeeded'] as String?,
quantityReserved: map['quantityReserved'] as String?,
);
}
}
}

@ -1,7 +1,6 @@
import '../lookup.dart';
class PPMCheckList{
class PPMCheckList {
Lookup? status;
String? title;
String? comment;
@ -16,19 +15,19 @@ class PPMCheckList{
Map<String, String> toMap() {
return {
if(status != null) 'status': status!.id.toString(),
if(title != null) 'title': title!,
if(comment != null) 'comment': comment!,
if(measuredValue != null) 'measuredValue': measuredValue!,
if (status != null) 'status': status!.id.toString(),
if (title != null) 'title': title!,
if (comment != null) 'comment': comment!,
if (measuredValue != null) 'measuredValue': measuredValue!,
};
}
factory PPMCheckList.fromMap(Map<String, dynamic> map) {
return PPMCheckList(
status: Lookup.fromJson(map['status']),
title: map['title'] as String,
comment: map['comment'] as String,
measuredValue: map['measuredValue'] as String,
title: map['title'] as String?,
comment: map['comment'] as String?,
measuredValue: map['measuredValue'] as String?,
);
}
}
}

@ -20,50 +20,48 @@ import '../../../../widgets/pentry/pentry_ppm_check_list_form.dart';
class EditPentry extends StatefulWidget {
final Pentry? pentry;
final Visit? visit;
const EditPentry({Key? key,this.pentry, this.visit}) : super(key: key);
const EditPentry({Key? key, this.pentry, this.visit}) : super(key: key);
@override
State<EditPentry> createState() => _EditPentryState();
}
class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateMixin{
class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateMixin {
bool _isLoading = false;
bool _validate = false;
late Subtitle _subtitle;
Subtitle? _subtitle;
late UserProvider _userProvider;
late SettingProvider _settingProvider;
late RegularVisitsProvider _regularVisitsProvider;
late Pentry _pentry;
Pentry? _pentry;
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
late TabController _tabController;
late final TabController _tabController;
_onSubmit() async {
_validate = true;
if(!_pentry.validate()) {
setState(() { });
if (!(_pentry?.validate() ?? false)) {
setState(() {});
return;
}
_isLoading = true;
setState(() {});
int status = await _regularVisitsProvider.updatePentry(
user: _userProvider.user!,
host: _settingProvider.host??"",
pentry: _pentry,
visit: widget.visit!
);
_isLoading =false;
int status = await _regularVisitsProvider.updatePentry(user: _userProvider.user, host: _settingProvider.host, pentry: _pentry, visit: widget.visit);
_isLoading = false;
setState(() {});
if(status >= 200 && status < 300){
Fluttertoast.showToast(
msg: _subtitle.requestCompleteSuccessfully,
);
if (status >= 200 && status < 300) {
if (_subtitle != null) {
Fluttertoast.showToast(
msg: _subtitle!.requestCompleteSuccessfully,
);
}
// Navigator.of(context).pop();
}else{
String errorMessage = HttpStatusManger.getStatusMessage(
status: status, subtitle: _subtitle);
} else {
String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle);
Fluttertoast.showToast(
msg: errorMessage,
);
@ -72,7 +70,7 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
@override
void initState() {
_pentry = widget.pentry!;
_pentry = widget.pentry;
_tabController = TabController(length: 4, vsync: this);
super.initState();
}
@ -85,7 +83,7 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
@override
Widget build(BuildContext context) {
_subtitle = AppLocalization.of(context)!.subtitle!;
_subtitle = AppLocalization.of(context)?.subtitle;
_userProvider = Provider.of<UserProvider>(context);
_settingProvider = Provider.of<SettingProvider>(context);
_regularVisitsProvider = Provider.of<RegularVisitsProvider>(context);
@ -98,91 +96,101 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
stateCode: 200,
onRefresh: () async {},
child: Column(
children: [
Material(
color: Theme.of(context).colorScheme.primary,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: TabBar(
controller: _tabController,
isScrollable: true,
onTap: (index){
setState(() {});
},
tabs: const [
Tab(text: "PPM Check List",),
Tab(text: "Calibration Tools",),
Tab(text: "PK Kits",),
Tab(text: "Pentry",),
]),
children: [
Material(
color: Theme.of(context).colorScheme.primary,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: TabBar(
controller: _tabController,
isScrollable: true,
onTap: (index) {
setState(() {});
},
tabs: const [
Tab(
text: "PPM Check List",
),
Tab(
text: "Calibration Tools",
),
Tab(
text: "PK Kits",
),
Tab(
text: "Pentry",
),
]),
),
),
Expanded(
child: Stack(
children: [
TabBarView(
physics: const NeverScrollableScrollPhysics(),
controller: _tabController,
children: [
PentryPPMCheckListForm(
models: _pentry?.ppmCheckLists,
enableValidate: _validate,
),
PentryCalibrationToolForm(
models: _pentry?.calibrationTools,
enableValidate: _validate,
),
PentryPMKitForm(
models: _pentry?.pmKits,
enableValidate: _validate,
),
PentryInfoForm(
model: _pentry,
enableValidate: _validate,
)
],
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
if (_tabController.index != 0)
ASmallButton(
text: _subtitle?.back,
onPressed: () {
_tabController.animateTo(
_tabController.index - 1,
);
setState(() {});
},
),
const Spacer(),
if (_tabController.index != _tabController.length - 1)
ASmallButton(
text: _subtitle?.next,
onPressed: () {
_tabController.animateTo(
_tabController.index + 1,
);
setState(() {});
},
),
if (_tabController.index == _tabController.length - 1)
ASmallButton(
text: _subtitle?.update,
onPressed: _onSubmit,
),
],
),
),
)
],
),
),
),
Expanded(
child: Stack(
children: [
TabBarView(
physics: const NeverScrollableScrollPhysics(),
controller: _tabController,
children: [
PentryPPMCheckListForm(
models: _pentry.ppmCheckLists,
enableValidate: _validate,
),
PentryCalibrationToolForm(
models: _pentry.calibrationTools,
enableValidate: _validate,
),
PentryPMKitForm(
models: _pentry.pmKits,
enableValidate: _validate,
),
PentryInfoForm(
model: _pentry,
enableValidate: _validate,
)
],
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
if(_tabController.index != 0)
ASmallButton(
text: _subtitle.back,
onPressed: (){
_tabController.animateTo(_tabController.index - 1,);
setState(() {});
},
),
const Spacer(),
if(_tabController.index != _tabController.length -1)
ASmallButton(
text: _subtitle.next,
onPressed: (){
_tabController.animateTo(_tabController.index + 1,);
setState(() {});
},
),
if(_tabController.index == _tabController.length -1)
ASmallButton(
text: _subtitle.update,
onPressed: _onSubmit,
),
],
),
),
)
],
),
),
],
)
),
),
),
);
}
}

@ -13,7 +13,9 @@ class PentryPPMCheckListForm extends StatefulWidget {
final List<PPMCheckList>? models;
final bool? enableValidate;
const PentryPPMCheckListForm({
Key? key, this.models, this.enableValidate,
Key? key,
this.models,
this.enableValidate,
}) : super(key: key);
@override
@ -21,99 +23,112 @@ class PentryPPMCheckListForm extends StatefulWidget {
}
class _PentryPPMCheckListFormState extends State<PentryPPMCheckListForm> {
@override
Widget build(BuildContext context) {
final subtitle = AppLocalization.of(context)?.subtitle;
return ListView.builder(
padding: EdgeInsets.only(
top: 12 * AppStyle.getScaleFactor(context),
left: 12 * AppStyle.getScaleFactor(context),
right: 12 * AppStyle.getScaleFactor(context),
bottom: 80 * AppStyle.getScaleFactor(context)
),
itemCount: (widget.models?.length??0) + 1,
itemBuilder: (context,index){
if(index == widget.models?.length){
return AButton(
text: subtitle?.add??"",
onPressed: (){
widget.models!.add(PPMCheckList());
setState(() {});
},
);
}
final model = widget.models![index];
return ListView(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ASubTitle("#${index+1}"),
if(index != 0)
ASmallButton(
color: Theme.of(context).colorScheme.error,
text: subtitle!.delete,
onPressed: (){
widget.models!.remove(model);
setState(() {});
},
),
],
),
const SizedBox(height: 8,),
const ASubTitle("Task"),
const SizedBox(height: 4,),
ATextFormField(
initialValue: (model.title ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value){
model.title = value;
},
),
const SizedBox(height: 8,),
ASubTitle(subtitle?.status??""),
const SizedBox(height: 4,),
PentryTaskStatusMenu(
initialValue: model.status,
onSelect: (status){
model.status = status;
padding: EdgeInsets.only(
top: 12 * AppStyle.getScaleFactor(context), left: 12 * AppStyle.getScaleFactor(context), right: 12 * AppStyle.getScaleFactor(context), bottom: 80 * AppStyle.getScaleFactor(context)),
itemCount: (widget.models?.length ?? 0) + 1,
itemBuilder: (context, index) {
if (index == widget.models?.length) {
return AButton(
text: subtitle?.add ?? "",
onPressed: () {
widget.models?.add(PPMCheckList());
setState(() {});
},
),
const SizedBox(height: 8,),
const ASubTitle("Comment"),
const SizedBox(height: 4,),
ATextFormField(
initialValue: (model.comment ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value){
model.comment = value;
},
),
const SizedBox(height: 8,),
const ASubTitle("Measured Value"),
const SizedBox(height: 4,),
ATextFormField(
initialValue: (model.measuredValue ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value){
model.measuredValue = value;
},
),
const SizedBox(height: 8,),
Divider(color: Theme.of(context).textTheme.titleMedium?.color,),
],
);
}
);
);
}
final model = widget.models?[index];
return ListView(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ASubTitle("#${index + 1}"),
if (index != 0)
ASmallButton(
color: Theme.of(context).colorScheme.error,
text: subtitle?.delete,
onPressed: () {
widget.models?.remove(model);
setState(() {});
},
),
],
),
const SizedBox(
height: 8,
),
const ASubTitle("Task"),
const SizedBox(
height: 4,
),
ATextFormField(
initialValue: (model?.title ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value) {
model?.title = value;
},
),
const SizedBox(
height: 8,
),
ASubTitle(subtitle?.status ?? ""),
const SizedBox(
height: 4,
),
PentryTaskStatusMenu(
initialValue: model?.status,
onSelect: (status) {
model?.status = status;
},
),
const SizedBox(
height: 8,
),
const ASubTitle("Comment"),
const SizedBox(
height: 4,
),
ATextFormField(
initialValue: (model?.comment ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value) {
model?.comment = value;
},
),
const SizedBox(
height: 8,
),
const ASubTitle("Measured Value"),
const SizedBox(
height: 4,
),
ATextFormField(
initialValue: (model?.measuredValue ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value) {
model?.measuredValue = value;
},
),
const SizedBox(
height: 8,
),
Divider(
color: Theme.of(context).textTheme.titleMedium?.color,
),
],
);
});
}
}

@ -26,11 +26,11 @@ class SingleStatusMenuState extends State<SingleStatusMenu> {
@override
void didUpdateWidget(covariant SingleStatusMenu oldWidget) {
if (widget.initialStatus != null) {
_selectedStatus = widget.statuses?.firstWhere((element) {
return element.id == widget.initialStatus?.id;
});
} else {
_selectedStatus = null;
_selectedStatus = widget.initialStatus?.id != null
? widget.statuses?.firstWhere((element) {
return element.id == widget.initialStatus?.id;
})
: null;
}
super.didUpdateWidget(oldWidget);
}
@ -38,9 +38,11 @@ class SingleStatusMenuState extends State<SingleStatusMenu> {
@override
void initState() {
if (widget.initialStatus != null) {
_selectedStatus = widget.statuses?.firstWhere((element) {
return element.id == widget.initialStatus?.id;
});
_selectedStatus = widget.initialStatus?.id != null
? widget.statuses?.firstWhere((element) {
return element.id == widget.initialStatus?.id;
})
: null;
}
super.initState();
@ -87,9 +89,7 @@ class SingleStatusMenuState extends State<SingleStatusMenu> {
value: value,
child: Text(
value.label ?? '',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w600),
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Theme.of(context).primaryColor, fontWeight: FontWeight.w600),
),
);
}).toList(),

Loading…
Cancel
Save