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.
106 lines
4.6 KiB
Dart
106 lines
4.6 KiB
Dart
import 'package:mc_common_app/classes/app_state.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/models/general_models/widgets_models.dart';
|
|
import 'package:mc_common_app/view_models/ad_view_model.dart';
|
|
import 'package:mc_common_app/view_models/user_view_model.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
import 'package:mc_common_app/widgets/txt_field.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class UpdateUserCityCountry extends StatefulWidget {
|
|
const UpdateUserCityCountry({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<UpdateUserCityCountry> createState() => _UpdateUserCityCountryState();
|
|
}
|
|
|
|
class _UpdateUserCityCountryState extends State<UpdateUserCityCountry> {
|
|
DropValue? city;
|
|
DropValue? country;
|
|
|
|
@override
|
|
void initState() {
|
|
context.read<UserVM>().getAllCountriesForUser();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer(builder: (BuildContext context, UserVM uVM, Widget? child) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(
|
|
title: "Update City",
|
|
),
|
|
body: Column(
|
|
children: [
|
|
uVM.userCountries != null
|
|
? Container(
|
|
padding: const EdgeInsets.only(right: 20, left: 20, top: 12),
|
|
child: Builder(builder: (context) {
|
|
List<DropValue> userCountryDrop = [];
|
|
for (var element in uVM.userCountries!.data!) {
|
|
if (AppState().getUser.data!.userInfo!.countryId == element.id) {
|
|
country = DropValue(element.id?.toInt() ?? 0, element.countryName ?? "", "");
|
|
}
|
|
userCountryDrop.add(DropValue(element.id?.toInt() ?? 0, element.countryName ?? "", ""));
|
|
}
|
|
return DropdownField(
|
|
(DropValue value) async {
|
|
country = value;
|
|
await uVM.getAllCitiesForUser(country!.id);
|
|
setState(() {});
|
|
},
|
|
list: userCountryDrop,
|
|
dropdownValue: country != null && country != -1 ? DropValue(country!.id, country!.value, "") : null,
|
|
hint: country != null && country != -1 ? country!.value : "Country",
|
|
// errorValue: adVM.vehicleCountryId.errorValue,
|
|
);
|
|
}))
|
|
: SizedBox(),
|
|
uVM.userCities != null
|
|
? Container(
|
|
padding: const EdgeInsets.only(right: 20, left: 20, top: 12),
|
|
child: Builder(builder: (context) {
|
|
List<DropValue> userCityDrop = [];
|
|
for (var element in uVM.userCities!.data!) {
|
|
if (AppState().getUser.data!.userInfo!.cityId == element.id) {
|
|
city = DropValue(element.id?.toInt() ?? 0, element.cityName ?? "", "");
|
|
}
|
|
userCityDrop.add(DropValue(element.id?.toInt() ?? 0, element.cityName ?? "", ""));
|
|
}
|
|
return DropdownField(
|
|
(DropValue value) {
|
|
city = value;
|
|
setState(() {});
|
|
},
|
|
list: userCityDrop,
|
|
dropdownValue: city != null && city != -1 ? DropValue(city!.id, city!.value, "") : null,
|
|
hint: city != null && city != -1 ? city!.value : "City",
|
|
// errorValue: adVM.vehicleCountryId.errorValue,
|
|
);
|
|
}))
|
|
: SizedBox(),
|
|
20.height,
|
|
Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: ShowFillButton(
|
|
title: LocaleKeys.confirm.tr(),
|
|
maxWidth: double.infinity,
|
|
onPressed: () async {
|
|
await uVM.userDetailsUpdate(context, AppState().getUser.data!.userInfo!.firstName!, AppState().getUser.data!.userInfo!.lastName!, city != null ? city?.id.toString() : null);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|