Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
9.1 kB
1
Indexable
Never
import 'dart:io';

import 'package:bjbs/app/controllers/utility_controller.dart';
import 'package:bjbs/app/modules/login/components/button_forgot_password.dart';
import 'package:bjbs/app/modules/login/components/button_login_biometrics.dart';
import 'package:bjbs/app/modules/login/controllers/login_controller.dart';
import 'package:bjbs/app/routes/app_pages.dart';
import 'package:bjbs/styles/colors.dart';
import 'package:bjbs/styles/style.dart';
import 'package:bjbs/utils/app_asset.dart';
import 'package:bjbs/widgets/buttons/button_primary.dart';
import 'package:bjbs/widgets/buttons/button_rich_text.dart';
import 'package:bjbs/widgets/inputs/input_password.dart';
import 'package:bjbs/widgets/inputs/input_primary.dart';
import 'package:bjbs/widgets/others/show_dialog.dart';
import 'package:bjbs/widgets/pages/page_bg_grey.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';

class LoginView extends GetView<LoginController> {
  const LoginView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return PageBgGrey(
      bottomBarHeight: (Platform.isAndroid) ? 90.h : 113.h,
      bottomBar: Stack(
        children: [
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ButtonRichText(
                // onPress: controller.gotoRegister,
                onPress: () => Get.toNamed(Routes.REGISTER),
                description: '${'dont_have_an_account_yet'.tr}?',
                label: 'registration'.tr,
              ),
              // Text('|', style: TextStyles.small1.copyWith(color: Colors.white)),
              // horizontalSpace(8),
              ButtonRichText(
                // onPress: controller.gotoRegister,
                onPress: () => Get.toNamed(Routes.ONBOARDING),
                description: '${'or'.tr} ',
                label: 'open_account'.tr,
              ),
              // InkWell(
              //   onTap: () => Get.toNamed(Routes.ONBOARDING),
              //   child: Text(
              //     'open_account'.tr,
              //     style: TextStyles.small1.copyWith(
              //       fontWeight: FontWeight.bold,
              //       color: AppColor.primaryColor,
              //       decoration: TextDecoration.none,
              //     ),
              //   ),
              // ),
              // InkWell(
              //   onTap: () => Get.toNamed(Routes.ONBOARDING),
              //   child: Text(
              //     'open_account'.tr,
              //     style: TextStyles.small1.copyWith(
              //       fontWeight: FontWeight.bold,
              //       color: AppColor.primaryColor,
              //       decoration: TextDecoration.none,
              //     ),
              //   ),
              // ),
              Center(
                child: Text(
                  '©Mobile Maslahah ${DateTime.now().year} ${Get.find<UtilityController>().appVersion}',
                  style: TextStyles.caption.copyWith(
                    color: Colors.grey[500],
                  ),
                ),
              )
            ],
          ),
          // Row(
          //   mainAxisAlignment: MainAxisAlignment.center,
          //   children: [
          //     Center(
          //       child: Text(
          //         '©Mobile Maslahah ${DateTime.now().year} ${Get.find<UtilityController>().appVersion}',
          //         style: TextStyles.caption.copyWith(
          //           color: Colors.grey[500],
          //         ),
          //       ),
          //     )
          //   ],
          // ),
          Align(
            alignment: Alignment.bottomRight,
            child: Padding(
              padding: EdgeInsets.only(bottom: 10.h),
              child: InkWell(
                onTap: () async {
                  await controller.showPopUpCCandCCM();
                },
                child: SizedBox.square(
                  dimension: 75.w,
                  child: Image.asset(AppAsset.icon('ic_chat.png')),
                ),
              ),
            ),
          ),
        ],
      ),
      child: Align(
        alignment: Alignment.bottomCenter,
        child: Obx(
          () => SingleChildScrollView(
            child: Padding(
              padding: EdgeInsets.all(Insets.xxl),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Image.asset(
                    AppAsset.logo('bjbs_new.png'),
                    width: Get.width * 0.5,
                    height: Get.width * 0.5,
                  ),
                  Row(
                    children: [
                      SvgPicture.asset(
                        AppAsset.icon('ic_user.svg'),
                        width: 24.w,
                        height: 24.w,
                      ),
                      horizontalSpace(4),
                      Expanded(
                        child: InputPrimary(
                          controller: controller.tUsername,
                          onChanged: controller.setUsername,
                          inputFormatters: [
                            FilteringTextInputFormatter.deny(' ')
                          ],
                          color: AppColor.greyLight.withOpacity(.5),
                          outlineColor: Colors.transparent,
                          textColor: Colors.white,
                          hintColor: Colors.white60,
                          borderRadius: 4,
                          hint: 'user_id'.tr,
                        ),
                      ),
                    ],
                  ),
                  Row(
                    children: [
                      SvgPicture.asset(
                        AppAsset.icon('ic_password.svg'),
                        width: 24.w,
                        height: 24.w,
                      ),
                      horizontalSpace(4),
                      Expanded(
                        child: InputPassword(
                          controller: controller.tPassword,
                          value: controller.setPassword,
                          validation: (v) {
                            return v.isNotEmpty;
                          },
                          validationText: '',
                          color: AppColor.greyLight.withOpacity(.5),
                          outlineColor: Colors.transparent,
                          textColor: Colors.white,
                          hintColor: Colors.white60,
                          borderRadius: 4,
                          iconColor: Colors.white,
                          hint: 'password'.tr,
                        ),
                      ),
                    ],
                  ),
                  const ButtonForgotPassword(),
                  ButtonPrimary(
                    width: Get.width * 0.7,
                    isOutline: true,
                    radius: 24,
                    isLoading: controller.isLoading.value,
                    enabled: controller.isValid.value,
                    onTap: () async {
                      final locationStatus = await Permission.location.status;
                      if (locationStatus.isGranted) {
                        await controller.login();
                      } else {
                        if (controller.userBiometric.value.isEmpty) {
                          showPopUpInfo(
                            title: 'information'.tr,
                            description:
                                'Untuk dapat melanjutkan login, Kami membutuhkan lokasi anda'
                                    .tr,
                            labelButton: 'continyu'.tr,
                            onPress: () async {
                              Get.back();
                              await controller.login();
                            },
                          );
                        }
                      }
                    },
                    label: 'LOGIN',
                    outlineColor: controller.isValid.value
                        ? Colors.transparent
                        : Colors.white,
                  ),
                  if (controller.isBiometrics.value)
                    Padding(
                      padding: EdgeInsets.all(Insets.xl),
                      child: Text(
                        'or'.tr,
                        style: TextStyles.body2.copyWith(color: Colors.white),
                      ),
                    ),
                  if (controller.isBiometrics.value)
                    ButtonLoginBiometrics(
                      isLoadingBiometric: controller.isLoadingBiometric.value,
                    ),
                  verticalSpace(Insets.xxl),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
Leave a Comment