You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/views/widgets/search/service_request_search_bar....

332 lines
13 KiB
Dart

import 'package:flutter/material.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/service_request/service_request_search.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/app_style/sizing.dart';
import 'package:test_sa/views/widgets/buttons/app_button.dart';
import 'package:test_sa/views/widgets/buttons/app_small_button.dart';
import 'package:test_sa/views/widgets/hospitals/hospital_auto_complete_field.dart';
import 'package:test_sa/views/widgets/status/service_request/service_request_status_mune.dart';
import 'package:test_sa/views/widgets/switch_button.dart';
import 'package:test_sa/views/widgets/titles/app_sub_title.dart';
import '../../../models/call_request_for_work_order_model.dart';
import '../../../models/engineer.dart';
import '../app_text_form_field.dart';
import '../date_and_time/date_picker.dart';
import '../status/report/service_report_all_users.dart';
import '../status/report/service_report_visit_date_operator.dart';
class ServiceRequestsSearchDialog extends StatefulWidget {
final ServiceRequestSearch initialSearchValue;
final bool expandedSearch;
final Function(ServiceRequestSearch) onSearch;
const ServiceRequestsSearchDialog({Key key, this.initialSearchValue, this.expandedSearch, this.onSearch}) : super(key: key);
@override
_ServiceRequestsSearchDialogState createState() => _ServiceRequestsSearchDialogState();
}
class _ServiceRequestsSearchDialogState extends State<ServiceRequestsSearchDialog> with TickerProviderStateMixin {
ServiceRequestSearch _search;
List<Lookup> status = [
Lookup(
name: "New",
id: 4,
),
Lookup(
name: "Repaired",
id: 6,
),
Lookup(name: "Repeated", id: 8),
Lookup(
name: "Closed",
id: 9,
),
Lookup(
name: "Under Repair",
id: 5,
),
];
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
void initState() {
super.initState();
_search = ServiceRequestSearch();
_search.fromSearch(widget.initialSearchValue);
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.height / 1.2,
child: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ASmallButton(
text: context.translation.cancel,
onPressed: () {
Navigator.of(context).pop();
},
),
ASmallButton(
text: context.translation.search,
onPressed: () {
if (!_formKey.currentState.validate()) {
return;
}
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
)
],
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
ASwitchButton(
title: "Most Recent",
value: _search.mostRecent ?? false,
onChange: (value) {
_search.mostRecent = value;
setState(() {});
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
ATextFormField(
labelText: "Call ID",
onSaved: (value) {
_search.callId = value;
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
ATextFormField(
initialValue: _search.deviceNumber,
hintText: context.translation.assetNumber,
style: Theme.of(context).textTheme.headline6,
textInputAction: TextInputAction.search,
onAction: () {
if (!_formKey.currentState.validate()) {
return;
}
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
onSaved: (value) {
_search.deviceNumber = value;
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
ATextFormField(
initialValue: _search.deviceSerialNumber,
hintText: context.translation.serialNumber,
style: Theme.of(context).textTheme.headline6,
textInputAction: TextInputAction.search,
onAction: () {
if (!_formKey.currentState.validate()) {
return;
}
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
onSaved: (value) {
_search.deviceSerialNumber = value;
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
HospitalAutoCompleteField(
initialValue: _search.hospital?.name,
// onSave: (value){
// _search.hospital = value;
// },
onSearch: (value) {
_search.hospital = value;
Navigator.of(context).pop(_search);
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
ATextFormField(
initialValue: _search.deviceName,
hintText: context.translation.deviceName,
style: Theme.of(context).textTheme.headline6,
textInputAction: TextInputAction.search,
onAction: () {
if (!_formKey.currentState.validate()) {
return;
}
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
onSaved: (value) {
_search.deviceName = value;
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
ATextFormField(
initialValue: _search.model,
hintText: context.translation.model,
style: Theme.of(context).textTheme.headline6,
textInputAction: TextInputAction.search,
onAction: () {
if (!_formKey.currentState.validate()) {
return;
}
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
onSaved: (value) {
_search.model = value;
},
),
SizedBox(
height: 16 * AppStyle.getScaleFactor(context),
),
const ASubTitle("Status"),
const SizedBox(
height: 4,
),
ServiceRequestStatusMenu(
initialValue: _search.statusValue,
onSelect: (status) {
_search.statusValue = status;
},
),
SizedBox(
height: 16 * AppStyle.getScaleFactor(context),
),
ASubTitle(context.translation.assignedEmployee),
const SizedBox(height: 4),
ServiceReportAllUsers(
initialValue: _search.assignedEmployee == null ? null : Engineer(id: _search.assignedEmployee.id, name: _search.assignedEmployee.name),
onSelect: (engineer) {
_search.assignedEmployee = AssignedEmployee(id: engineer.id, name: engineer.name);
},
),
SizedBox(
height: 16 * AppStyle.getScaleFactor(context),
),
const ASubTitle("Request Date"),
const SizedBox(height: 4),
ServiceReportVisitDateOperator(
initialValue: _search.dateOperator,
onSelect: (status) {
_search.dateOperator = status;
setState(() {});
},
),
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (_search?.dateOperator?.name?.toLowerCase()?.contains("between") ?? false) const ASubTitle("From"),
ADatePicker(
date: DateTime.tryParse(_search.from ?? ""),
from: DateTime(1950),
onDatePicker: (date) {
_search.from = date?.toIso8601String();
setState(() {});
},
),
],
),
),
if (_search?.dateOperator?.name?.toLowerCase()?.contains("between") ?? false) const SizedBox(width: 16),
if (_search?.dateOperator?.name?.toLowerCase()?.contains("between") ?? false)
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const ASubTitle("To"),
ADatePicker(
date: DateTime.tryParse(_search.to ?? ""),
from: DateTime(1950),
onDatePicker: (date) {
_search.to = date?.toIso8601String();
setState(() {});
},
),
],
),
),
],
),
const SizedBox(width: 16),
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 12),
// child: Wrap(
// spacing: 10,
// runSpacing: 10,
// alignment: WrapAlignment.spaceEvenly,
// children: List.generate(
// status.length,
// (index) {
// bool isSelected = _search.statusValue == status[index];
// return FilterItem(
// isSelected: isSelected,
// onSelected: (){
// if(isSelected) {
// _search.statusValue = null;
// } else {
// _search.statusValue = status[index];
// }
//
// setState(() {});
// },
// status: status[index],
// );
// }
//
// ),
// ),
// ),
Visibility(
visible: widget.initialSearchValue.toMap().isNotEmpty,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: AButton(
padding: EdgeInsets.zero,
text: context.translation.clearSearch,
onPressed: () {
_search = ServiceRequestSearch();
Navigator.of(context).pop(_search);
},
),
),
),
],
),
),
),
),
);
}
}