mirror of
https://github.com/Linloir/Simple-TCP-Client.git
synced 2025-12-18 17:28:11 +08:00
Improvements:
- Login & Register page submit button debounce - Snack bar show failure info
This commit is contained in:
parent
dba8e0bb52
commit
f40d0987ce
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 15:38:07
|
* @Date : 2022-10-12 15:38:07
|
||||||
* @LastEditTime : 2022-10-12 17:36:53
|
* @LastEditTime : 2022-10-20 20:51:09
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -47,7 +47,8 @@ class LoginCubit extends Cubit<LoginState> {
|
|||||||
Future<void> onSubmission() async {
|
Future<void> onSubmission() async {
|
||||||
if(state.status.isValidated) {
|
if(state.status.isValidated) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
status: FormzStatus.submissionInProgress
|
status: FormzStatus.submissionInProgress,
|
||||||
|
info: ""
|
||||||
));
|
));
|
||||||
tcpRepository.pushRequest(LoginRequest(
|
tcpRepository.pushRequest(LoginRequest(
|
||||||
identity: UserIdentity(
|
identity: UserIdentity(
|
||||||
@ -67,7 +68,8 @@ class LoginCubit extends Cubit<LoginState> {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
status: FormzStatus.submissionFailure
|
status: FormzStatus.submissionFailure,
|
||||||
|
info: response.info?.replaceAll('Exception: ', ''),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 15:38:13
|
* @Date : 2022-10-12 15:38:13
|
||||||
* @LastEditTime : 2022-10-12 16:24:42
|
* @LastEditTime : 2022-10-20 20:49:43
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -16,28 +16,32 @@ class LoginState extends Equatable {
|
|||||||
final String avatar;
|
final String avatar;
|
||||||
|
|
||||||
final FormzStatus status;
|
final FormzStatus status;
|
||||||
|
final String info;
|
||||||
|
|
||||||
const LoginState({
|
const LoginState({
|
||||||
this.status = FormzStatus.pure,
|
this.status = FormzStatus.pure,
|
||||||
this.username = const Username.pure(),
|
this.username = const Username.pure(),
|
||||||
this.password = const Password.pure(),
|
this.password = const Password.pure(),
|
||||||
this.avatar = ""
|
this.avatar = "",
|
||||||
|
this.info = ""
|
||||||
});
|
});
|
||||||
|
|
||||||
LoginState copyWith({
|
LoginState copyWith({
|
||||||
FormzStatus? status,
|
FormzStatus? status,
|
||||||
Username? username,
|
Username? username,
|
||||||
Password? password,
|
Password? password,
|
||||||
String? avatar
|
String? avatar,
|
||||||
|
String? info,
|
||||||
}) {
|
}) {
|
||||||
return LoginState(
|
return LoginState(
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
username: username ?? this.username,
|
username: username ?? this.username,
|
||||||
password: password ?? this.password,
|
password: password ?? this.password,
|
||||||
avatar: avatar ?? this.avatar
|
avatar: avatar ?? this.avatar,
|
||||||
|
info: info ?? this.info
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [status, username, password, avatar];
|
List<Object?> get props => [status, username, password, avatar, info];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 15:06:30
|
* @Date : 2022-10-12 15:06:30
|
||||||
* @LastEditTime : 2022-10-14 10:47:08
|
* @LastEditTime : 2022-10-20 20:55:07
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -46,11 +46,13 @@ class LoginPage extends StatelessWidget {
|
|||||||
body: BlocListener<LoginCubit, LoginState>(
|
body: BlocListener<LoginCubit, LoginState>(
|
||||||
listener:(context, state) {
|
listener:(context, state) {
|
||||||
if(state.status == FormzStatus.submissionFailure) {
|
if(state.status == FormzStatus.submissionFailure) {
|
||||||
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
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) {
|
else if(state.status == FormzStatus.submissionSuccess) {
|
||||||
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Login Successed'))
|
const SnackBar(content: Text('Login Successed'))
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 16:29:25
|
* @Date : 2022-10-12 16:29:25
|
||||||
* @LastEditTime : 2022-10-12 17:31:23
|
* @LastEditTime : 2022-10-20 20:43:51
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -103,8 +103,13 @@ class SubmitButton extends StatelessWidget {
|
|||||||
}),
|
}),
|
||||||
overlayColor: MaterialStateProperty.all(Colors.blue[900]!.withOpacity(0.2))
|
overlayColor: MaterialStateProperty.all(Colors.blue[900]!.withOpacity(0.2))
|
||||||
),
|
),
|
||||||
onPressed: state.status == FormzStatus.submissionInProgress ? null : () {
|
onPressed: () {
|
||||||
context.read<LoginCubit>().onSubmission();
|
if(
|
||||||
|
state.status == FormzStatus.valid ||
|
||||||
|
state.status == FormzStatus.submissionFailure
|
||||||
|
) {
|
||||||
|
context.read<LoginCubit>().onSubmission();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: state.status == FormzStatus.submissionInProgress ?
|
child: state.status == FormzStatus.submissionInProgress ?
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-10 08:04:53
|
* @Date : 2022-10-10 08:04:53
|
||||||
* @LastEditTime : 2022-10-20 17:58:56
|
* @LastEditTime : 2022-10-20 20:38:45
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
import 'package:easy_debounce/easy_debounce.dart';
|
import 'package:easy_debounce/easy_debounce.dart';
|
||||||
@ -119,7 +119,7 @@ class SplashPage extends StatelessWidget {
|
|||||||
return BlocProvider<InitializationCubit>(
|
return BlocProvider<InitializationCubit>(
|
||||||
create: (context) {
|
create: (context) {
|
||||||
return InitializationCubit(
|
return InitializationCubit(
|
||||||
serverAddress: 'chat.linloir.cn',
|
serverAddress: '127.0.0.1',
|
||||||
serverPort: 20706
|
serverPort: 20706
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 15:38:07
|
* @Date : 2022-10-12 15:38:07
|
||||||
* @LastEditTime : 2022-10-12 17:52:03
|
* @LastEditTime : 2022-10-20 20:53:03
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -47,7 +47,8 @@ class RegisterCubit extends Cubit<RegisterState> {
|
|||||||
Future<void> onSubmission() async {
|
Future<void> onSubmission() async {
|
||||||
if(state.status.isValidated) {
|
if(state.status.isValidated) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
status: FormzStatus.submissionInProgress
|
status: FormzStatus.submissionInProgress,
|
||||||
|
info: ""
|
||||||
));
|
));
|
||||||
tcpRepository.pushRequest(RegisterRequest(
|
tcpRepository.pushRequest(RegisterRequest(
|
||||||
identity: UserIdentity(
|
identity: UserIdentity(
|
||||||
@ -67,7 +68,8 @@ class RegisterCubit extends Cubit<RegisterState> {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
status: FormzStatus.submissionFailure
|
status: FormzStatus.submissionFailure,
|
||||||
|
info: response.info?.replaceAll('Exception: ', ''),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 15:38:13
|
* @Date : 2022-10-12 15:38:13
|
||||||
* @LastEditTime : 2022-10-12 17:40:39
|
* @LastEditTime : 2022-10-20 20:52:19
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -16,28 +16,32 @@ class RegisterState extends Equatable {
|
|||||||
final String avatar;
|
final String avatar;
|
||||||
|
|
||||||
final FormzStatus status;
|
final FormzStatus status;
|
||||||
|
final String info;
|
||||||
|
|
||||||
const RegisterState({
|
const RegisterState({
|
||||||
this.status = FormzStatus.pure,
|
this.status = FormzStatus.pure,
|
||||||
this.username = const Username.pure(),
|
this.username = const Username.pure(),
|
||||||
this.password = const Password.pure(),
|
this.password = const Password.pure(),
|
||||||
this.avatar = ""
|
this.avatar = "",
|
||||||
|
this.info = ""
|
||||||
});
|
});
|
||||||
|
|
||||||
RegisterState copyWith({
|
RegisterState copyWith({
|
||||||
FormzStatus? status,
|
FormzStatus? status,
|
||||||
Username? username,
|
Username? username,
|
||||||
Password? password,
|
Password? password,
|
||||||
String? avatar
|
String? avatar,
|
||||||
|
String? info,
|
||||||
}) {
|
}) {
|
||||||
return RegisterState(
|
return RegisterState(
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
username: username ?? this.username,
|
username: username ?? this.username,
|
||||||
password: password ?? this.password,
|
password: password ?? this.password,
|
||||||
avatar: avatar ?? this.avatar
|
avatar: avatar ?? this.avatar,
|
||||||
|
info: info ?? this.info
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [status, username, password, avatar];
|
List<Object?> get props => [status, username, password, avatar, info];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 17:36:38
|
* @Date : 2022-10-12 17:36:38
|
||||||
* @LastEditTime : 2022-10-19 11:14:06
|
* @LastEditTime : 2022-10-20 20:55:17
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@ -56,11 +56,13 @@ class RegisterPage extends StatelessWidget {
|
|||||||
body: BlocListener<RegisterCubit, RegisterState>(
|
body: BlocListener<RegisterCubit, RegisterState>(
|
||||||
listener:(context, state) {
|
listener:(context, state) {
|
||||||
if(state.status == FormzStatus.submissionFailure) {
|
if(state.status == FormzStatus.submissionFailure) {
|
||||||
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
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) {
|
else if(state.status == FormzStatus.submissionSuccess) {
|
||||||
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Register Successed'))
|
const SnackBar(content: Text('Register Successed'))
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-12 16:29:25
|
* @Date : 2022-10-12 16:29:25
|
||||||
* @LastEditTime : 2022-10-12 17:44:33
|
* @LastEditTime : 2022-10-20 20:54:22
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -103,8 +103,13 @@ class SubmitButton extends StatelessWidget {
|
|||||||
}),
|
}),
|
||||||
overlayColor: MaterialStateProperty.all(Colors.blue[900]!.withOpacity(0.2))
|
overlayColor: MaterialStateProperty.all(Colors.blue[900]!.withOpacity(0.2))
|
||||||
),
|
),
|
||||||
onPressed: state.status == FormzStatus.submissionInProgress ? null : () {
|
onPressed: () {
|
||||||
context.read<RegisterCubit>().onSubmission();
|
if(
|
||||||
|
state.status == FormzStatus.valid ||
|
||||||
|
state.status == FormzStatus.submissionFailure
|
||||||
|
) {
|
||||||
|
context.read<RegisterCubit>().onSubmission();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: state.status == FormzStatus.submissionInProgress ?
|
child: state.status == FormzStatus.submissionInProgress ?
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user