Search All Requests Done
parent
3c4d8b74e2
commit
e29946e280
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
|
||||||
|
class SearchAllRequestsModel {
|
||||||
|
SearchByRequestNumberModel requestNumber;
|
||||||
|
SearchByAssetNameModel assetName;
|
||||||
|
SearchByAssetNoModel assetNo;
|
||||||
|
SearchByManufactureModel manufacture;
|
||||||
|
SearchBySNModel sn;
|
||||||
|
SearchByRequestModel model;
|
||||||
|
SearchAllRequestsBaseModel selectedValue;
|
||||||
|
|
||||||
|
SearchAllRequestsModel({this.requestNumber, this.assetName, this.assetNo, this.manufacture, this.sn, this.model});
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class SearchAllRequestsBaseModel {
|
||||||
|
String label;
|
||||||
|
String value;
|
||||||
|
BuildContext context;
|
||||||
|
TextInputType inputType;
|
||||||
|
SearchAllRequestsBaseModel(BuildContext context, {this.label, this.value, this.inputType = TextInputType.text});
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchByRequestNumberModel extends SearchAllRequestsBaseModel {
|
||||||
|
SearchByRequestNumberModel(BuildContext context, {String value = "0"}) : super(context, label: "${context.translation.requestNo}.", value: value?.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchByAssetNameModel extends SearchAllRequestsBaseModel {
|
||||||
|
SearchByAssetNameModel(BuildContext context, {String value = "0"}) : super(context, label: context.translation.assetName, value: value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchByAssetNoModel extends SearchAllRequestsBaseModel {
|
||||||
|
SearchByAssetNoModel(BuildContext context, {String value = "0"}) : super(context, label: context.translation.assetNo, value: value, inputType: TextInputType.number);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchByManufactureModel extends SearchAllRequestsBaseModel {
|
||||||
|
SearchByManufactureModel(BuildContext context, {String value = "0"}) : super(context, label: context.translation.manufacture, value: value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchBySNModel extends SearchAllRequestsBaseModel {
|
||||||
|
SearchBySNModel(BuildContext context, {String value = "0"}) : super(context, label: context.translation.sn, value: value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchByRequestModel extends SearchAllRequestsBaseModel {
|
||||||
|
SearchByRequestModel(BuildContext context, {String value = "0"}) : super(context, label: context.translation.model, value: value);
|
||||||
|
}
|
||||||
@ -0,0 +1,110 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/models/new_models/department.dart';
|
||||||
|
import 'package:test_sa/models/new_models/site.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
|
||||||
|
import 'package:test_sa/providers/department_provider.dart';
|
||||||
|
import 'package:test_sa/providers/gas_request_providers/site_provider.dart';
|
||||||
|
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
|
||||||
|
|
||||||
|
import '../../../../views/widgets/equipment/equipment_status_buttons.dart';
|
||||||
|
import '../../../common_widgets/app_lazy_loading.dart';
|
||||||
|
import '../../../common_widgets/default_app_bar.dart';
|
||||||
|
|
||||||
|
class AllRequestsFilterPage extends StatefulWidget {
|
||||||
|
static const String id = "all_requests_filter_page";
|
||||||
|
// final AssetSearch data;
|
||||||
|
const AllRequestsFilterPage({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AllRequestsFilterPage> createState() => _AllRequestsFilterPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AllRequestsFilterPageState extends State<AllRequestsFilterPage> {
|
||||||
|
// AssetSearch filter;
|
||||||
|
Site _site;
|
||||||
|
Department _department;
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// filter = widget.data ?? AssetSearch();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: DefaultAppBar(title: context.translation.filter),
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
/// todo : TBD
|
||||||
|
EquipmentStatusButtons(onSelect: (value) {
|
||||||
|
if (value == null) {
|
||||||
|
/// the selected value is [All Assets]
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
16.height,
|
||||||
|
SingleItemDropDownMenu<Department, DepartmentProvider>(
|
||||||
|
context: context,
|
||||||
|
title: context.translation.byDepartment,
|
||||||
|
initialValue: _department,
|
||||||
|
onSelect: (value) {
|
||||||
|
_department = value;
|
||||||
|
},
|
||||||
|
).paddingOnly(start: 16, end: 16),
|
||||||
|
8.height,
|
||||||
|
SingleItemDropDownMenu<Site, SiteProvider>(
|
||||||
|
context: context,
|
||||||
|
title: context.translation.bySite,
|
||||||
|
initialValue: _site,
|
||||||
|
onSelect: (value) {
|
||||||
|
_site = value;
|
||||||
|
},
|
||||||
|
).paddingOnly(start: 16, end: 16),
|
||||||
|
16.height,
|
||||||
|
context.translation.pmDateRange.heading5(context).paddingOnly(start: 16, end: 16),
|
||||||
|
8.height,
|
||||||
|
|
||||||
|
/// todo : TBD
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
ADatePicker(
|
||||||
|
label: context.translation.from,
|
||||||
|
onDatePicker: (date) {},
|
||||||
|
).expanded,
|
||||||
|
8.width,
|
||||||
|
ADatePicker(
|
||||||
|
label: context.translation.to,
|
||||||
|
onDatePicker: (date) {},
|
||||||
|
).expanded,
|
||||||
|
],
|
||||||
|
).paddingOnly(start: 16, end: 16),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
).expanded,
|
||||||
|
AppFilledButton(onPressed: _search, label: context.translation.applyFilter).paddingOnly(start: 16, end: 16),
|
||||||
|
],
|
||||||
|
).paddingOnly(top: 16, bottom: 16),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _search() async {
|
||||||
|
// filter.site = _site?.name;
|
||||||
|
// filter.department = _department?.departmentName;
|
||||||
|
final deviceProvider = Provider.of<AssetProvider>(context, listen: false);
|
||||||
|
deviceProvider.reset();
|
||||||
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
||||||
|
// await deviceProvider.getAssets(search: filter);
|
||||||
|
Navigator.pop(context);
|
||||||
|
// Navigator.of(context).pop(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
||||||
|
import 'package:test_sa/new_views/pages/land_page/widgets/requests_search_button.dart';
|
||||||
|
|
||||||
|
import '../../../../models/search_all_requests_model.dart';
|
||||||
|
import '../../../common_widgets/app_lazy_loading.dart';
|
||||||
|
import '../../../common_widgets/default_app_bar.dart';
|
||||||
|
|
||||||
|
class AllRequestsSearchPage extends StatefulWidget {
|
||||||
|
static const String id = "all_requests_search_page";
|
||||||
|
final SearchAllRequestsModel data;
|
||||||
|
const AllRequestsSearchPage({Key key, this.data}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AllRequestsSearchPage> createState() => _AllRequestsSearchPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AllRequestsSearchPageState extends State<AllRequestsSearchPage> {
|
||||||
|
SearchAllRequestsModel search;
|
||||||
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
search = widget.data;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (search == null) {
|
||||||
|
search = SearchAllRequestsModel(
|
||||||
|
requestNumber: SearchByRequestNumberModel(context),
|
||||||
|
assetName: SearchByAssetNameModel(context),
|
||||||
|
assetNo: SearchByAssetNoModel(context),
|
||||||
|
manufacture: SearchByManufactureModel(context),
|
||||||
|
sn: SearchBySNModel(context),
|
||||||
|
model: SearchByRequestModel(context),
|
||||||
|
);
|
||||||
|
search.selectedValue = search.requestNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: DefaultAppBar(title: context.translation.search),
|
||||||
|
body: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
context.translation.searchBy.heading5(context),
|
||||||
|
8.height,
|
||||||
|
RequestsSearchButtons(
|
||||||
|
items: [search.requestNumber, search.assetName, search.assetNo, search.manufacture, search.sn, search.model],
|
||||||
|
initialValue: search.selectedValue,
|
||||||
|
onSelect: (value) {
|
||||||
|
if (search.selectedValue != value) {
|
||||||
|
search.selectedValue = value;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
16.height,
|
||||||
|
AppTextFormField(
|
||||||
|
controller: TextEditingController(text: search.selectedValue.value),
|
||||||
|
labelText: search.selectedValue.label,
|
||||||
|
textInputType: search.selectedValue.inputType,
|
||||||
|
onSaved: (value) {
|
||||||
|
search.selectedValue.value = value;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
).expanded,
|
||||||
|
AppFilledButton(onPressed: _search, label: context.translation.search),
|
||||||
|
],
|
||||||
|
).paddingAll(16),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _search() async {
|
||||||
|
if (_formKey.currentState.validate()) {
|
||||||
|
_formKey.currentState.save();
|
||||||
|
final requestsProvider = Provider.of<AllRequestsProvider>(context, listen: false);
|
||||||
|
// requestsProvider.reset();
|
||||||
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
||||||
|
await requestsProvider.getAllRequests(search: search);
|
||||||
|
Navigator.pop(context);
|
||||||
|
Navigator.of(context).pop(search);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
|
||||||
|
import '../../../../models/search_all_requests_model.dart';
|
||||||
|
import '../../../app_style/app_color.dart';
|
||||||
|
|
||||||
|
class RequestsSearchButtons extends StatefulWidget {
|
||||||
|
final Function(SearchAllRequestsBaseModel) onSelect;
|
||||||
|
final List<SearchAllRequestsBaseModel> items;
|
||||||
|
final SearchAllRequestsBaseModel initialValue;
|
||||||
|
|
||||||
|
const RequestsSearchButtons({Key key, @required this.items, this.initialValue, this.onSelect}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RequestsSearchButtons> createState() => _RequestsSearchButtonsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RequestsSearchButtonsState extends State<RequestsSearchButtons> {
|
||||||
|
SearchAllRequestsBaseModel _data;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_data = widget.initialValue;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant RequestsSearchButtons oldWidget) {
|
||||||
|
if (widget.initialValue != oldWidget.initialValue) {
|
||||||
|
setState(() {
|
||||||
|
_data = widget.initialValue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Wrap(
|
||||||
|
spacing: 8.toScreenWidth,
|
||||||
|
runSpacing: 8.toScreenHeight,
|
||||||
|
children: widget.items
|
||||||
|
.map(
|
||||||
|
(data) => Container(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 8.toScreenHeight, horizontal: (_data == data ? 12 : 8).toScreenWidth),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(7),
|
||||||
|
color: _data == data ? AppColor.neutral30 : Colors.white,
|
||||||
|
border: _data == data ? Border.all(width: 1, color: AppColor.primary50) : null,
|
||||||
|
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 14)],
|
||||||
|
),
|
||||||
|
child: data.label.tinyFont(context).custom(color: AppColor.neutral50),
|
||||||
|
).onPress(
|
||||||
|
() {
|
||||||
|
setState(() {
|
||||||
|
_data = data;
|
||||||
|
});
|
||||||
|
widget.onSelect(data);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue