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.
309 lines
15 KiB
Dart
309 lines
15 KiB
Dart
import 'dart:async';
|
|
import 'package:car_provider_app/view_models/dashboard_view_model.dart';
|
|
import 'package:mc_common_app/classes/consts.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/utils/utils.dart';
|
|
import 'package:mc_common_app/view_models/service_view_model.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/views/location_views/pick_location_page.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/views/advertisement/ad_creation_steps/ad_creation_steps_containers.dart';
|
|
import 'package:mc_common_app/views/advertisement/components/picked_images_container_widget.dart';
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.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/txt_field.dart';
|
|
|
|
class DefineBranchView extends StatefulWidget {
|
|
final BranchDetailModel? branchData;
|
|
|
|
const DefineBranchView(this.branchData, {super.key});
|
|
|
|
@override
|
|
State<DefineBranchView> createState() => _DefineBranchViewState();
|
|
}
|
|
|
|
class _DefineBranchViewState extends State<DefineBranchView> {
|
|
late ServiceVM serviceVM;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
scheduleMicrotask(() {
|
|
serviceVM = context.read<ServiceVM>();
|
|
serviceVM.getAllCountriesList(widget.branchData, EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(title: LocaleKeys.defineBranches.tr()),
|
|
body: Consumer<ServiceVM>(builder: (context, serviceVM, _) {
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
12.height,
|
|
serviceVM.country != null
|
|
? DropdownField(
|
|
(DropValue value) {
|
|
serviceVM.countryValue = DropValue(value.id, value.value, "");
|
|
serviceVM.countryCode = value.subValue;
|
|
serviceVM.countryId = value.id;
|
|
serviceVM.getAllCities(widget.branchData, EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
|
},
|
|
isSelectAble: widget.branchData == null,
|
|
list: serviceVM.countryDropList,
|
|
dropdownValue: serviceVM.countryValue,
|
|
hint: "${LocaleKeys.chooseCountry.tr()}*",
|
|
)
|
|
: const CircularProgressIndicator(),
|
|
12.height,
|
|
if (serviceVM.countryId != -1)
|
|
serviceVM.cities != null
|
|
? serviceVM.citiesDropList.isEmpty
|
|
? Text(LocaleKeys.no_city_available.tr())
|
|
: DropdownField(
|
|
(DropValue value) {
|
|
serviceVM.cityValue = DropValue(value.id, value.value, "");
|
|
serviceVM.setOnlyState(ViewState.busy);
|
|
serviceVM.cityId = value.id;
|
|
serviceVM.setState(ViewState.idle);
|
|
},
|
|
list: serviceVM.citiesDropList,
|
|
dropdownValue: serviceVM.cityValue,
|
|
hint: "${LocaleKeys.chooseCity.tr()}*",
|
|
)
|
|
: const CircularProgressIndicator(),
|
|
12.height,
|
|
if (serviceVM.cityId != -1)
|
|
Column(
|
|
children: [
|
|
TxtField(
|
|
hint: "${LocaleKeys.branchName.tr()}*",
|
|
value: serviceVM.branchName,
|
|
onChanged: (v) {
|
|
serviceVM.branchName = v;
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
maxLines: 3,
|
|
hint: "${LocaleKeys.branchDescription.tr()}*",
|
|
value: serviceVM.branchDescription,
|
|
onChanged: (v) {
|
|
serviceVM.branchDescription = v;
|
|
},
|
|
),
|
|
12.height,
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: TxtField(
|
|
errorValue: '',
|
|
hint: 'Opening Time*',
|
|
value: serviceVM.openTime,
|
|
isNeedClickAll: true,
|
|
postfixData: Icons.access_time,
|
|
postFixDataColor: MyColors.lightTextColor,
|
|
onTap: () async {
|
|
TimeOfDay startTime = TimeOfDay.now();
|
|
String endTime = await Utils.pickTime(context, initialTime: startTime);
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
serviceVM.updateSelectionOpenTime(endTime);
|
|
},
|
|
),
|
|
),
|
|
12.width,
|
|
Expanded(
|
|
child: TxtField(
|
|
errorValue: '',
|
|
hint: 'Closing Time*',
|
|
value: serviceVM.closedTime,
|
|
isNeedClickAll: true,
|
|
postfixData: Icons.access_time,
|
|
postFixDataColor: MyColors.lightTextColor,
|
|
onTap: () async {
|
|
TimeOfDay startTime = TimeOfDay.now();
|
|
String endTime = await Utils.pickTime(context, initialTime: startTime);
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
serviceVM.updateSelectionCloseTime(endTime);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: LocaleKeys.address.tr(),
|
|
isNeedClickAll: false,
|
|
value: serviceVM.address,
|
|
postfixWidget: IconButton(
|
|
icon: const Icon(
|
|
size: 28,
|
|
Icons.add_location_outlined,
|
|
),
|
|
onPressed: () {
|
|
navigateTo(
|
|
context,
|
|
PickLocationPage(
|
|
onPickAddress: (double latitude, double longitude, String address) {
|
|
serviceVM.latitude = latitude;
|
|
serviceVM.longitude = longitude;
|
|
serviceVM.address = address;
|
|
serviceVM.setState(ViewState.idle);
|
|
},
|
|
),
|
|
);
|
|
}),
|
|
onChanged: (v) {
|
|
serviceVM.address = v;
|
|
},
|
|
),
|
|
12.height,
|
|
// InkWell(
|
|
// onTap: () {
|
|
// navigateTo(
|
|
// context,
|
|
// PickLocationPage(
|
|
// onPickAddress: (double latitude, double longitude, String address) {
|
|
// serviceVM.latitude = latitude;
|
|
// serviceVM.longitude = longitude;
|
|
// serviceVM.address = address;
|
|
// serviceVM.setState(ViewState.idle);
|
|
// },
|
|
// ),
|
|
// );
|
|
// },
|
|
// child: Container(
|
|
// width: double.infinity,
|
|
// height: 45,
|
|
// decoration: BoxDecoration(
|
|
// color: Colors.transparent,
|
|
// border: Border.all(color: MyColors.darkPrimaryColor, width: 2),
|
|
// borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
// ),
|
|
// child: Row(
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
// crossAxisAlignment: CrossAxisAlignment.center,
|
|
// children: [
|
|
// const Icon(
|
|
// Icons.place_outlined,
|
|
// size: 18,
|
|
// color: MyColors.darkPrimaryColor,
|
|
// ),
|
|
// 8.width,
|
|
// Text(
|
|
// LocaleKeys.pickAddress.tr(),
|
|
// style: const TextStyle(
|
|
// color: MyColors.darkPrimaryColor,
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// 12.height,
|
|
DottedRectContainer(
|
|
onTap: () => serviceVM.pickMultipleImages(),
|
|
text: LocaleKeys.attachImage.tr(),
|
|
icon: MyAssets.attachmentIcon.buildSvg(),
|
|
),
|
|
if (serviceVM.branchImageError != "") ...[
|
|
10.height,
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
serviceVM.branchImageError.toText(fontSize: 14, color: Colors.red),
|
|
],
|
|
).paddingOnly(right: 10)
|
|
],
|
|
if (serviceVM.pickedBranchImages.isNotEmpty) ...[
|
|
16.height,
|
|
PickedFilesContainer(
|
|
pickedFiles: serviceVM.pickedBranchImages,
|
|
onCrossPressedPrimary: serviceVM.removeImageFromList,
|
|
onAddFilePressed: () {
|
|
serviceVM.pickMultipleImages();
|
|
},
|
|
),
|
|
],
|
|
],
|
|
),
|
|
],
|
|
).horPaddingMain(),
|
|
),
|
|
),
|
|
if (serviceVM.branchErrorScreen.isNotEmpty) ...[
|
|
serviceVM.branchErrorScreen.toText(fontSize: 14, color: Colors.red).paddingAll(21),
|
|
],
|
|
if (widget.branchData == null || widget.branchData!.id == null) ...[
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 10),
|
|
child: ShowFillButton(
|
|
maxHeight: 55,
|
|
title: LocaleKeys.createBranch.tr(),
|
|
onPressed: () async {
|
|
await serviceVM.onCreateBranchPressed(
|
|
context: context,
|
|
branchName: serviceVM.branchName,
|
|
branchDesc: serviceVM.branchDescription,
|
|
openTime: serviceVM.openTime,
|
|
closeTime: serviceVM.closedTime,
|
|
cityID: serviceVM.cityId,
|
|
address: serviceVM.address,
|
|
latitude: serviceVM.latitude,
|
|
longitude: serviceVM.longitude,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
] else ...[
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ShowFillButton(
|
|
maxHeight: 55,
|
|
title: LocaleKeys.updateBranch.tr(),
|
|
onPressed: () async {
|
|
await serviceVM.onUpdateBranchPressed(
|
|
context: context,
|
|
branchID: widget.branchData!.id ?? 0,
|
|
branchName: widget.branchData!.branchName ?? "",
|
|
branchDesc: widget.branchData!.branchDescription ?? "",
|
|
openTime: widget.branchData!.openTime ?? "",
|
|
closedTime: widget.branchData!.closeTime ?? "",
|
|
cityID: widget.branchData!.cityId ?? 0,
|
|
address: widget.branchData!.address ?? "",
|
|
latitude: widget.branchData!.latitude ?? "0",
|
|
longitude: widget.branchData!.longitude ?? "0",
|
|
);
|
|
},
|
|
).horPaddingMain(),
|
|
),
|
|
12.height,
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
}
|