AddressBookSetView

mail@pastecode.io avatar
unknown
dart
2 years ago
8.0 kB
1
Indexable
Never
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mobile/app/global_widgets/circular_block_button_widget.dart';
import 'package:mobile/app/models/responses/get_all_cities.dart';
import 'package:mobile/app/modules/address_book/controllers/add_book_map_controller.dart';
import 'package:mobile/app/modules/address_book/controllers/address_book_controller.dart';
import 'package:mobile/app/modules/address_book/widgets/address_book_bar.dart';
import 'package:mobile/app/modules/address_book/widgets/address_book_text_feild.dart';
import 'package:mobile/app/modules/address_book/widgets/address_book_tile.dart';
import 'package:mobile/app/services/auth_service.dart';
import 'package:mobile/common/ui.dart';

class AddressBookSetView extends GetView<AddressBookController> {
  final _currentUser = Get.find<AuthService>().appUser;
  AddressBookMapController addressBookMapController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: true,
        child: ListView(
          primary: true,
          children: [
            AddressBookBar(title: 'Address Book'.tr),
            Obx(() => AddressBookTile(
                  title: controller.nicknameStr.value,
                  subTitle: controller.nickName.value.text,
                  iconColor: Colors.green,
                  showMenu: false,
                )),
            Row(
              children: [
                Expanded(
                  flex: 1,
                  child: DropdownButtonFormField(
                items: controller.citiesList.map((e) {
                  return new DropdownMenuItem<CityItems>(
                      value: e,
                      child: Row(
                        children: <Widget>[
                          Text(
                            Get.locale.toString() == 'ar' ? e.nameAr : e.nameEn,
                            style: Get.theme.textTheme.bodyText2,
                          ),
                        ],
                      ));
                }).toList(),
                onChanged: (CityItems newValue) {
                  controller.cityController.text =
                      Get.locale.toString() == 'ar'
                          ? newValue.nameAr
                          : newValue.nameEn;
                  print(controller.cityController.text);
                  controller.onCityChange(newValue);
                },
                value: controller.selectedCity,
                decoration: InputDecoration(
                  border: OutlineInputBorder(
                    borderRadius: const BorderRadius.all(
                      const Radius.circular(10.0),
                    ),
                  ),
                  hintText: "Select City".tr,
                  hintStyle: TextStyle(
                    color: Colors.black,
                  ),
                  enabledBorder: InputBorder.none,
                ),
              )
                .paddingSymmetric(vertical: 20, horizontal: 10),
                ),
                Expanded(
                  flex: 1,
                  child: AddressBookTextFormFeild(
                    addController: controller.building.value,
                    hintText: 'Building/Villa'.tr,
                  ).paddingSymmetric(vertical: 20, horizontal: 10),
                ),
              ],
            ).paddingSymmetric(horizontal: 20),
            Row(
              children: [
                Expanded(
                  flex: 1,
                  child: AddressBookTextFormFeild(
                    addController: controller.street.value,
                    hintText: 'Street'.tr,
                  ).paddingSymmetric(vertical: 10, horizontal: 10),
                ),
                Expanded(
                  flex: 1,
                  child: AddressBookTextFormFeild(
                    addController: controller.area.value,
                    hintText: 'Area'.tr,
                  ).paddingSymmetric(vertical: 10, horizontal: 10),
                ),
              ],
            ).paddingSymmetric(horizontal: 20),
            AddressBookTextFormFeild(
              addController: controller.direction.value,
              hintText: 'Directions'.tr,
            ).paddingSymmetric(vertical: 10, horizontal: 30),
            Obx(
              () => Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  addressLocationIcon(
                      val: 0, iconData: Icons.home_filled, label: 'Home.'.tr),
                  SizedBox(width: 30),
                  addressLocationIcon(
                      val: 1, iconData: Icons.work, label: 'Work'.tr),
                  SizedBox(width: 30),
                  addressLocationIcon(
                      val: 2, iconData: Icons.location_on, label: 'Others'.tr),
                ],
              ).paddingOnly(bottom: 10, top: 20),
            ),
            Obx(() => controller.addressBookType.value == 2
                ? AddressBookTextFormFeild(
                    onChanged: (val) {
                      controller.nicknameStr.value = val;
                    },
                    addController: controller.nickName.value,
                    hintText: 'NickName'.tr,
                  ).paddingSymmetric(vertical: 10, horizontal: 30)
                : Container()),
            CircularBlockButtonWidget(
                color: Get.theme.focusColor,
                text: Text(
                  'Save Address'.tr,
                  style: Get.textTheme.headline3.copyWith(fontSize: 16),
                ),
                onPressed: () async {
                  if (controller.city.value.text.trim() != '' &&
                      controller.building.value.text.trim() != '' &&
                      controller.street.value.text.trim() != '' &&
                      controller.area.value.text.trim() != '' &&
                      controller.nickName.value.text.trim() != '') {
                    await controller
                        .addOrEditAddressBookItem()
                        .then((value) async {
                      await controller.refeshListAddressBook();
                      Get.back();
                    });
                  } else {
                    Get.showSnackbar(Ui.ErrorSnackBar(
                      title: 'Error'.tr,
                      message: 'please complete your information'.tr,
                    ));
                  }
                }).paddingSymmetric(vertical: 20, horizontal: 30),
          ],
        ),
      ),
    );
  }

  Widget addressLocationIcon({int val, IconData iconData, String label}) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        InkWell(
          onTap: () {
            controller.addressBookType.value = val;

            controller.addressBookType.value == 0
                ? controller.nicknameStr.value = 'Home.'.tr
                : controller.addressBookType.value == 1
                    ? controller.nicknameStr.value = 'Work'.tr
                    : controller.nicknameStr.value = '';

            controller.addressBookType.value == 0
                ? controller.nickName.value.text = 'Home.'.tr
                : controller.addressBookType.value == 1
                    ? controller.nickName.value.text = 'Work'.tr
                    : controller.nickName.value.text =
                        controller.nicknameStr.value;

            // print(_val.toString());
          },
          child: CircleAvatar(
            backgroundColor: controller.addressBookType.value == val
                ? Colors.green
                : Colors.grey[500],
            minRadius: 30,
            child: Icon(
              iconData,
              color: Colors.white,
              size: 30,
            ),
          ),
        ),
        Text(label)
      ],
    );
  }
}