|
|
|
@ -5,17 +5,34 @@ import 'package:provider/provider.dart';
|
|
|
|
import 'package:test_sa/controllers/providers/api/all_requests_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/context_extension.dart';
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/extensions/string_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.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_filled_button.dart';
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../../../models/search_all_requests_model.dart';
|
|
|
|
import '../../../../models/search_all_requests_model.dart';
|
|
|
|
import '../../../common_widgets/app_lazy_loading.dart';
|
|
|
|
import '../../../common_widgets/app_lazy_loading.dart';
|
|
|
|
import '../../../common_widgets/default_app_bar.dart';
|
|
|
|
import '../../../common_widgets/default_app_bar.dart';
|
|
|
|
import '../widgets/request_search_buttons.dart';
|
|
|
|
import '../widgets/request_search_buttons.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum SortOrder {
|
|
|
|
|
|
|
|
ascending,
|
|
|
|
|
|
|
|
descending;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String get label {
|
|
|
|
|
|
|
|
switch (this) {
|
|
|
|
|
|
|
|
case SortOrder.ascending:
|
|
|
|
|
|
|
|
return "Ascending/Oldest";
|
|
|
|
|
|
|
|
case SortOrder.descending:
|
|
|
|
|
|
|
|
return "Descending/Newest";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class AllRequestsSearchPage extends StatefulWidget {
|
|
|
|
class AllRequestsSearchPage extends StatefulWidget {
|
|
|
|
static const String id = "all_requests_search_page";
|
|
|
|
static const String id = "all_requests_search_page";
|
|
|
|
final SearchAllRequestsModel? data;
|
|
|
|
final SearchAllRequestsModel? data;
|
|
|
|
@ -29,10 +46,25 @@ class AllRequestsSearchPage extends StatefulWidget {
|
|
|
|
class _AllRequestsSearchPageState extends State<AllRequestsSearchPage> {
|
|
|
|
class _AllRequestsSearchPageState extends State<AllRequestsSearchPage> {
|
|
|
|
SearchAllRequestsModel? search;
|
|
|
|
SearchAllRequestsModel? search;
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
|
|
|
|
SortOrder selectedSortOption = SortOrder.ascending;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
search = widget.data;
|
|
|
|
search = widget.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize from widget.data if available, otherwise default to Ascending
|
|
|
|
|
|
|
|
if (search?.selectedSortOption != null) {
|
|
|
|
|
|
|
|
// Match the saved sort option name to our enum
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
selectedSortOption = SortOrder.values.firstWhere(
|
|
|
|
|
|
|
|
(e) => e.name == search!.selectedSortOption,
|
|
|
|
|
|
|
|
orElse: () => SortOrder.ascending,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
selectedSortOption = SortOrder.ascending;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (search != null) {
|
|
|
|
if (search != null) {
|
|
|
|
search!.requestNumber?.controller?.text = search?.requestNumber?.value ?? "";
|
|
|
|
search!.requestNumber?.controller?.text = search?.requestNumber?.value ?? "";
|
|
|
|
search!.assetName?.controller?.text = search?.assetName?.value ?? "";
|
|
|
|
search!.assetName?.controller?.text = search?.assetName?.value ?? "";
|
|
|
|
@ -81,6 +113,9 @@ class _AllRequestsSearchPageState extends State<AllRequestsSearchPage> {
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
// search!.resetSearchValues();
|
|
|
|
// search!.resetSearchValues();
|
|
|
|
search?.resetSearchValuesAndController(except: null);
|
|
|
|
search?.resetSearchValuesAndController(except: null);
|
|
|
|
|
|
|
|
search!.startDate = null;
|
|
|
|
|
|
|
|
search!.endDate = null;
|
|
|
|
|
|
|
|
selectedSortOption = SortOrder.ascending;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
@ -132,6 +167,79 @@ class _AllRequestsSearchPageState extends State<AllRequestsSearchPage> {
|
|
|
|
search!.searchBySelectedValue!.value = value;
|
|
|
|
search!.searchBySelectedValue!.value = value;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
16.height,
|
|
|
|
|
|
|
|
"Sort".heading5(context),
|
|
|
|
|
|
|
|
8.height,
|
|
|
|
|
|
|
|
Row(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
for (var element in SortOrder.values)
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(right: 16),
|
|
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
|
|
|
width: 24,
|
|
|
|
|
|
|
|
height: 24,
|
|
|
|
|
|
|
|
child: Radio(
|
|
|
|
|
|
|
|
value: element,
|
|
|
|
|
|
|
|
activeColor: AppColor.primary10,
|
|
|
|
|
|
|
|
fillColor: WidgetStateColor.resolveWith((states) {
|
|
|
|
|
|
|
|
if (states.contains(WidgetState.selected)) {
|
|
|
|
|
|
|
|
return AppColor.primary10;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Colors.grey;
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
groupValue: selectedSortOption,
|
|
|
|
|
|
|
|
onChanged: (state) {
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
selectedSortOption = element;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
8.width,
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
element.label,
|
|
|
|
|
|
|
|
style: AppTextStyles.tinyFont.copyWith(color: AppColor.filterButtonTextColor(context)),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
16.height,
|
|
|
|
|
|
|
|
context.translation.pickDate.heading5(context),
|
|
|
|
|
|
|
|
8.height,
|
|
|
|
|
|
|
|
Row(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
ADatePicker(
|
|
|
|
|
|
|
|
label: context.translation.from,
|
|
|
|
|
|
|
|
from: DateTime(2000),
|
|
|
|
|
|
|
|
date: search!.startDate,
|
|
|
|
|
|
|
|
onDatePicker: (date) {
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
search!.startDate = date;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
).expanded,
|
|
|
|
|
|
|
|
8.width,
|
|
|
|
|
|
|
|
ADatePicker(
|
|
|
|
|
|
|
|
label: context.translation.to,
|
|
|
|
|
|
|
|
from: DateTime(2000),
|
|
|
|
|
|
|
|
date: search!.endDate,
|
|
|
|
|
|
|
|
onDatePicker: (date) {
|
|
|
|
|
|
|
|
if (search!.startDate != null && date.isBefore(search!.startDate!)) {
|
|
|
|
|
|
|
|
"End Date time must be greater then start date".showToast;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
search!.endDate = date;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
).expanded,
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).expanded,
|
|
|
|
).expanded,
|
|
|
|
@ -145,10 +253,15 @@ class _AllRequestsSearchPageState extends State<AllRequestsSearchPage> {
|
|
|
|
void _search() async {
|
|
|
|
void _search() async {
|
|
|
|
if (_formKey.currentState!.validate()) {
|
|
|
|
if (_formKey.currentState!.validate()) {
|
|
|
|
_formKey.currentState!.save();
|
|
|
|
_formKey.currentState!.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the enum name (ascending or descending) instead of label
|
|
|
|
|
|
|
|
search!.selectedSortOption = selectedSortOption.name;
|
|
|
|
|
|
|
|
|
|
|
|
final requestsProvider = Provider.of<AllRequestsProvider>(context, listen: false);
|
|
|
|
final requestsProvider = Provider.of<AllRequestsProvider>(context, listen: false);
|
|
|
|
|
|
|
|
if (search?.startDate != null) search?.endDate ??= DateTime.now();
|
|
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
|
|
requestsProvider.reset();
|
|
|
|
requestsProvider.reset();
|
|
|
|
await requestsProvider.getAllRequests(context, search: search);
|
|
|
|
await requestsProvider.getAllRequests(context, search: search, isAscending: selectedSortOption == SortOrder.ascending);
|
|
|
|
Navigator.pop(context);
|
|
|
|
Navigator.pop(context);
|
|
|
|
Navigator.of(context).pop(search);
|
|
|
|
Navigator.of(context).pop(search);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -160,6 +273,9 @@ class _AllRequestsSearchPageState extends State<AllRequestsSearchPage> {
|
|
|
|
(search?.assetNo?.controller?.text.isNotEmpty ?? false) ||
|
|
|
|
(search?.assetNo?.controller?.text.isNotEmpty ?? false) ||
|
|
|
|
(search?.manufacture?.controller?.text.isNotEmpty ?? false) ||
|
|
|
|
(search?.manufacture?.controller?.text.isNotEmpty ?? false) ||
|
|
|
|
(search?.sn?.controller?.text.isNotEmpty ?? false) ||
|
|
|
|
(search?.sn?.controller?.text.isNotEmpty ?? false) ||
|
|
|
|
(search?.model?.controller?.text.isNotEmpty ?? false);
|
|
|
|
(search?.model?.controller?.text.isNotEmpty ?? false) ||
|
|
|
|
|
|
|
|
(search?.startDate != null) ||
|
|
|
|
|
|
|
|
(search?.endDate != null) ||
|
|
|
|
|
|
|
|
selectedSortOption != SortOrder.ascending;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|