Commit 5dadc46a by tanghuan

微信登录时,增加loading

1 parent c500d097
......@@ -8,23 +8,33 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluwx/fluwx.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LoginMainState extends Equatable {
final bool agreed;
final bool showAgreed;
final bool loading;
const LoginMainState({this.agreed = false, this.showAgreed = false});
const LoginMainState({
this.agreed = false,
this.showAgreed = false,
this.loading = false,
});
@override
List<Object?> get props => [agreed, showAgreed];
List<Object?> get props => [
agreed,
showAgreed,
loading,
];
LoginMainState copyWith({
bool? agreed,
bool? showAgreed,
bool? loading,
}) {
return LoginMainState(
agreed: agreed ?? this.agreed,
showAgreed: showAgreed ?? this.showAgreed,
loading: loading ?? this.loading,
);
}
}
......@@ -67,6 +77,9 @@ class LoginMainCubit extends Cubit<LoginMainState> {
if (!result) {
throw Exception('微信授权处理失败');
}
// 控制显示加载框
emit(state.copyWith(loading: true));
}
void goLoginPhone() {
......@@ -98,7 +111,7 @@ class LoginMainCubit extends Cubit<LoginMainState> {
sharedPreferences.setString('auth_stuId', stuId ?? '');
sharedPreferences.setString('auth_ip', Constant.h5Server);
if(Constant.needIM){
if (Constant.needIM) {
// IM登录, 正式使用时,需要从服务端获取用户签名
var loginResult = await _imService.login(userCode);
if (loginResult) {
......
......@@ -14,7 +14,9 @@ class LoginMainPage extends StatelessWidget {
create: (context) => LoginMainCubit(LoginMainState()),
child: BlocConsumer<LoginMainCubit, LoginMainState>(builder: (context, state) {
var loginMainCubit = context.read<LoginMainCubit>();
return Scaffold(
return Stack(
children: [
Scaffold(
resizeToAvoidBottomInset: true,
backgroundColor: Colors.white,
body: SafeArea(
......@@ -36,7 +38,6 @@ class LoginMainPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 30),
// _buildHeader(),
LoginPageHeaderWidget(),
SizedBox(height: 25),
_buildLoginButtons(context, loginMainCubit, state.agreed),
......@@ -49,6 +50,25 @@ class LoginMainPage extends StatelessWidget {
],
)),
),
),
state.loading
? Container(
color: Colors.black54,
width: MediaQuery.of(context).size.width,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(
color: Color(0xFF7691FA),
),
],
),
),
)
: SizedBox(),
],
);
}, listener: (context, state) {
if (state.showAgreed) {
......@@ -58,31 +78,6 @@ class LoginMainPage extends StatelessWidget {
);
}
Widget _buildHeader() {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'欢迎登录',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
SizedBox(height: 6),
Text(
'班小二,班级群必备效率工具',
style: TextStyle(
fontSize: 14,
color: Colors.black87,
),
),
],
);
}
Widget _buildLoginButtons(BuildContext context, LoginMainCubit loginMainCubit, bool agreed) {
return Column(
children: [
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!