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.
254 lines
10 KiB
Dart
254 lines
10 KiB
Dart
import 'package:flutter/material.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/lookup.dart';
|
|
import 'package:test_sa/modules/asset_tracking/filter_provider.dart';
|
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.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/common_widgets/multiple_item_drop_down_menu.dart';
|
|
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
|
|
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';
|
|
import '../../../new_views/common_widgets/default_app_bar.dart';
|
|
import 'models/asset_tracking_search_model.dart';
|
|
|
|
class AssetTrackingSearchScreen extends StatefulWidget {
|
|
static const String id = "asset_tracking_screen";
|
|
AssetTrackingSearchModel? searchModel;
|
|
|
|
AssetTrackingSearchScreen({Key? key, this.searchModel}) : super(key: key);
|
|
|
|
@override
|
|
State<AssetTrackingSearchScreen> createState() => _AssetTrackingSearchScreenState();
|
|
}
|
|
|
|
class _AssetTrackingSearchScreenState extends State<AssetTrackingSearchScreen> {
|
|
late AssetTrackingSearchModel searchModel;
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
late TextEditingController _searchController;
|
|
|
|
@override
|
|
void initState() {
|
|
searchModel = widget.searchModel ?? AssetTrackingSearchModel();
|
|
_searchController = TextEditingController(text: searchModel.search);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_searchController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: DefaultAppBar(
|
|
title: context.translation.search,
|
|
showBackButtonAsCancel: true,
|
|
actions: [
|
|
if (_showResetButton())
|
|
TextButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
_searchController.text = "";
|
|
searchModel = AssetTrackingSearchModel();
|
|
|
|
});
|
|
},
|
|
style: TextButton.styleFrom(padding: EdgeInsets.zero, tapTargetSize: MaterialTapTargetSize.shrinkWrap),
|
|
child: Text(
|
|
'Clear Filters',
|
|
style: AppTextStyles.bodyText2.copyWith(color: AppColor.red30),
|
|
),
|
|
).paddingOnly(start: 16, end: 16),
|
|
],
|
|
),
|
|
body: Form(
|
|
key: _formKey,
|
|
child: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
context.translation.searchBy.heading5(context).custom(color: AppColor.textStyleColor(context)),
|
|
4.height,
|
|
context.translation.searchByDesc.bodyText2(context).custom(color: AppColor.lightTextColor(context)),
|
|
16.height,
|
|
AppTextFormField(
|
|
controller: _searchController,
|
|
labelText: context.translation.search,
|
|
onChange: (text) {
|
|
_searchController.text = text;
|
|
_searchController.selection = TextSelection.fromPosition(TextPosition(offset: _searchController.text.length));
|
|
setState(() {});
|
|
},
|
|
onSaved: (value) {
|
|
searchModel.search = value;
|
|
},
|
|
),
|
|
8.height,
|
|
MultipleItemDropDownMenu<Lookup, TypeProvider>(
|
|
context: context,
|
|
title: 'Type',
|
|
initialValue: searchModel.types != null ? searchModel.types! : [],
|
|
showAsBottomSheet: true,
|
|
showShadow: true,
|
|
height: 56.toScreenHeight,
|
|
showCancel: true,
|
|
onSelect: (value) {
|
|
if (value != null) {
|
|
setState(() {
|
|
searchModel.types = value;
|
|
});
|
|
}
|
|
},
|
|
),
|
|
8.height,
|
|
MultipleItemDropDownMenu<Lookup, AssetTrackingDepartmentProvider>(
|
|
context: context,
|
|
title: 'Department',
|
|
initialValue: searchModel.departments != null ? searchModel.departments! : [],
|
|
showAsBottomSheet: true,
|
|
showShadow: true,
|
|
height: 56.toScreenHeight,
|
|
showCancel: true,
|
|
onSelect: (value) {
|
|
if (value != null) {
|
|
setState(() {
|
|
searchModel.departments = value;
|
|
});
|
|
}
|
|
},
|
|
),
|
|
8.height,
|
|
MultipleItemDropDownMenu<Lookup, AssetTrackingStatusProvider>(
|
|
context: context,
|
|
title: 'Status',
|
|
initialValue: searchModel.status != null ? searchModel.status! : [],
|
|
showAsBottomSheet: true,
|
|
showShadow: true,
|
|
height: 56.toScreenHeight,
|
|
showCancel: true,
|
|
onSelect: (value) {
|
|
if (value != null) {
|
|
setState(() {
|
|
searchModel.status = value;
|
|
});
|
|
}
|
|
},
|
|
),
|
|
8.height,
|
|
// MultipleItemDropDownMenu<Lookup, LastSeenProvider>(
|
|
// context: context,
|
|
// title: 'Last Seen',
|
|
// initialValue: searchModel.lastSeen != null ? searchModel.lastSeen! : [],
|
|
// showAsBottomSheet: true,
|
|
// showShadow: true,
|
|
// height: 56.toScreenHeight,
|
|
// showCancel: true,
|
|
// onSelect: (value) {
|
|
// if (value != null) {
|
|
// setState(() {
|
|
// searchModel.lastSeen = value;
|
|
// });
|
|
// }
|
|
// },
|
|
// ),
|
|
// 8.height,
|
|
// MultipleItemDropDownMenu<Lookup, TagStatusProvider>(
|
|
// context: context,
|
|
// title: 'Tag Status',
|
|
// initialValue: searchModel.tagStatus != null ? searchModel.tagStatus! : [],
|
|
// showAsBottomSheet: true,
|
|
// showShadow: true,
|
|
// height: 56.toScreenHeight,
|
|
// showCancel: true,
|
|
// onSelect: (value) {
|
|
// if (value != null) {
|
|
// setState(() {
|
|
// searchModel.tagStatus = value;
|
|
// });
|
|
// }
|
|
// },
|
|
// ),
|
|
// 8.height,
|
|
// MultipleItemDropDownMenu<Lookup, TagAssignmentProvider>(
|
|
// context: context,
|
|
// title: 'Tag Assignment',
|
|
// initialValue: searchModel.tagAssignment != null ? searchModel.tagAssignment! : [],
|
|
// showAsBottomSheet: true,
|
|
// showShadow: true,
|
|
// height: 56.toScreenHeight,
|
|
// showCancel: true,
|
|
// onSelect: (value) {
|
|
// if (value != null) {
|
|
// setState(() {
|
|
// searchModel.tagAssignment = value;
|
|
// });
|
|
// }
|
|
// },
|
|
// ),
|
|
8.height,
|
|
InfoHeader16Widget('Last Seen'),
|
|
8.height,
|
|
Row(
|
|
children: [
|
|
ADatePicker(
|
|
label: context.translation.from,
|
|
from: DateTime(2000),
|
|
date: DateTime.tryParse(searchModel.startDate ?? ""),
|
|
onDatePicker: (date) {
|
|
setState(() {
|
|
searchModel.startDate = date.toIso8601String();
|
|
});
|
|
},
|
|
).expanded,
|
|
8.width,
|
|
ADatePicker(
|
|
label: context.translation.to,
|
|
from: DateTime(2000),
|
|
date: DateTime.tryParse(searchModel.endDate ?? ""),
|
|
onDatePicker: (date) {
|
|
setState(() {
|
|
searchModel.endDate = date.toIso8601String();
|
|
});
|
|
},
|
|
).expanded,
|
|
],
|
|
),
|
|
],
|
|
).expanded,
|
|
FooterActionButton.footerContainer(context: context, child: AppFilledButton(onPressed: _search, label: context.translation.search)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _search() {
|
|
if (!_formKey.currentState!.validate()) {
|
|
return;
|
|
}
|
|
_formKey.currentState!.save();
|
|
Navigator.pop(context, searchModel);
|
|
}
|
|
|
|
bool _showResetButton() {
|
|
return (_searchController.text.isNotEmpty) ||
|
|
// (searchModel.tagAssignment != null && searchModel.tagAssignment!.isNotEmpty) ||
|
|
// (searchModel.tagStatus != null && searchModel.tagStatus!.isNotEmpty) ||
|
|
// (searchModel.lastSeen != null && searchModel.lastSeen!.isNotEmpty) ||
|
|
(searchModel.types != null && searchModel.types!.isNotEmpty) ||
|
|
(searchModel.status != null && searchModel.status!.isNotEmpty) ||
|
|
(searchModel.departments != null && searchModel.departments!.isNotEmpty)||
|
|
(searchModel.startDate != null && searchModel.startDate!.isNotEmpty) ||
|
|
(searchModel.endDate != null && searchModel.endDate!.isNotEmpty);
|
|
}
|
|
}
|