diff --git a/lib/controllers/providers/api/regular_visits_provider.dart b/lib/controllers/providers/api/regular_visits_provider.dart index c530953..0d66fb3 100644 --- a/lib/controllers/providers/api/regular_visits_provider.dart +++ b/lib/controllers/providers/api/regular_visits_provider.dart @@ -72,11 +72,9 @@ class RegularVisitsProvider extends ChangeNotifier { if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received try { - List requestsListJson = - json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", "")); - List visits = - requestsListJson.map((request) => Visit.fromJson(request)).toList(); - visits.addAll(visits); + List requestsListJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", "")); + List visitsList = requestsListJson.map((request) => Visit.fromJson(request)).toList(); + visits.addAll(visitsList); if (visits.length == pageItemNumber) { nextPage = true; } else { @@ -149,22 +147,22 @@ class RegularVisitsProvider extends ChangeNotifier { } Future 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 body = pentry.toMap(); - body["uid"] = user.id ?? ""; - body["token"] = user.token ?? ""; + Map? 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; diff --git a/lib/models/pantry/pentry.dart b/lib/models/pantry/pentry.dart index a90dd9b..5212a1b 100644 --- a/lib/models/pantry/pentry.dart +++ b/lib/models/pantry/pentry.dart @@ -44,21 +44,15 @@ class Pentry { Map toMap() { Map 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 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 pmKits = []; if (map['pmKits'] != null) { - pmKits = (map['pmKits'] as List) - .map((e) => PMKit.fromMap(e as Map)) - .toList(); + pmKits = (map['pmKits'] as List).map((e) => PMKit.fromMap(e as Map)).toList(); } List ppmCheckLists = []; if (map['ppmCheckLists'] != null) { - ppmCheckLists = (map['ppmCheckLists'] as List) - .map((e) => PPMCheckList.fromMap(e as Map)) - .toList(); + ppmCheckLists = (map['ppmCheckLists'] as List).map((e) => PPMCheckList.fromMap(e as Map)).toList(); } List calibrationTools = []; if (map['calibrationTools'] != null) { - calibrationTools = (map['calibrationTools'] as List) - .map((e) => CalibrationTool.fromMap(e as Map)) - .toList(); + calibrationTools = (map['calibrationTools'] as List).map((e) => CalibrationTool.fromMap(e as Map)).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); } } diff --git a/lib/models/pantry/pm_kit.dart b/lib/models/pantry/pm_kit.dart index 09c9b78..58cd708 100644 --- a/lib/models/pantry/pm_kit.dart +++ b/lib/models/pantry/pm_kit.dart @@ -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 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 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?, ); } -} \ No newline at end of file +} diff --git a/lib/models/pantry/ppm_check_list.dart b/lib/models/pantry/ppm_check_list.dart index 444a108..b11b3a7 100644 --- a/lib/models/pantry/ppm_check_list.dart +++ b/lib/models/pantry/ppm_check_list.dart @@ -1,7 +1,6 @@ - import '../lookup.dart'; -class PPMCheckList{ +class PPMCheckList { Lookup? status; String? title; String? comment; @@ -16,19 +15,19 @@ class PPMCheckList{ Map 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 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?, ); } -} \ No newline at end of file +} diff --git a/lib/models/visits/visit.dart b/lib/models/visits/visit.dart index f3823b7..02490e0 100644 --- a/lib/models/visits/visit.dart +++ b/lib/models/visits/visit.dart @@ -1,7 +1,6 @@ - import '../lookup.dart'; -class Visit{ +class Visit { String? id; String? serialNumber; String? expectDate; @@ -42,7 +41,7 @@ class Visit{ this.deviceNumber, }); - factory Visit.fromJson(Map parsedJson){ + factory Visit.fromJson(Map parsedJson) { return Visit( id: parsedJson["nid"], serialNumber: parsedJson["title"], @@ -61,10 +60,10 @@ class Visit{ contactStatus: parsedJson["contactStatus"], images: List.from(parsedJson["images"] ?? []), status: Lookup( - id: int.tryParse(parsedJson["status"] ?? "-1")??-1, // actual value (0,1,2) - label: parsedJson["status_value"] // text value - ), + id: int.tryParse(parsedJson["status"] ?? "-1") ?? -1, // actual value (0,1,2) + label: parsedJson["status_value"] // text value + ), assignTo: parsedJson["assigned_to"], ); } -} \ No newline at end of file +} diff --git a/lib/views/pages/user/visits/pantry/edit_pentry.dart b/lib/views/pages/user/visits/pantry/edit_pentry.dart index b47a889..17c6f2f 100644 --- a/lib/views/pages/user/visits/pantry/edit_pentry.dart +++ b/lib/views/pages/user/visits/pantry/edit_pentry.dart @@ -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 createState() => _EditPentryState(); } -class _EditPentryState extends State with SingleTickerProviderStateMixin{ +class _EditPentryState extends State 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 _scaffoldKey = GlobalKey(); - 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 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 with SingleTickerProviderStateM @override Widget build(BuildContext context) { - _subtitle = AppLocalization.of(context)!.subtitle!; + _subtitle = AppLocalization.of(context)?.subtitle; _userProvider = Provider.of(context); _settingProvider = Provider.of(context); _regularVisitsProvider = Provider.of(context); @@ -98,91 +96,101 @@ class _EditPentryState extends State 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, - ), - ], - ), - ), - ) - ], - ), - ), - ], - ) + ), ), ), ); } } - diff --git a/lib/views/widgets/date_and_time/from_to_date_bar.dart b/lib/views/widgets/date_and_time/from_to_date_bar.dart index 13b7ca5..26e3df8 100644 --- a/lib/views/widgets/date_and_time/from_to_date_bar.dart +++ b/lib/views/widgets/date_and_time/from_to_date_bar.dart @@ -4,20 +4,22 @@ import '../../../controllers/localization/localization.dart'; import '../../../models/subtitle.dart'; import '../../app_style/sizing.dart'; import 'date_picker.dart'; + class FromToDateBar extends StatefulWidget { - final DateTime from; - final DateTime to; + final DateTime? from; + final DateTime? to; final Function(DateTime)? onPickFrom; final Function(DateTime)? onPickTo; const FromToDateBar({Key? key, required this.from, required this.to, this.onPickFrom, this.onPickTo}) : super(key: key); + @override _FromToDateBarState createState() => _FromToDateBarState(); } class _FromToDateBarState extends State { - late DateTime _from; - late DateTime _to; + late DateTime? _from; + late DateTime? _to; @override void initState() { @@ -32,22 +34,18 @@ class _FromToDateBarState extends State { return Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - _subtitle?.from??'', - style: Theme.of(context).textTheme.bodyText1?.copyWith( - fontSize: 12, - fontWeight: FontWeight.normal - ), + _subtitle?.from ?? '', + style: Theme.of(context).textTheme.bodyText1?.copyWith(fontSize: 12, fontWeight: FontWeight.normal), textScaleFactor: AppStyle.getScaleFactor(context), ), ADatePicker( date: _from, from: DateTime(1950), - onDatePicker: (date){ + onDatePicker: (date) { _from = date; setState(() {}); widget.onPickFrom!(date); @@ -59,17 +57,14 @@ class _FromToDateBarState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - _subtitle?.to??"", - style: Theme.of(context).textTheme.bodyText1?.copyWith( - fontSize: 12, - fontWeight: FontWeight.normal - ), + _subtitle?.to ?? "", + style: Theme.of(context).textTheme.bodyText1?.copyWith(fontSize: 12, fontWeight: FontWeight.normal), textScaleFactor: AppStyle.getScaleFactor(context), ), ADatePicker( date: _to, from: DateTime(1950), - onDatePicker: (date){ + onDatePicker: (date) { _to = date; setState(() {}); widget.onPickTo!(date); diff --git a/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart b/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart index b00c458..21f5a36 100644 --- a/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart +++ b/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart @@ -13,7 +13,9 @@ class PentryPPMCheckListForm extends StatefulWidget { final List? 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 { - - @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, + ), + ], + ); + }); } } diff --git a/lib/views/widgets/search/visits_search_bar.dart b/lib/views/widgets/search/visits_search_bar.dart index a9d2ce7..ebe885b 100644 --- a/lib/views/widgets/search/visits_search_bar.dart +++ b/lib/views/widgets/search/visits_search_bar.dart @@ -29,8 +29,7 @@ class VisitsSearchDialog extends StatefulWidget { VisitsSearchDialogState createState() => VisitsSearchDialogState(); } -class VisitsSearchDialogState extends State - with TickerProviderStateMixin { +class VisitsSearchDialogState extends State with TickerProviderStateMixin { VisitsSearch? _search; List status = const [ Lookup( @@ -195,8 +194,7 @@ class VisitsSearchDialogState extends State children: List.generate( contactStatus.length, (index) { - bool isSelected = - _search?.contactStatus == contactStatus[index].key; + bool isSelected = _search?.contactStatus == contactStatus[index].key; return FilterItem( isSelected: isSelected, onSelected: () { @@ -220,8 +218,8 @@ class VisitsSearchDialogState extends State height: 4.0 * AppStyle.getScaleFactor(context), ), FromToDateBar( - from: _search!.actualDateFrom!, - to: _search!.actualDateTo!, + from: _search?.actualDateFrom, + to: _search?.actualDateTo, onPickFrom: (date) { _search?.actualDateFrom = date; }, @@ -237,11 +235,8 @@ class VisitsSearchDialogState extends State height: 4.0 * AppStyle.getScaleFactor(context), ), FromToDateBar( - from: _search?.expectedDateFrom ?? - DateTime(today.year, today.month, 1), - to: _search?.expectedDateTo ?? - DateTime(today.year, (today.month + 1).clamp(1, 12), - today.month == 12 ? 31 : 0), + from: _search?.expectedDateFrom ?? DateTime(today.year, today.month, 1), + to: _search?.expectedDateTo ?? DateTime(today.year, (today.month + 1).clamp(1, 12), today.month == 12 ? 31 : 0), onPickFrom: (date) { _search?.expectedDateFrom = date; }, @@ -252,8 +247,7 @@ class VisitsSearchDialogState extends State Visibility( visible: _search?.toSearchString().isNotEmpty ?? false, child: Padding( - padding: - const EdgeInsets.symmetric(vertical: 8, horizontal: 16), + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), child: AButton( padding: EdgeInsets.zero, text: subtitle?.clearSearch ?? '', diff --git a/lib/views/widgets/status/single_status_menu.dart b/lib/views/widgets/status/single_status_menu.dart index 3e58db7..0b05dd7 100644 --- a/lib/views/widgets/status/single_status_menu.dart +++ b/lib/views/widgets/status/single_status_menu.dart @@ -26,11 +26,11 @@ class SingleStatusMenuState extends State { @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 { @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 { 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(),