A

A
mail@pastecode.io avatar
unknown
dart
a year ago
18 kB
4
Indexable
Never
import 'package:ceramic_quotation/app/common/tabel_screen.dart';
import 'package:ceramic_quotation/app/common/text_filed.dart';
import 'package:ceramic_quotation/app/constant/app_color.dart';
import 'package:ceramic_quotation/app/constant/app_string.dart';
import 'package:ceramic_quotation/app/model/account_model/account_model.dart';
import 'package:ceramic_quotation/app/model/account_model/account_request_update_model.dart';
import 'package:ceramic_quotation/app/modules/login/views/login_view.dart';
import 'package:ceramic_quotation/app/modules/member_add/controller/member_add_controller.dart';
import 'package:ceramic_quotation/app/utils/app_prefrence.dart';
import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../common/custom_buttion.dart';

import '../../../routes/app_pages.dart';

import '../controller/account_controller.dart';

class AccountView extends GetView<AccountController> {
  AccountView({super.key});

  // AccountController abc = Get.put(AccountController());
  @override
  Widget build(BuildContext context) {
    // WidgetsBinding.instance.addPostFrameCallback((_) {
    //   abc.geAccountData();
    // });
    MemberController memberController = Get.put(MemberController());
    return GetBuilder<AccountController>(
      init: AccountController(),
      builder: (accountController) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.only(
                top: 20,
                left: 20,
                bottom: 20,
                right: 10,
              ),
              child: Row(
                children: [
                  LoginTextField(
                    onChanged: (val) {
                      accountController.runFilter(val);
                    },
                    isdense: true,
                    height: 15,
                    prefixIcon: const Icon(
                      Icons.search_rounded,
                      color: Colors.grey,
                      size: 18,
                    ),
                    hintText: AppString.findName,
                    hintStyle: Get.theme.primaryTextTheme.titleLarge,
                    fieldStyle: Get.theme.primaryTextTheme.headlineMedium,
                  ),
                  Padding(
                    padding: const EdgeInsets.all(20),
                    child: CustomButton(
                      title: AppString.add,
                      onTap: () {
                        memberController.getUpdateMember();
                        Get.toNamed(Routes.member);
                      },
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(20),
                    child: CustomButton(
                      title: AppString.upDate,
                      onTap: () {
                        AppPreference.clear();
                        AppPreference.remove("admin");
                        Get.toNamed(Routes.login);
                        print("String Is${AppPreference.getString('admin')}");

                        accountController.update();
                      },
                    ),
                  ),
                ],
              ),
            ),
            accountController.accountModel == null
                ? Center(
                    child: CircularProgressIndicator(
                      color: AppColors.blue,
                    ),
                  )
                : Expanded(
                    child: Padding(
                      padding: const EdgeInsets.only(left: 20, right: 10),
                      child: TableScreen(
                        sortAscending: accountController.sortAscending,
                        sortColumnIndex: accountController.sortColumnIndex,
                        sortingName: (index, ascending) {
                          accountController.sorting(
                            (d) => d.name!,
                            index,
                            ascending,
                          );
                        },
                        dropDownValueAlias: true,
                        dropDownValueGroup: true,
                        dropDownValueParty: true,
                        dropDownValueAliasText: false,
                        dropDownValuePartyText: false,
                        dataColumnOne: AppString.no,
                        dataColumnTwo: AppString.name,
                        dataColumnThree: AppString.alias,
                        dataColumnFour: AppString.party,
                        dataColumnFive: AppString.address,
                        dataColumnSix: AppString.city,
                        dataColumnSeven: AppString.pinCode,
                        dataColumnEight: AppString.state,
                        dataColumnNine: AppString.mobileNo,
                        dataColumnTen: AppString.email,
                        dataColumnEleOne: AppString.active,
                        dataCondation: true,
                        dataColumnSizeTwo: ColumnSize.M,
                        dataColumnSizeSix: ColumnSize.S,
                        dataColumnSizeOne: ColumnSize.S,
                        dataColumnSizeSeven: ColumnSize.S,
                        dataColumnSizeEight: ColumnSize.S,
                        dataColumnSizeThree: ColumnSize.M,
                        dataColumnSizeFour: ColumnSize.M,
                        dataColumnSizeEleOne: ColumnSize.S,
                        rows: List.generate(
                          accountController.accountData!.length,
                          (index) {
                            accountController
                                    .accountData![index].idController.text =
                                accountController.accountData![index].id!;
                            accountController
                                    .accountData![index].nameController.text =
                                accountController.accountData![index].name!;
                            accountController
                                    .accountData![index].aliasController.text =
                                accountController.accountData![index].alias!;
                            accountController.accountData![index]
                                    .addressController.text =
                                accountController.accountData![index].address!;
                            accountController
                                    .accountData![index].emailController.text =
                                accountController.accountData![index].email!;
                            accountController
                                    .accountData![index].stateController.text =
                                accountController.accountData![index].state!;
                            accountController.accountData![index]
                                    .pincodeController.text =
                                accountController.accountData![index].pin!;
                            accountController
                                    .accountData![index].cityController.text =
                                accountController.accountData![index].city!;
                            accountController.accountData![index]
                                    .districtController.text =
                                accountController.accountData![index].district!;
                            accountController.accountData![index]
                                    .accountTypeController.text =
                                accountController
                                    .accountData![index].accounttype!;
                            accountController
                                    .accountData![index].numberController.text =
                                accountController.accountData![index].mobile!;

                            cursoPosition(
                              accountController.accountData![index],
                            );

                            return DataRow(
                              cells: [
                                DataCell(TextField(
                                  readOnly: true,
                                  focusNode:
                                      accountController.accountData![index].f1,
                                  controller: accountController
                                      .accountData![index].idController,
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].nameController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].aliasController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].addressController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].cityController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].pincodeController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].stateController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].numberController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index].emailController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(TextField(
                                  controller: accountController
                                      .accountData![index]
                                      .accountTypeController,
                                  onTap: () {
                                    FocusScope.of(context).requestFocus(onclick(
                                      context,
                                      accountController.accountData![index],
                                    ));
                                  },
                                  style: Get.theme.textTheme.displayLarge,
                                )),
                                DataCell(
                                  TextField(
                                    controller: accountController
                                        .accountData![index].districtController,
                                    onTap: () {
                                      FocusScope.of(context)
                                          .requestFocus(onclick(
                                        context,
                                        accountController.accountData![index],
                                      ));
                                    },
                                    style: Get.theme.textTheme.displayLarge,
                                  ),
                                ),
                              ],
                            );
                          },
                        ),
                      ),
                    ),
                  ),
          ],
        );
      },
    );
  }

  onclick(context, AccountData accountData) {
    AccountController accountController = Get.put(AccountController());
    AccountUpdateRequestModel accountUpdateRequestModel =
        AccountUpdateRequestModel(
      id: accountData.idController.text,
      name: accountData.nameController.text,
      alias: accountData.aliasController.text,
      accounttype: accountData.accountTypeController.text,
      address: accountData.addressController.text,
      city: accountData.cityController.text,
      district: accountData.districtController.text,
      mobile: accountData.numberController.text,
      email: accountData.emailController.text,
      pin: accountData.pincodeController.text,
      state: accountData.stateController.text,
    );

    accountController.accountUpdate(
      accountUpdateRequestModel,
      context,
    );
  }

  cursoPosition(AccountData accountData) {
    accountData.nameController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.nameController.text.length),
    );
    accountData.aliasController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.aliasController.text.length),
    );
    accountData.accountTypeController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.accountTypeController.text.length),
    );
    accountData.addressController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.addressController.text.length),
    );
    accountData.cityController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.cityController.text.length),
    );
    accountData.stateController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.stateController.text.length),
    );
    accountData.numberController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.numberController.text.length),
    );
    accountData.pincodeController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.pincodeController.text.length),
    );
    accountData.districtController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.districtController.text.length),
    );
    accountData.emailController.selection = TextSelection.fromPosition(
      TextPosition(offset: accountData.emailController.text.length),
    );
  }
}