Branches Fix
parent
46839624c7
commit
96a96900ef
@ -0,0 +1,250 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:mc_common_app/classes/consts.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(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,230 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:car_provider_app/generated/locale_keys.g.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/view_models/branch_view_model.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/extensions/string_extensions.dart';
|
||||
import 'package:mc_common_app/models/general_models/m_response.dart';
|
||||
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
||||
import 'package:mc_common_app/theme/colors.dart';
|
||||
import 'package:mc_common_app/utils/enums.dart';
|
||||
import 'package:mc_common_app/utils/navigator.dart';
|
||||
import 'package:mc_common_app/utils/utils.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/txt_field.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class DefineBranchPage extends StatefulWidget {
|
||||
BranchDetailModel? branchData;
|
||||
|
||||
DefineBranchPage(this.branchData);
|
||||
|
||||
@override
|
||||
State<DefineBranchPage> createState() => _DefineBranchPageState();
|
||||
}
|
||||
|
||||
class _DefineBranchPageState extends State<DefineBranchPage> {
|
||||
late ServiceVM branchVM;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
scheduleMicrotask(() {
|
||||
branchVM = context.read<ServiceVM>();
|
||||
branchVM.getAllCountriesList(widget.branchData, EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// ServiceVM branchVM = context.read<ServiceVM>();
|
||||
// branchVM.getAllCountriesList(widget.branchData,
|
||||
// EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
||||
return Scaffold(
|
||||
appBar: CustomAppBar(
|
||||
title: LocaleKeys.defineBranches.tr(),
|
||||
),
|
||||
body: Consumer<ServiceVM>(builder: (context, model, _) {
|
||||
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,
|
||||
model.country != null
|
||||
? DropdownField(
|
||||
(DropValue value) {
|
||||
model.countryValue = DropValue(value.id, value.value, "");
|
||||
model.countryCode = value.subValue;
|
||||
model.countryId = value.id;
|
||||
model.getAllCities(widget.branchData, EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
||||
},
|
||||
isSelectAble: widget.branchData == null ? true : false,
|
||||
list: model.countryDropList,
|
||||
dropdownValue: model.countryValue,
|
||||
hint: "${LocaleKeys.chooseCountry.tr()}*",
|
||||
)
|
||||
: const CircularProgressIndicator(),
|
||||
12.height,
|
||||
if (model.countryId != -1)
|
||||
model.cities != null
|
||||
? model.citiesDropList.isEmpty
|
||||
? Text(LocaleKeys.no_city_available.tr())
|
||||
: DropdownField(
|
||||
(DropValue value) {
|
||||
model.cityValue = DropValue(value.id, value.value, "");
|
||||
model.setOnlyState(ViewState.busy);
|
||||
model.cityId = value.id;
|
||||
model.setState(ViewState.idle);
|
||||
},
|
||||
list: model.citiesDropList,
|
||||
dropdownValue: model.cityValue,
|
||||
hint: "${LocaleKeys.chooseCity.tr()}*",
|
||||
)
|
||||
: const CircularProgressIndicator(),
|
||||
12.height,
|
||||
if (model.cityId != -1)
|
||||
Column(
|
||||
children: [
|
||||
TxtField(
|
||||
hint: "${LocaleKeys.branchName.tr()}*",
|
||||
value: model.branchName,
|
||||
onChanged: (v) {
|
||||
model.branchName = v;
|
||||
},
|
||||
),
|
||||
12.height,
|
||||
TxtField(
|
||||
hint: "${LocaleKeys.branchDescription.tr()}*",
|
||||
value: model.branchDescription,
|
||||
onChanged: (v) {
|
||||
model.branchDescription = v;
|
||||
},
|
||||
),
|
||||
12.height,
|
||||
TxtField(
|
||||
hint: LocaleKeys.address.tr(),
|
||||
isNeedClickAll: false,
|
||||
maxLines: 5,
|
||||
value: model.address,
|
||||
onChanged: (v) {
|
||||
model.address = v;
|
||||
},
|
||||
),
|
||||
12.height,
|
||||
InkWell(
|
||||
onTap: () {
|
||||
navigateTo(
|
||||
context,
|
||||
PickLocationPage(
|
||||
onPickAddress: (double latitude, double longitude, String address) {
|
||||
model.latitude = latitude;
|
||||
model.longitude = longitude;
|
||||
model.address = address;
|
||||
model.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,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.place_outlined,
|
||||
size: 18,
|
||||
color: Colors.transparent,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
|
||||
child: ShowFillButton(
|
||||
title: widget.branchData != null ? (widget.branchData!.id == null ? LocaleKeys.createBranch.tr() : LocaleKeys.updateBranch.tr()) : LocaleKeys.createBranch.tr(),
|
||||
onPressed: () async {
|
||||
if (widget.branchData == null) {
|
||||
Utils.showLoading(context);
|
||||
MResponse res =
|
||||
await model.createBranch(model.branchName, model.branchDescription, model.cityId.toString(), model.address, model.latitude.toString(), model.longitude.toString());
|
||||
Utils.hideLoading(context);
|
||||
if (res.messageStatus == 1) {
|
||||
Utils.showToast(LocaleKeys.branch_created.tr());
|
||||
pop(context);
|
||||
model.getBranchAndServices();
|
||||
} else {
|
||||
Utils.showToast(res.message ?? "");
|
||||
}
|
||||
} else {
|
||||
Utils.showLoading(context);
|
||||
MResponse res = await model.updateBranch(
|
||||
widget.branchData!.id ?? 0, model.branchName, model.branchDescription, model.cityId.toString(), model.address, model.latitude.toString(), model.longitude.toString());
|
||||
Utils.hideLoading(context);
|
||||
if (res.messageStatus == 1) {
|
||||
Utils.showToast(LocaleKeys.branch_updated.tr());
|
||||
pop(context);
|
||||
pop(context);
|
||||
model.getBranchAndServices();
|
||||
} else {
|
||||
Utils.showToast(res.message ?? "");
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue