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.
252 lines
12 KiB
Dart
252 lines
12 KiB
Dart
import 'dart:async';
|
|
|
|
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/view_models/service_view_model.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:car_provider_app/views/location/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 CreateBranchView extends StatefulWidget {
|
|
final BranchDetailModel? branchData;
|
|
|
|
const CreateBranchView(this.branchData, {super.key});
|
|
|
|
@override
|
|
State<CreateBranchView> createState() => _CreateBranchViewState();
|
|
}
|
|
|
|
class _CreateBranchViewState extends State<CreateBranchView> {
|
|
late ServiceVM branchVM;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
scheduleMicrotask(() {
|
|
branchVM = context.read<ServiceVM>();
|
|
branchVM.getAllCountriesList(widget.branchData, EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(
|
|
title: LocaleKeys.createBranch.tr(),
|
|
),
|
|
body: Consumer<ServiceVM>(builder: (context, serviceVM, _) {
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Column(
|
|
children: [
|
|
// LocaleKeys.chooseCountry.tr().toText(fontSize: 14, color: MyColors.lightTextColor),
|
|
// 8.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 ? true : false,
|
|
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(
|
|
hint: "${LocaleKeys.branchDescription.tr()}*",
|
|
value: serviceVM.branchDescription,
|
|
onChanged: (v) {
|
|
serviceVM.branchDescription = v;
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: LocaleKeys.address.tr(),
|
|
isNeedClickAll: false,
|
|
maxLines: 3,
|
|
value: serviceVM.address,
|
|
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();
|
|
},
|
|
),
|
|
],
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (widget.branchData == null || widget.branchData!.id == null) ...[
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
|
|
child: ShowFillButton(
|
|
maxHeight: 55,
|
|
title: LocaleKeys.createBranch.tr(),
|
|
onPressed: () async {
|
|
await serviceVM.onCreateBranchPressed(
|
|
context: context,
|
|
branchName: serviceVM.branchName,
|
|
branchDesc: serviceVM.branchDescription,
|
|
cityID: serviceVM.cityId,
|
|
address: serviceVM.address,
|
|
latitude: serviceVM.latitude,
|
|
longitude: serviceVM.longitude,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
] else ...[
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
|
|
child: ShowFillButton(
|
|
maxHeight: 55,
|
|
title: widget.branchData != null ? (widget.branchData!.id == null ? LocaleKeys.createBranch.tr() : LocaleKeys.updateBranch.tr()) : LocaleKeys.createBranch.tr(),
|
|
onPressed: () async {
|
|
await serviceVM.updateBranch(
|
|
widget.branchData!.id ?? 0,
|
|
serviceVM.branchName,
|
|
serviceVM.branchDescription,
|
|
serviceVM.cityId.toString(),
|
|
serviceVM.address,
|
|
serviceVM.latitude.toString(),
|
|
serviceVM.longitude.toString(),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
}
|