|
|
|
|
@ -19,6 +19,7 @@ import 'package:mc_common_app/utils/utils.dart';
|
|
|
|
|
import 'package:mc_common_app/view_models/service_view_model.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/bottom_sheet.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/common_widgets/categories_list.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/tab/role_type_tab.dart';
|
|
|
|
|
@ -43,16 +44,14 @@ class CreateBranchModel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ServicesListPage extends StatefulWidget {
|
|
|
|
|
const ServicesListPage({Key? key}) : super(key: key);
|
|
|
|
|
const ServicesListPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<ServicesListPage> createState() => _ServicesListPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ServicesListPageState extends State<ServicesListPage> {
|
|
|
|
|
int selectedTab = 0;
|
|
|
|
|
ServiceStatusEnum selectedService = ServiceStatusEnum.approvedOrActive;
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> filteredServices = [];
|
|
|
|
|
late CategoryData categoryData;
|
|
|
|
|
|
|
|
|
|
@ -61,37 +60,22 @@ class _ServicesListPageState extends State<ServicesListPage> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
scheduleMicrotask(() async {
|
|
|
|
|
await _fetchServices(ServiceStatusEnum.approvedOrActive);
|
|
|
|
|
await _onRefresh(ServiceStatusEnum.approvedOrActive);
|
|
|
|
|
});
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _fetchServices(ServiceStatusEnum status) async {
|
|
|
|
|
categoryData.services = await context.read<ServiceVM>().fetchProviderServicesModelByCategoryIdAndBranchID(
|
|
|
|
|
branchID: categoryData.branchId.toString(),
|
|
|
|
|
categoryId: categoryData.id.toString(),
|
|
|
|
|
);
|
|
|
|
|
filteredServices = categoryData.services!.where((i) => i.serviceStatus == status.index + 1).toList();
|
|
|
|
|
|
|
|
|
|
screenState = ViewState.idle;
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _onRefresh(ServiceStatusEnum status, int tab) async {
|
|
|
|
|
Future<void> _onRefresh(ServiceStatusEnum status) async {
|
|
|
|
|
log("status: $status");
|
|
|
|
|
screenState = ViewState.busy;
|
|
|
|
|
selectedService = status;
|
|
|
|
|
selectedTab = tab;
|
|
|
|
|
setState(() {});
|
|
|
|
|
categoryData.services = await context.read<ServiceVM>().fetchProviderServicesModelByCategoryIdAndBranchID(
|
|
|
|
|
branchID: categoryData.branchId.toString(),
|
|
|
|
|
categoryId: categoryData.id.toString(),
|
|
|
|
|
);
|
|
|
|
|
context.read<ServiceVM>().applyFilterOnBranchServices(serviceStatusEnum: status);
|
|
|
|
|
filteredServices = categoryData.services!.where((i) => i.serviceStatusEnum == status).toList();
|
|
|
|
|
|
|
|
|
|
if (selectedService == ServiceStatusEnum.approvedOrActive) {
|
|
|
|
|
filteredServices = categoryData.services!.where((i) => i.serviceStatus == ServiceStatusEnum.approvedOrActive.index + 1).toList();
|
|
|
|
|
} else {
|
|
|
|
|
filteredServices = categoryData.services!.where((i) => i.serviceStatus != ServiceStatusEnum.approvedOrActive.index + 1).toList();
|
|
|
|
|
}
|
|
|
|
|
screenState = ViewState.idle;
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
@ -99,12 +83,14 @@ class _ServicesListPageState extends State<ServicesListPage> {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
categoryData = ModalRoute.of(context)!.settings.arguments as CategoryData;
|
|
|
|
|
final serviceVM = context.read<ServiceVM>();
|
|
|
|
|
|
|
|
|
|
if (context.read<ServiceVM>().isNeedRefreshServicesList) {
|
|
|
|
|
if (serviceVM.isNeedRefreshServicesList) {
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
if (mounted) {
|
|
|
|
|
_onRefresh(ServiceStatusEnum.pending, 1);
|
|
|
|
|
context.read<ServiceVM>().isNeedRefreshServicesList = false;
|
|
|
|
|
selectedService = ServiceStatusEnum.pending;
|
|
|
|
|
_onRefresh(ServiceStatusEnum.pending);
|
|
|
|
|
serviceVM.isNeedRefreshServicesList = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -130,33 +116,56 @@ class _ServicesListPageState extends State<ServicesListPage> {
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
|
|
|
|
|
child: RoleTypeTab(
|
|
|
|
|
selectedTab,
|
|
|
|
|
[
|
|
|
|
|
DropValue(0, 'Active', ''),
|
|
|
|
|
DropValue(1, 'Requested', ''),
|
|
|
|
|
],
|
|
|
|
|
width: (MediaQuery.of(context).size.width / 2) - 26,
|
|
|
|
|
onSelect: (DropValue value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
selectedTab = value.id;
|
|
|
|
|
if (selectedTab == 0) {
|
|
|
|
|
selectedService = ServiceStatusEnum.approvedOrActive;
|
|
|
|
|
filteredServices = categoryData.services!.where((i) => i.serviceStatus == ServiceStatusEnum.approvedOrActive.index + 1).toList();
|
|
|
|
|
} else {
|
|
|
|
|
selectedService = value.id.toServiceStatusEnum();
|
|
|
|
|
filteredServices = categoryData.services!.where((i) => i.serviceStatus != ServiceStatusEnum.approvedOrActive.index + 1).toList();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
20.height,
|
|
|
|
|
Consumer(
|
|
|
|
|
builder: (BuildContext context, ServiceVM serviceVM, Widget? child) {
|
|
|
|
|
return FiltersList(
|
|
|
|
|
filterList: serviceVM.branchServicesFilterOptions,
|
|
|
|
|
onFilterTapped: (index, selectedFilterId) {
|
|
|
|
|
selectedService = selectedFilterId.toServiceStatusEnum();
|
|
|
|
|
serviceVM.applyFilterOnBranchServices(serviceStatusEnum: selectedFilterId.toServiceStatusEnum());
|
|
|
|
|
filteredServices = categoryData.services!.where((i) => i.serviceStatusEnum == selectedFilterId.toServiceStatusEnum()).toList();
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Padding(
|
|
|
|
|
// padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
|
|
|
|
|
// child: RoleTypeTab(
|
|
|
|
|
// selectedTab,
|
|
|
|
|
// [
|
|
|
|
|
// DropValue(0, 'Active', ''),
|
|
|
|
|
// DropValue(1, 'Requested', ''),
|
|
|
|
|
// DropValue(2, 'Deactivated', ''),
|
|
|
|
|
// ],
|
|
|
|
|
// width: (MediaQuery.of(context).size.width / 3) - 26,
|
|
|
|
|
// onSelect: (DropValue value) {
|
|
|
|
|
// setState(() {
|
|
|
|
|
// selectedTab = value.id;
|
|
|
|
|
//
|
|
|
|
|
// if (selectedTab == 0) {
|
|
|
|
|
// selectedService = ServiceStatusEnum.approvedOrActive;
|
|
|
|
|
// filteredServices = categoryData.services!.where((i) => i.serviceStatusEnum == ServiceStatusEnum.approvedOrActive).toList();
|
|
|
|
|
// } else if (selectedTab == 2) {
|
|
|
|
|
// selectedService = ServiceStatusEnum.deactivated;
|
|
|
|
|
// filteredServices = categoryData.services!.where((i) => i.serviceStatusEnum == ServiceStatusEnum.deactivated).toList();
|
|
|
|
|
// } else {
|
|
|
|
|
// selectedService = value.id.toServiceStatusEnum();
|
|
|
|
|
// filteredServices =
|
|
|
|
|
// categoryData.services!.where((i) => (i.serviceStatusEnum != ServiceStatusEnum.approvedOrActive && i.serviceStatusEnum != ServiceStatusEnum.deactivated)).toList();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// },
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: RefreshIndicator(
|
|
|
|
|
onRefresh: () async => _onRefresh(selectedService, selectedTab),
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
_onRefresh(selectedService);
|
|
|
|
|
},
|
|
|
|
|
child: screenState == ViewState.busy
|
|
|
|
|
? const Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
|
@ -172,14 +181,14 @@ class _ServicesListPageState extends State<ServicesListPage> {
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
if (filteredServices[index].serviceStatus == 1) ...[
|
|
|
|
|
Utils.statusContainerChip(text: "Pending", chipColor: MyColors.adPendingStatusColor),
|
|
|
|
|
5.height,
|
|
|
|
|
],
|
|
|
|
|
// if (filteredServices[index].serviceStatusEnum == ServiceStatusEnum.pending) ...[
|
|
|
|
|
// Utils.statusContainerChip(text: "Pending", chipColor: MyColors.adPendingStatusColor),
|
|
|
|
|
// 5.height,
|
|
|
|
|
// ],
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(child: (filteredServices[index].serviceDescription ?? "").toText(fontSize: 16)),
|
|
|
|
|
if (filteredServices[index].serviceStatus != 1) ...[
|
|
|
|
|
if (filteredServices[index].serviceStatusEnum != ServiceStatusEnum.pending) ...[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(4.0),
|
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
|
@ -222,14 +231,20 @@ class _ServicesListPageState extends State<ServicesListPage> {
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const Icon(Icons.arrow_forward_rounded, size: 20),
|
|
|
|
|
if (filteredServices[index].serviceStatusEnum != ServiceStatusEnum.blocked) ...[
|
|
|
|
|
const Icon(Icons.arrow_forward_rounded, size: 20),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).toWhiteContainer(width: double.infinity, allPading: 12).onPress(
|
|
|
|
|
() => navigateWithName(context, AppRoutes.itemsList, arguments: filteredServices[index]),
|
|
|
|
|
);
|
|
|
|
|
).toWhiteContainer(width: double.infinity, allPading: 12).onPress(() {
|
|
|
|
|
if (filteredServices[index].serviceStatusEnum == ServiceStatusEnum.blocked) {
|
|
|
|
|
Utils.showToast(LocaleKeys.blockedByAdmin.tr());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
navigateWithName(context, AppRoutes.itemsList, arguments: filteredServices[index]);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (context, index) {
|
|
|
|
|
return const SizedBox(height: 12);
|
|
|
|
|
|