import 'package:baseproject/core/common/index.dart'; import 'package:baseproject/core/components/index.dart'; import 'package:baseproject/features/presentation/account/bloc/login_bloc.dart'; import 'package:baseproject/features/repositories/hra_repository.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({Key? key}) : super(key: key); @override State createState() => _LoginScreenState(); } class _LoginScreenState extends State { final GlobalKey _formKey = GlobalKey(); bool _rememberMe = false; final LoginBloc _loginBloc = getItSuper(); Future _onSubmit() async { final formState = _formKey.currentState; if (formState == null) return; if (!formState.saveAndValidate()) { return; } final value = formState.value; final dto = LoginDto( userName: value['userName'] as String?, password: value['password'] as String?, rememberMe: _rememberMe, ); final captcha = _loginBloc.state.model.captcha; dto.captchaText = "999999"; //captcha?.dntCaptchaTextValue; dto.captchaToken = captcha?.dntCaptchaTokenValue; dto.captchaInputText = "999999"; _loginBloc.login(dto, context); } @override Widget build(BuildContext context) { return BlocProvider( create: (_) => _loginBloc, child: Scaffold( appBar: AppBar( title: const Text('Đăng nhập'), ), body: SafeArea( child: Padding( padding: const EdgeInsets.all(16), child: FormBuilder( initialValue: kDebugMode ? { 'userName': 'hocsinh001', 'password': 'BearCMS0011002848238master', } : {}, key: _formKey, autovalidateMode: AutovalidateMode.onUserInteraction, child: BlocBuilder>( builder: (context, state) { final vm = state.model; final isLoading = state is LoadingState || vm.isLoading; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ CustomTextField( name: 'userName', labelText: 'Tên đăng nhập', isLabelTop: true, isShowTextRequire: true, validator: FormBuilderValidators.required( context, ), ), ConstantWidget.heightSpace16, TextFieldPassword( name: 'password', labelText: 'Mật khẩu', validator: FormBuilderValidators.required( context, ), ), ConstantWidget.heightSpace24, SizedBox( height: 48, child: ConstantWidget.buildPrimaryButton( onPressed: isLoading ? null : _onSubmit, text: 'Đăng nhập', ), ), ], ); }, ), ), ), ), ), ); } }