Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:io';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:module_auth/presentation/cubit/validate_login_cubit.dart';
- import 'package:module_auth/presentation/pages/forgot_password/forgot_password_check_page.dart';
- import 'package:module_core/module_core.dart';
- import 'package:module_core/module_core.dart' as di;
- import 'package:module_dependencies/module_dependencies.dart';
- import 'package:module_dependencies/module_dependencies_ui.dart';
- class LoginPage extends StatefulWidget {
- const LoginPage({super.key});
- static const routeName = '/login';
- @override
- State<LoginPage> createState() => _LoginPageState();
- }
- class _LoginPageState extends State<LoginPage> {
- final _formKey = GlobalKey<FormState>();
- final TextEditingController _mobileNumberController = TextEditingController();
- final TextEditingController _passwordController = TextEditingController();
- final _validateLoginCubit = ValidateLoginCubit();
- @override
- void dispose() {
- _mobileNumberController.dispose();
- _passwordController.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return BlocProvider(
- create: (_) => di.locator<LoginBloc>(),
- child: Scaffold(
- appBar: CustomAppBar(
- titleText: 'MASUK',
- leading: InkWell(
- hoverColor: colorPrimary,
- onTap: () => Navigator.pop(context),
- child: const Icon(
- CupertinoIcons.back,
- color: Colors.white,
- size: 24,
- ),
- ),
- ),
- body: SingleChildScrollView(
- padding: EdgeInsets.symmetric(
- horizontal: defaultMargin,
- ),
- child: Form(
- key: _formKey,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Gap(50.h),
- Image.asset(
- Assets.png.myagentDesc.path,
- height: context.width / 2,
- ),
- Gap(24.h),
- CustomTextField(
- controller: _mobileNumberController,
- textName: 'Nomor Ponsel',
- hintText: 'Nomor Ponsel',
- maxLines: 1,
- keyboardType: Platform.isIOS
- ? const TextInputType.numberWithOptions(
- signed: true,
- )
- : TextInputType.number,
- inputFormatters: [
- FilteringTextInputFormatter.digitsOnly,
- ],
- validator: (value) {
- if (value != null) {
- if (value.isEmpty) {
- return 'Nomor ponsel tidak boleh kosong';
- }
- if (value.length < 9) {
- return 'Nomor ponsel minimal 9 karakter';
- }
- if (value.length > 15) {
- return 'Nomor ponsel maksimal 15 karakter';
- }
- if (value.length > 2) {
- if (value.substring(0, 2) != '08') {
- return 'Nomor ponsel tidak valid';
- }
- }
- }
- return null;
- },
- onChanged: (value) {
- _validateLoginCubit
- .update(_formKey.currentState?.validate() ?? false);
- },
- ),
- const Gap(25),
- CustomTextField(
- controller: _passwordController,
- textName: 'Password',
- hintText: 'Password',
- isObsecure: true,
- maxLines: 1,
- validator: (value) {
- if (value != null) {
- if (value.isEmpty) {
- return 'Password tidak boleh kosong';
- }
- }
- return null;
- },
- onChanged: (value) {
- _validateLoginCubit
- .update(_formKey.currentState?.validate() ?? false);
- },
- ),
- const Gap(30),
- BlocBuilder<ValidateLoginCubit, bool>(
- bloc: _validateLoginCubit,
- builder: (context, state) {
- return BlocConsumer<LoginBloc, LoginState>(
- listener: (context, stateLogin) {
- if (stateLogin.state == RequestState.loaded) {
- Navigator.of(context).pushNamedAndRemoveUntil(
- MainPage.routeName,
- (_) => false,
- );
- CustomToast.showSuccess(
- 'Login berhasil',
- context: context,
- );
- } else if (stateLogin.state == RequestState.error) {
- if (stateLogin.message ==
- 'No Handphone belum terdaftar') {
- showDialog(
- context: context,
- builder: (context) {
- return ErrorMessageDialog(
- errorMessage: stateLogin.message,
- onTap: () {
- Navigator.pop(context);
- Navigator.pushNamed(
- context,
- IntroductionRegisterPage.routeName,
- );
- },
- buttonLabel: 'DAFTAR AKUN BARU',
- );
- },
- );
- } else {
- showDialog(
- context: context,
- builder: (context) {
- return ErrorMessageDialog(
- errorMessage: stateLogin.message,
- );
- },
- );
- }
- }
- },
- builder: (context, stateLogin) {
- if (stateLogin.state == RequestState.loading) {
- return SizedBox(
- height: 42,
- width: double.infinity,
- child: LoadingShimmer(radius: defaultRadius),
- );
- }
- return CustomButton.buttonRounded(
- radius: defaultRadius,
- onTap: state
- ? () {
- if (FocusScope.of(context).hasFocus) {
- FocusManager.instance.primaryFocus
- ?.unfocus();
- }
- BlocProvider.of<LoginBloc>(
- context,
- ).add(
- PostLoginEvent(
- _mobileNumberController.text,
- _passwordController.text,
- ),
- );
- }
- : null,
- text: "MASUK",
- color: state ? colorPrimary : colorGrey,
- );
- },
- );
- },
- ),
- Gap(16.h),
- InkWell(
- onTap: () {
- showModalBottomSheet(
- context: context,
- isScrollControlled: true,
- useRootNavigator: true,
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.vertical(
- top: Radius.circular(24.0),
- ),
- ),
- builder: (_) {
- return LayoutBuilder(
- builder: (context, _) {
- return AnimatedPadding(
- padding: MediaQuery.of(
- context,
- ).viewInsets,
- duration: const Duration(
- milliseconds: 100,
- ),
- child: const ForgotPasswordCheckPage(),
- );
- },
- );
- },
- );
- },
- child: Text(
- 'Lupa kata sandi',
- textAlign: TextAlign.center,
- style: blackTextStyle.copyWith(
- fontSize: 12.sp,
- fontWeight: regular,
- height: 1.5,
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement