[API doesn't support the required parameters] add search dialog to track asset transfer
parent
d80e28f706
commit
614426853b
@ -0,0 +1,49 @@
|
||||
import '../lookup.dart';
|
||||
|
||||
class DeviceTransferSearch {
|
||||
String assetName, assetNumber, site;
|
||||
bool mostRecent;
|
||||
Lookup dateOperator;
|
||||
String from, to;
|
||||
|
||||
DeviceTransferSearch({
|
||||
this.assetName,
|
||||
this.assetNumber,
|
||||
this.site,
|
||||
this.mostRecent,
|
||||
this.dateOperator,
|
||||
this.from,
|
||||
this.to,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
Map<String, dynamic> search = {};
|
||||
if (assetName != null && assetName.isNotEmpty) {
|
||||
search["assetName"] = assetName;
|
||||
}
|
||||
if (assetNumber != null && assetNumber.isNotEmpty) {
|
||||
search["assetNumber"] = assetNumber;
|
||||
}
|
||||
if (site != null && site.isNotEmpty) {
|
||||
search["site"] = site;
|
||||
}
|
||||
if (dateOperator != null && from != null) {
|
||||
search["requestedDateSymbol"] = dateOperator.toMap();
|
||||
search["requestedDateFrom"] = from;
|
||||
}
|
||||
if (dateOperator != null && to != null) {
|
||||
search["requestedDateTo"] = to;
|
||||
}
|
||||
return search;
|
||||
}
|
||||
|
||||
void fromSearch(DeviceTransferSearch newSearch) {
|
||||
assetName = newSearch.assetName;
|
||||
assetNumber = newSearch.assetNumber;
|
||||
site = newSearch.site;
|
||||
mostRecent = newSearch.mostRecent;
|
||||
from = newSearch.from;
|
||||
to = newSearch.to;
|
||||
dateOperator = newSearch.dateOperator;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,202 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:test_sa/controllers/localization/localization.dart';
|
||||
import 'package:test_sa/models/device/device_transfer_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 '../app_text_form_field.dart';
|
||||
import '../date_and_time/date_picker.dart';
|
||||
import '../status/report/service_report_visit_date_operator.dart';
|
||||
import '../switch_button.dart';
|
||||
import '../titles/app_sub_title.dart';
|
||||
|
||||
class AssetTransferSearchDialog extends StatefulWidget {
|
||||
final DeviceTransferSearch initialSearchValue;
|
||||
final bool expandedSearch;
|
||||
final Function(DeviceTransferSearch) onSearch;
|
||||
|
||||
const AssetTransferSearchDialog({Key key, this.initialSearchValue, this.expandedSearch, this.onSearch}) : super(key: key);
|
||||
@override
|
||||
AssetTransferSearchDialogState createState() => AssetTransferSearchDialogState();
|
||||
}
|
||||
|
||||
class AssetTransferSearchDialogState extends State<AssetTransferSearchDialog> with TickerProviderStateMixin {
|
||||
DeviceTransferSearch _search;
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_search = DeviceTransferSearch();
|
||||
_search.fromSearch(widget.initialSearchValue);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Subtitle subtitle = AppLocalization.of(context).subtitle;
|
||||
return SizedBox(
|
||||
height: MediaQuery.of(context).size.height / 1.3,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ASmallButton(
|
||||
text: subtitle.cancel,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
ASmallButton(
|
||||
text: subtitle.search,
|
||||
onPressed: () {
|
||||
if (!_formKey.currentState.validate()) {
|
||||
return;
|
||||
}
|
||||
_formKey.currentState.save();
|
||||
Navigator.of(context).pop(_search);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
ASwitchButton(
|
||||
title: "Most Recent",
|
||||
value: _search.mostRecent ?? false,
|
||||
onChange: (value) {
|
||||
_search.mostRecent = value;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
height: 8.0 * AppStyle.getScaleFactor(context),
|
||||
),
|
||||
ATextFormField(
|
||||
initialValue: _search.assetNumber,
|
||||
hintText: subtitle.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.assetNumber = value;
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
height: 8.0 * AppStyle.getScaleFactor(context),
|
||||
),
|
||||
ATextFormField(
|
||||
initialValue: _search.assetName,
|
||||
hintText: subtitle.assetName,
|
||||
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.site = value;
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
height: 8.0 * AppStyle.getScaleFactor(context),
|
||||
),
|
||||
ATextFormField(
|
||||
initialValue: _search.site,
|
||||
hintText: subtitle.site,
|
||||
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.assetName = value;
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
height: 8.0 * 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),
|
||||
Visibility(
|
||||
visible: _search.toMap().isNotEmpty,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||
child: AButton(
|
||||
padding: EdgeInsets.zero,
|
||||
text: subtitle.clearSearch,
|
||||
onPressed: () {
|
||||
_search = DeviceTransferSearch();
|
||||
Navigator.of(context).pop(_search);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue