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.
162 lines
7.7 KiB
Dart
162 lines
7.7 KiB
Dart
import 'dart:async';
|
|
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
import 'package:mc_common_app/utils/date_helper.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/view_models/appointments_view_model.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/branch_details_card.dart';
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class ProviderProfileView extends StatefulWidget {
|
|
final int providerId;
|
|
|
|
ProviderProfileView({required this.providerId});
|
|
|
|
@override
|
|
State<ProviderProfileView> createState() => _ProviderProfileViewState();
|
|
}
|
|
|
|
class _ProviderProfileViewState extends State<ProviderProfileView> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
scheduleMicrotask(() async => context.read<AppointmentsVM>().getProviderProfileWithBranchesAndServices(widget.providerId));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer(
|
|
builder: (BuildContext context, AppointmentsVM appointmentsVM, Widget? child) {
|
|
if (appointmentsVM.state == ViewState.busy || appointmentsVM.providerProfileModel == null) {
|
|
return Scaffold(
|
|
backgroundColor: MyColors.white,
|
|
appBar: CustomAppBar(
|
|
title: LocaleKeys.providerDetails.tr(),
|
|
),
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: CustomAppBar(
|
|
title: LocaleKeys.providerDetails.tr(),
|
|
actions: [
|
|
Icon(
|
|
appointmentsVM.providerProfileModel!.isFavorite! ? Icons.favorite : Icons.favorite_border,
|
|
color: appointmentsVM.providerProfileModel!.isFavorite! ? MyColors.darkPrimaryColor : MyColors.black,
|
|
).horPaddingMain().onPress(
|
|
() async {
|
|
if (appointmentsVM.providerProfileModel!.isFavorite!) {
|
|
bool status = await appointmentsVM.removeProviderFromFavorite(serviceProviderID: appointmentsVM.providerProfileModel!.id!, context: context);
|
|
if (status) {
|
|
appointmentsVM.providerProfileModel!.isFavorite = false;
|
|
appointmentsVM.getMyFavoriteProviders();
|
|
setState(() {});
|
|
}
|
|
} else {
|
|
bool status = await appointmentsVM.addProviderToFavorite(serviceProviderID: appointmentsVM.providerProfileModel!.id!, context: context);
|
|
|
|
if (status) {
|
|
appointmentsVM.providerProfileModel!.isFavorite = true;
|
|
setState(() {});
|
|
}
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
padding: EdgeInsets.symmetric(horizontal: 21),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(child: appointmentsVM.providerProfileModel!.profileImage.buildNetworkImage(height: 250, width: double.infinity, fit: BoxFit.cover)),
|
|
12.height,
|
|
if (appointmentsVM.providerProfileModel!.memberSince!.isNotEmpty) ...[
|
|
Row(
|
|
children: [
|
|
("${LocaleKeys.companyName.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12),
|
|
4.width,
|
|
(appointmentsVM.providerProfileModel!.companyName ?? appointmentsVM.providerProfileModel!.name).toString().toText(
|
|
fontSize: 16,
|
|
isBold: true,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
if (appointmentsVM.providerProfileModel!.memberSince!.isNotEmpty) ...[
|
|
Row(
|
|
children: [
|
|
("${LocaleKeys.memberSince.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12),
|
|
4.width,
|
|
"${DateHelper.formatAsMonthYear(
|
|
DateHelper.parseStringToDate(
|
|
DateHelper.formatDateT(
|
|
appointmentsVM.providerProfileModel!.memberSince ?? "",
|
|
),
|
|
),
|
|
)}"
|
|
.toText(fontSize: 12, isBold: true),
|
|
],
|
|
),
|
|
],
|
|
4.height,
|
|
appointmentsVM.providerProfileModel!.companyDescription!.toText(color: MyColors.lightTextColor, fontSize: 12),
|
|
],
|
|
).toWhiteContainer(width: double.infinity, allPading: 12),
|
|
12.height,
|
|
appointmentsVM.providerProfileModel!.serviceProviderBranch == null
|
|
? Center(
|
|
child: (LocaleKeys.noBranchFound.tr()).toText(
|
|
fontSize: 16,
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
)
|
|
: appointmentsVM.providerProfileModel!.serviceProviderBranch!.isEmpty
|
|
? Center(child: Text(LocaleKeys.no_branch.tr()))
|
|
: ListView.separated(
|
|
itemBuilder: (context, index) {
|
|
BranchDetailModel branchModel = appointmentsVM.providerProfileModel!.serviceProviderBranch![index];
|
|
return BranchDetailCard(
|
|
onCardTapped: () {
|
|
navigateWithName(context, AppRoutes.branchDetailView, arguments: branchModel);
|
|
},
|
|
providerImageUrl: (branchModel.branchImages != null && branchModel.branchImages!.isNotEmpty) ? (branchModel.branchImages!.first.imageUrl ?? "") : "",
|
|
title: branchModel.branchName ?? "",
|
|
providerLocation: branchModel.distanceKm.toString() + " KM",
|
|
providerName: branchModel.serviceProviderName ?? "",
|
|
providerRatings: (branchModel.branchRateAvg ?? 0.0),
|
|
services: branchModel.branchServices,
|
|
);
|
|
},
|
|
separatorBuilder: (context, index) {
|
|
return 12.height;
|
|
},
|
|
itemCount: appointmentsVM.providerProfileModel!.serviceProviderBranch!.length,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|