From f40d0987ce84a5f5f3081fa73f13270baf382cba Mon Sep 17 00:00:00 2001 From: Linloir <3145078758@qq.com> Date: Thu, 20 Oct 2022 21:00:47 +0800 Subject: [PATCH] Improvements: - Login & Register page submit button debounce - Snack bar show failure info --- lib/login/cubit/login_cubit.dart | 8 +++++--- lib/login/cubit/login_state.dart | 14 +++++++++----- lib/login/login_page.dart | 6 ++++-- lib/login/view/login_form.dart | 11 ++++++++--- lib/main.dart | 4 ++-- lib/register/cubit/register_cubit.dart | 8 +++++--- lib/register/cubit/register_state.dart | 14 +++++++++----- lib/register/register_page.dart | 6 ++++-- lib/register/view/register_form.dart | 11 ++++++++--- 9 files changed, 54 insertions(+), 28 deletions(-) diff --git a/lib/login/cubit/login_cubit.dart b/lib/login/cubit/login_cubit.dart index 654fe84..34d5ed7 100644 --- a/lib/login/cubit/login_cubit.dart +++ b/lib/login/cubit/login_cubit.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 15:38:07 - * @LastEditTime : 2022-10-12 17:36:53 + * @LastEditTime : 2022-10-20 20:51:09 * @Description : */ @@ -47,7 +47,8 @@ class LoginCubit extends Cubit { Future onSubmission() async { if(state.status.isValidated) { emit(state.copyWith( - status: FormzStatus.submissionInProgress + status: FormzStatus.submissionInProgress, + info: "" )); tcpRepository.pushRequest(LoginRequest( identity: UserIdentity( @@ -67,7 +68,8 @@ class LoginCubit extends Cubit { } else { emit(state.copyWith( - status: FormzStatus.submissionFailure + status: FormzStatus.submissionFailure, + info: response.info?.replaceAll('Exception: ', ''), )); } break; diff --git a/lib/login/cubit/login_state.dart b/lib/login/cubit/login_state.dart index f8ba983..8682cdc 100644 --- a/lib/login/cubit/login_state.dart +++ b/lib/login/cubit/login_state.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 15:38:13 - * @LastEditTime : 2022-10-12 16:24:42 + * @LastEditTime : 2022-10-20 20:49:43 * @Description : */ @@ -16,28 +16,32 @@ class LoginState extends Equatable { final String avatar; final FormzStatus status; + final String info; const LoginState({ this.status = FormzStatus.pure, this.username = const Username.pure(), this.password = const Password.pure(), - this.avatar = "" + this.avatar = "", + this.info = "" }); LoginState copyWith({ FormzStatus? status, Username? username, Password? password, - String? avatar + String? avatar, + String? info, }) { return LoginState( status: status ?? this.status, username: username ?? this.username, password: password ?? this.password, - avatar: avatar ?? this.avatar + avatar: avatar ?? this.avatar, + info: info ?? this.info ); } @override - List get props => [status, username, password, avatar]; + List get props => [status, username, password, avatar, info]; } diff --git a/lib/login/login_page.dart b/lib/login/login_page.dart index b17f9d2..abb266d 100644 --- a/lib/login/login_page.dart +++ b/lib/login/login_page.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 15:06:30 - * @LastEditTime : 2022-10-14 10:47:08 + * @LastEditTime : 2022-10-20 20:55:07 * @Description : */ @@ -46,11 +46,13 @@ class LoginPage extends StatelessWidget { body: BlocListener( listener:(context, state) { if(state.status == FormzStatus.submissionFailure) { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Login Failed')) + SnackBar(content: Text('Login Failed${state.info.isNotEmpty ? ': ${state.info}' : ''}')) ); } else if(state.status == FormzStatus.submissionSuccess) { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Login Successed')) ); diff --git a/lib/login/view/login_form.dart b/lib/login/view/login_form.dart index b5b8e8a..69470d4 100644 --- a/lib/login/view/login_form.dart +++ b/lib/login/view/login_form.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 16:29:25 - * @LastEditTime : 2022-10-12 17:31:23 + * @LastEditTime : 2022-10-20 20:43:51 * @Description : */ @@ -103,8 +103,13 @@ class SubmitButton extends StatelessWidget { }), overlayColor: MaterialStateProperty.all(Colors.blue[900]!.withOpacity(0.2)) ), - onPressed: state.status == FormzStatus.submissionInProgress ? null : () { - context.read().onSubmission(); + onPressed: () { + if( + state.status == FormzStatus.valid || + state.status == FormzStatus.submissionFailure + ) { + context.read().onSubmission(); + } }, child: state.status == FormzStatus.submissionInProgress ? const SizedBox( diff --git a/lib/main.dart b/lib/main.dart index 4429c3c..8e7e8da 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-10 08:04:53 - * @LastEditTime : 2022-10-20 17:58:56 + * @LastEditTime : 2022-10-20 20:38:45 * @Description : */ import 'package:easy_debounce/easy_debounce.dart'; @@ -119,7 +119,7 @@ class SplashPage extends StatelessWidget { return BlocProvider( create: (context) { return InitializationCubit( - serverAddress: 'chat.linloir.cn', + serverAddress: '127.0.0.1', serverPort: 20706 ); }, diff --git a/lib/register/cubit/register_cubit.dart b/lib/register/cubit/register_cubit.dart index cd339b5..ccc86c9 100644 --- a/lib/register/cubit/register_cubit.dart +++ b/lib/register/cubit/register_cubit.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 15:38:07 - * @LastEditTime : 2022-10-12 17:52:03 + * @LastEditTime : 2022-10-20 20:53:03 * @Description : */ @@ -47,7 +47,8 @@ class RegisterCubit extends Cubit { Future onSubmission() async { if(state.status.isValidated) { emit(state.copyWith( - status: FormzStatus.submissionInProgress + status: FormzStatus.submissionInProgress, + info: "" )); tcpRepository.pushRequest(RegisterRequest( identity: UserIdentity( @@ -67,7 +68,8 @@ class RegisterCubit extends Cubit { } else { emit(state.copyWith( - status: FormzStatus.submissionFailure + status: FormzStatus.submissionFailure, + info: response.info?.replaceAll('Exception: ', ''), )); } break; diff --git a/lib/register/cubit/register_state.dart b/lib/register/cubit/register_state.dart index 5783f0e..8a85ee0 100644 --- a/lib/register/cubit/register_state.dart +++ b/lib/register/cubit/register_state.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 15:38:13 - * @LastEditTime : 2022-10-12 17:40:39 + * @LastEditTime : 2022-10-20 20:52:19 * @Description : */ @@ -16,28 +16,32 @@ class RegisterState extends Equatable { final String avatar; final FormzStatus status; + final String info; const RegisterState({ this.status = FormzStatus.pure, this.username = const Username.pure(), this.password = const Password.pure(), - this.avatar = "" + this.avatar = "", + this.info = "" }); RegisterState copyWith({ FormzStatus? status, Username? username, Password? password, - String? avatar + String? avatar, + String? info, }) { return RegisterState( status: status ?? this.status, username: username ?? this.username, password: password ?? this.password, - avatar: avatar ?? this.avatar + avatar: avatar ?? this.avatar, + info: info ?? this.info ); } @override - List get props => [status, username, password, avatar]; + List get props => [status, username, password, avatar, info]; } diff --git a/lib/register/register_page.dart b/lib/register/register_page.dart index 8846ae7..a2d9c2e 100644 --- a/lib/register/register_page.dart +++ b/lib/register/register_page.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 17:36:38 - * @LastEditTime : 2022-10-19 11:14:06 + * @LastEditTime : 2022-10-20 20:55:17 * @Description : */ /* @@ -56,11 +56,13 @@ class RegisterPage extends StatelessWidget { body: BlocListener( listener:(context, state) { if(state.status == FormzStatus.submissionFailure) { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Register Failed')) + SnackBar(content: Text('Register Failed${state.info.isNotEmpty ? ': ${state.info}' : ''}')) ); } else if(state.status == FormzStatus.submissionSuccess) { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Register Successed')) ); diff --git a/lib/register/view/register_form.dart b/lib/register/view/register_form.dart index 0823174..e73c27f 100644 --- a/lib/register/view/register_form.dart +++ b/lib/register/view/register_form.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-12 16:29:25 - * @LastEditTime : 2022-10-12 17:44:33 + * @LastEditTime : 2022-10-20 20:54:22 * @Description : */ @@ -103,8 +103,13 @@ class SubmitButton extends StatelessWidget { }), overlayColor: MaterialStateProperty.all(Colors.blue[900]!.withOpacity(0.2)) ), - onPressed: state.status == FormzStatus.submissionInProgress ? null : () { - context.read().onSubmission(); + onPressed: () { + if( + state.status == FormzStatus.valid || + state.status == FormzStatus.submissionFailure + ) { + context.read().onSubmission(); + } }, child: state.status == FormzStatus.submissionInProgress ? const SizedBox(