|
|
|
|
@ -18,9 +18,76 @@ import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/shimmer/home_shimmer_widgets.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class BranchesFragment extends StatelessWidget {
|
|
|
|
|
class BranchesFragment extends StatefulWidget {
|
|
|
|
|
const BranchesFragment({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<BranchesFragment> createState() => _BranchesFragmentState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _BranchesFragmentState extends State<BranchesFragment> {
|
|
|
|
|
final TextEditingController _searchController = TextEditingController();
|
|
|
|
|
final FocusNode _searchFocusNode = FocusNode();
|
|
|
|
|
String _searchQuery = '';
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_searchController.dispose();
|
|
|
|
|
_searchFocusNode.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<BranchDetailModel> _filterBranches(List<BranchDetailModel> branches) {
|
|
|
|
|
if (_searchQuery.isEmpty) {
|
|
|
|
|
return branches;
|
|
|
|
|
}
|
|
|
|
|
return branches.where((branch) {
|
|
|
|
|
return (branch.branchName ?? '').toLowerCase().contains(_searchQuery.toLowerCase());
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSearchField() {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 21),
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 55,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.grey[200],
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(color: Colors.grey[300]!, width: 1),
|
|
|
|
|
),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: _searchController,
|
|
|
|
|
focusNode: _searchFocusNode,
|
|
|
|
|
style: const TextStyle(fontSize: 16),
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_searchQuery = value;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: LocaleKeys.searchByBranch.tr(),
|
|
|
|
|
hintStyle: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
|
|
|
|
prefixIcon: Icon(Icons.search, size: 26, color: Colors.grey[700]),
|
|
|
|
|
suffixIcon: _searchQuery.isEmpty
|
|
|
|
|
? null
|
|
|
|
|
: InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
_searchController.clear();
|
|
|
|
|
_searchQuery = '';
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Icon(Icons.close, size: 22, color: Colors.grey[700]),
|
|
|
|
|
),
|
|
|
|
|
border: InputBorder.none,
|
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 18, vertical: 16),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final isArabic = AppState().isArabic(context);
|
|
|
|
|
@ -48,59 +115,68 @@ class BranchesFragment extends StatelessWidget {
|
|
|
|
|
).toViewOnly(context, onTap: () {
|
|
|
|
|
navigateWithName(context, AppRoutes.loginWithPassword, arguments: false);
|
|
|
|
|
}),
|
|
|
|
|
body: SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: double.infinity,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
if (appointmentsVM.branchesCategoriesFilterOptions.isNotEmpty) ...[
|
|
|
|
|
body: GestureDetector(
|
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
|
onTap: () => _searchFocusNode.unfocus(),
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: double.infinity,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
16.height,
|
|
|
|
|
FiltersList(
|
|
|
|
|
filterList: appointmentsVM.branchesCategoriesFilterOptions,
|
|
|
|
|
onFilterTapped: (index, selectedFilterId) => appointmentsVM.applyFilterOnBranches(index: index),
|
|
|
|
|
scrollController: appointmentsVM.branchesFilterScrollController,
|
|
|
|
|
_buildSearchField(),
|
|
|
|
|
if (appointmentsVM.branchesCategoriesFilterOptions.isNotEmpty) ...[
|
|
|
|
|
16.height,
|
|
|
|
|
FiltersList(
|
|
|
|
|
filterList: appointmentsVM.branchesCategoriesFilterOptions,
|
|
|
|
|
onFilterTapped: (index, selectedFilterId) => appointmentsVM.applyFilterOnBranches(index: index),
|
|
|
|
|
scrollController: appointmentsVM.branchesFilterScrollController,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
16.height,
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Builder(builder: (context) {
|
|
|
|
|
final filteredBranches = _filterBranches(appointmentsVM.nearbyBranches);
|
|
|
|
|
return RefreshIndicator(
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
context.read<AppointmentsVM>().getAllNearBranches(isNeedToRebuild: true, isFromRefresh: true);
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: appointmentsVM.state == ViewState.busy
|
|
|
|
|
? const BranchesListShimmer(itemCount: 5)
|
|
|
|
|
: filteredBranches.isEmpty
|
|
|
|
|
? Center(
|
|
|
|
|
child: LocaleKeys.no_branch.tr().toText(
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
color: MyColors.lightTextColor,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.separated(
|
|
|
|
|
itemCount: filteredBranches.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
BranchDetailModel branchDetailModel = filteredBranches[index];
|
|
|
|
|
return BranchDetailCard(
|
|
|
|
|
onCardTapped: () => navigateWithName(context, AppRoutes.branchDetailView, arguments: branchDetailModel),
|
|
|
|
|
providerImageUrl: branchDetailModel.branchProfileImage ?? "",
|
|
|
|
|
title: branchDetailModel.branchName ?? "",
|
|
|
|
|
providerLocation: branchDetailModel.distanceKm.toString() + " KM",
|
|
|
|
|
providerName: branchDetailModel.serviceProviderName ?? "",
|
|
|
|
|
providerRatings: branchDetailModel.branchRateAvg ?? 0.0,
|
|
|
|
|
services: branchDetailModel.branchServices,
|
|
|
|
|
).toViewOnly(context, onTap: () {
|
|
|
|
|
navigateWithName(context, AppRoutes.loginWithPassword, arguments: false);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (context, index) => 12.height,
|
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
|
),
|
|
|
|
|
).paddingOnly(left: 10, right: 10),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
16.height,
|
|
|
|
|
Expanded(
|
|
|
|
|
child: RefreshIndicator(
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
context.read<AppointmentsVM>().getAllNearBranches(isNeedToRebuild: true, isFromRefresh: true);
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: appointmentsVM.state == ViewState.busy
|
|
|
|
|
? const BranchesListShimmer(itemCount: 5)
|
|
|
|
|
: appointmentsVM.nearbyBranches.isEmpty
|
|
|
|
|
? Center(
|
|
|
|
|
child: LocaleKeys.no_branch.tr().toText(
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
color: MyColors.lightTextColor,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.separated(
|
|
|
|
|
itemCount: appointmentsVM.nearbyBranches.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
BranchDetailModel branchDetailModel = appointmentsVM.nearbyBranches[index];
|
|
|
|
|
return BranchDetailCard(
|
|
|
|
|
onCardTapped: () => navigateWithName(context, AppRoutes.branchDetailView, arguments: branchDetailModel),
|
|
|
|
|
providerImageUrl: branchDetailModel.branchProfileImage ?? "",
|
|
|
|
|
title: branchDetailModel.branchName ?? "",
|
|
|
|
|
providerLocation: branchDetailModel.distanceKm.toString() + " KM",
|
|
|
|
|
providerName: branchDetailModel.serviceProviderName ?? "",
|
|
|
|
|
providerRatings: branchDetailModel.branchRateAvg ?? 0.0,
|
|
|
|
|
services: branchDetailModel.branchServices,
|
|
|
|
|
).toViewOnly(context, onTap: () {
|
|
|
|
|
navigateWithName(context, AppRoutes.loginWithPassword, arguments: false);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (context, index) => 12.height,
|
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
|
),
|
|
|
|
|
).paddingOnly(left: 10, right: 10),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|