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....

223 lines
7.7 KiB
Dart

3 years ago
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
3 years ago
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/service_request/service_request_search.dart';
3 years ago
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';
3 years ago
import 'package:test_sa/views/widgets/status/service_request/service_request_status_mune.dart';
import 'package:test_sa/views/widgets/titles/app_sub_title.dart';
3 years ago
import '../app_text_form_field.dart';
3 years ago
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);
3 years ago
@override
_ServiceRequestsSearchDialogState createState() => _ServiceRequestsSearchDialogState();
}
class _ServiceRequestsSearchDialogState extends State<ServiceRequestsSearchDialog> with TickerProviderStateMixin {
3 years ago
ServiceRequestSearch _search;
List<Lookup> status = [
Lookup(
name: "New",
id: 4,
),
Lookup(
name: "Repaired",
id: 6,
),
3 years ago
Lookup(name: "Repeated", id: 8),
Lookup(
name: "Closed",
id: 9,
),
Lookup(
name: "Under Repair",
id: 5,
),
3 years ago
];
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
void initState() {
super.initState();
_search = ServiceRequestSearch();
_search.fromSearch(widget.initialSearchValue);
}
3 years ago
@override
Widget build(BuildContext context) {
Subtitle _subtitle = AppLocalization.of(context).subtitle;
return SizedBox(
3 years ago
height: MediaQuery.of(context).size.height / 1.2,
child: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
3 years ago
crossAxisAlignment: CrossAxisAlignment.start,
3 years ago
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ASmallButton(
text: _subtitle.cancel,
onPressed: () {
3 years ago
Navigator.of(context).pop();
},
),
ASmallButton(
text: _subtitle.search,
onPressed: () {
if (!_formKey.currentState.validate()) {
3 years ago
return;
3 years ago
}
3 years ago
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
)
],
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
3 years ago
ATextFormField(
initialValue: _search.deviceSerialNumber,
hintText: _subtitle.serialNumber,
style: Theme.of(context).textTheme.headline6,
3 years ago
textInputAction: TextInputAction.search,
onAction: () {
if (!_formKey.currentState.validate()) {
3 years ago
return;
3 years ago
}
3 years ago
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
onSaved: (value) {
3 years ago
_search.deviceSerialNumber = value;
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
HospitalAutoCompleteField(
3 years ago
initialValue: _search.hospital?.name,
// onSave: (value){
// _search.hospital = value;
// },
onSearch: (value) {
3 years ago
_search.hospital = value;
Navigator.of(context).pop(_search);
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
3 years ago
ATextFormField(
initialValue: _search.deviceName,
hintText: _subtitle.deviceName,
style: Theme.of(context).textTheme.headline6,
3 years ago
textInputAction: TextInputAction.search,
onAction: () {
if (!_formKey.currentState.validate()) {
3 years ago
return;
3 years ago
}
3 years ago
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
onSaved: (value) {
3 years ago
_search.deviceName = value;
},
),
SizedBox(
height: 8.0 * AppStyle.getScaleFactor(context),
),
3 years ago
ATextFormField(
initialValue: _search.model,
hintText: _subtitle.model,
style: Theme.of(context).textTheme.headline6,
3 years ago
textInputAction: TextInputAction.search,
onAction: () {
if (!_formKey.currentState.validate()) {
3 years ago
return;
3 years ago
}
3 years ago
_formKey.currentState.save();
Navigator.of(context).pop(_search);
},
onSaved: (value) {
3 years ago
_search.model = value;
},
),
SizedBox(
height: 16 * AppStyle.getScaleFactor(context),
),
3 years ago
const ASubTitle("Status"),
const SizedBox(
height: 4,
),
3 years ago
ServiceRequestStatusMenu(
initialValue: _search.statusValue,
onSelect: (status) {
3 years ago
_search.statusValue = status;
},
3 years ago
),
3 years ago
// 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],
// );
// }
//
// ),
// ),
// ),
3 years ago
Visibility(
3 years ago
visible: widget.initialSearchValue.toMap().isNotEmpty,
3 years ago
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
3 years ago
child: AButton(
padding: EdgeInsets.zero,
text: _subtitle.clearSearch,
onPressed: () {
3 years ago
_search = ServiceRequestSearch();
Navigator.of(context).pop(_search);
3 years ago
},
),
),
),
],
),
),
),
);
}
}