Commit 05f9b20a5fb7fb5f685592dd1614f178638da8d3
1 parent
fcc3a982
fixed: api调用方式,未完善
Showing
13 changed files
with
208 additions
and
265 deletions
lib/app/app.dart
@@ -16,9 +16,9 @@ class App extends StatelessWidget { | @@ -16,9 +16,9 @@ class App extends StatelessWidget { | ||
16 | Widget build(BuildContext context) { | 16 | Widget build(BuildContext context) { |
17 | return ScreenUtilInit( | 17 | return ScreenUtilInit( |
18 | designSize: const Size(667, 375), | 18 | designSize: const Size(667, 375), |
19 | - builder: (_,__) => MultiBlocProvider( | 19 | + builder: (_, __) => MultiBlocProvider( |
20 | providers: [ | 20 | providers: [ |
21 | - BlocProvider<TabBloc>(create: (_)=> TabBloc()), | 21 | + BlocProvider<TabBloc>(create: (_) => TabBloc()), |
22 | BlocProvider<CacheBloc>(create: (_) => CacheBloc()) | 22 | BlocProvider<CacheBloc>(create: (_) => CacheBloc()) |
23 | ], | 23 | ], |
24 | child: HideKeyboard( | 24 | child: HideKeyboard( |
@@ -30,16 +30,13 @@ class App extends StatelessWidget { | @@ -30,16 +30,13 @@ class App extends StatelessWidget { | ||
30 | useMaterial3: true, | 30 | useMaterial3: true, |
31 | ), | 31 | ), |
32 | builder: EasyLoading.init( | 32 | builder: EasyLoading.init( |
33 | - builder: (context,child) => ResponsiveBreakpoints( | ||
34 | - breakpoints: const [ | ||
35 | - Breakpoint(start: 0, end: 450, name: MOBILE), | ||
36 | - Breakpoint(start: 0, end: 450, name: PHONE), | ||
37 | - Breakpoint(start: 451, end: 800, name: TABLET), | ||
38 | - Breakpoint(start: 801, end: 1920, name: DESKTOP), | ||
39 | - Breakpoint(start: 1921, end: double.infinity, name: '4K'), | ||
40 | - ], | ||
41 | - child: child!) | ||
42 | - ), | 33 | + builder: (context, child) => ResponsiveBreakpoints(breakpoints: const [ |
34 | + Breakpoint(start: 0, end: 450, name: MOBILE), | ||
35 | + Breakpoint(start: 0, end: 450, name: PHONE), | ||
36 | + Breakpoint(start: 451, end: 800, name: TABLET), | ||
37 | + Breakpoint(start: 801, end: 1920, name: DESKTOP), | ||
38 | + Breakpoint(start: 1921, end: double.infinity, name: '4K'), | ||
39 | + ], child: child!)), | ||
43 | initialRoute: AppRouteName.splash, | 40 | initialRoute: AppRouteName.splash, |
44 | navigatorKey: AppRouter.navigatorKey, | 41 | navigatorKey: AppRouter.navigatorKey, |
45 | onGenerateRoute: AppRouter.generateRoute, | 42 | onGenerateRoute: AppRouter.generateRoute, |
lib/common/request/api_response/api_response_entity.g.dart
@@ -16,7 +16,7 @@ ApiResponse<T> $ApiResponseFromJson<T>(Map<String, dynamic> json) { | @@ -16,7 +16,7 @@ ApiResponse<T> $ApiResponseFromJson<T>(Map<String, dynamic> json) { | ||
16 | String type = T.toString(); | 16 | String type = T.toString(); |
17 | T? data; | 17 | T? data; |
18 | if (kDebugMode) { | 18 | if (kDebugMode) { |
19 | - print("type:$type"); | 19 | + print("ApiResponse <T> type:$type"); |
20 | } | 20 | } |
21 | if (json['data'] != null) { | 21 | if (json['data'] != null) { |
22 | data = jsonConvert.convert<T>(json['data']); | 22 | data = jsonConvert.convert<T>(json['data']); |
lib/common/request/config.dart
1 | ///request config | 1 | ///request config |
2 | class RequestConfig { | 2 | class RequestConfig { |
3 | static String baseUrl = 'http://wow-app.dev.kouyuxingqiu.com/'; | 3 | static String baseUrl = 'http://wow-app.dev.kouyuxingqiu.com/'; |
4 | + static String token = ''; | ||
4 | static const connectTimeout = Duration(seconds: 15); | 5 | static const connectTimeout = Duration(seconds: 15); |
5 | static const successCode = 200; | 6 | static const successCode = 200; |
6 | } | 7 | } |
lib/common/request/dao/user_dao.dart
1 | -import '../../../models/user_entity.dart'; | ||
2 | -import '../api_response/api_response_entity.dart'; | 1 | +import 'package:wow_english/models/user_entity.dart'; |
2 | + | ||
3 | import '../apis.dart'; | 3 | import '../apis.dart'; |
4 | -import '../exception.dart'; | ||
5 | import '../request_client.dart'; | 4 | import '../request_client.dart'; |
6 | 5 | ||
7 | class UserDao { | 6 | class UserDao { |
8 | - static loginByPassword( | ||
9 | - phoneNumber, | ||
10 | - password, | ||
11 | - Function(ApiResponse<UserEntity>)? onResponse, | ||
12 | - bool Function(ApiException)? onError, | ||
13 | - ) async { | ||
14 | - /*await DioUtil().requestData( | ||
15 | - HttpMethod.post, | ||
16 | - Api.login, | ||
17 | - data: { | ||
18 | - 'phoneNum':phoneNumber, | ||
19 | - 'type':'pwd', | ||
20 | - 'password':password}, | ||
21 | - successCallBack: (data){ | ||
22 | - emitter(LoginResultChangeState(true)); | ||
23 | - }, | ||
24 | - errorCallBack: (error){ | ||
25 | - emitter(LoginResultChangeState(false)); | ||
26 | - });*/ | ||
27 | - var params = {'phoneNum': phoneNumber, 'type': 'pwd', 'password': password}; | ||
28 | - await requestClient.post(Apis.login, data: params, onResponse: onResponse, onError: onError); | 7 | + static Future<UserEntity?> login(phoneNumber, type, checkKey, checkNumber) { |
8 | + var params = {'phoneNum': phoneNumber, 'type': type, checkKey: checkNumber}; | ||
9 | + var data = requestClient.post<UserEntity>( | ||
10 | + Apis.login, | ||
11 | + data: params, | ||
12 | + ); | ||
13 | + return data; | ||
29 | } | 14 | } |
30 | - | ||
31 | - static loginBySmsCode(phoneNumber, smsCode) {} | ||
32 | } | 15 | } |
lib/common/request/exception.dart
1 | import 'package:dio/dio.dart'; | 1 | import 'package:dio/dio.dart'; |
2 | +import 'package:flutter/foundation.dart'; | ||
3 | + | ||
2 | import 'api_response/api_response_entity.dart'; | 4 | import 'api_response/api_response_entity.dart'; |
3 | 5 | ||
4 | class ApiException implements Exception { | 6 | class ApiException implements Exception { |
@@ -57,7 +59,11 @@ class ApiException implements Exception { | @@ -57,7 +59,11 @@ class ApiException implements Exception { | ||
57 | return ApiException(errCode, error.response?.statusMessage ?? '未知错误'); | 59 | return ApiException(errCode, error.response?.statusMessage ?? '未知错误'); |
58 | } | 60 | } |
59 | } on Exception catch (e) { | 61 | } on Exception catch (e) { |
60 | - return ApiException(-1, unknownException); | 62 | + if (kDebugMode) { |
63 | + return ApiException(-1, e.toString()); | ||
64 | + } else { | ||
65 | + return ApiException(-1, unknownException); | ||
66 | + } | ||
61 | } | 67 | } |
62 | default: | 68 | default: |
63 | return ApiException(-1, error.message); | 69 | return ApiException(-1, error.message); |
lib/common/request/exception_handler.dart
@@ -2,9 +2,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; | @@ -2,9 +2,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; | ||
2 | 2 | ||
3 | import 'exception.dart'; | 3 | import 'exception.dart'; |
4 | 4 | ||
5 | - | ||
6 | -bool handleException(ApiException exception, | ||
7 | - {bool Function(ApiException)? onError}) { | 5 | +bool handleException(ApiException exception, {bool Function(ApiException)? onError}) { |
8 | if (onError?.call(exception) == true) { | 6 | if (onError?.call(exception) == true) { |
9 | return true; | 7 | return true; |
10 | } | 8 | } |
@@ -14,6 +12,5 @@ bool handleException(ApiException exception, | @@ -14,6 +12,5 @@ bool handleException(ApiException exception, | ||
14 | return true; | 12 | return true; |
15 | } | 13 | } |
16 | EasyLoading.showError(exception.message ?? ApiException.unknownException); | 14 | EasyLoading.showError(exception.message ?? ApiException.unknownException); |
17 | - | ||
18 | return false; | 15 | return false; |
19 | } | 16 | } |
lib/common/request/request.dart
@@ -2,15 +2,17 @@ import '../../utils/loading.dart'; | @@ -2,15 +2,17 @@ import '../../utils/loading.dart'; | ||
2 | import 'exception.dart'; | 2 | import 'exception.dart'; |
3 | import 'exception_handler.dart'; | 3 | import 'exception_handler.dart'; |
4 | 4 | ||
5 | -Future request( | 5 | +Future<T?> request<T>( |
6 | Function() block, { | 6 | Function() block, { |
7 | - bool showLoading = true, | 7 | + String loadingText = '加载中...', |
8 | bool Function(ApiException)? onError, | 8 | bool Function(ApiException)? onError, |
9 | }) async { | 9 | }) async { |
10 | try { | 10 | try { |
11 | - await loading(block, isShowLoading: showLoading); | 11 | + return await loading(block, loadingText: loadingText); |
12 | } catch (e) { | 12 | } catch (e) { |
13 | - handleException(ApiException.from(e), onError: onError); | 13 | + if (!handleException(ApiException.from(e), onError: onError)) { |
14 | + rethrow; | ||
15 | + } | ||
14 | } | 16 | } |
15 | - return; | 17 | + return null; |
16 | } | 18 | } |
lib/common/request/request_client.dart
@@ -45,7 +45,6 @@ class RequestClient { | @@ -45,7 +45,6 @@ class RequestClient { | ||
45 | throw exception; | 45 | throw exception; |
46 | } | 46 | } |
47 | } | 47 | } |
48 | - | ||
49 | return null; | 48 | return null; |
50 | } | 49 | } |
51 | 50 | ||
@@ -132,7 +131,6 @@ class RequestClient { | @@ -132,7 +131,6 @@ class RequestClient { | ||
132 | Function(ApiResponse<T>)? onResponse, | 131 | Function(ApiResponse<T>)? onResponse, |
133 | ) { | 132 | ) { |
134 | int statusCode = response.statusCode ?? -1; | 133 | int statusCode = response.statusCode ?? -1; |
135 | - print('statusCode=$statusCode'); | ||
136 | // 200..299 成功响应 | 134 | // 200..299 成功响应 |
137 | if (statusCode >= 200 && statusCode <= 299) { | 135 | if (statusCode >= 200 && statusCode <= 299) { |
138 | if (T.toString() == (RawData).toString()) { | 136 | if (T.toString() == (RawData).toString()) { |
lib/common/request/token_interceptor.dart
1 | import 'package:dio/dio.dart'; | 1 | import 'package:dio/dio.dart'; |
2 | +import 'package:wow_english/common/request/config.dart'; | ||
2 | 3 | ||
3 | class TokenInterceptor extends Interceptor { | 4 | class TokenInterceptor extends Interceptor { |
4 | @override | 5 | @override |
5 | void onRequest(RequestOptions options, RequestInterceptorHandler handler) { | 6 | void onRequest(RequestOptions options, RequestInterceptorHandler handler) { |
6 | - /// todo 判断token不为空插入 | ||
7 | - options.headers["Auth-token"] = ''; | 7 | + // 判断token不为空插入, todo token的取法应该跟user在一起,这里取不到user |
8 | + if (RequestConfig.token.isNotEmpty) { | ||
9 | + options.headers["Auth-token"] = RequestConfig.token; | ||
10 | + } | ||
8 | options.headers["version"] = '1.0.0'; | 11 | options.headers["version"] = '1.0.0'; |
9 | super.onRequest(options, handler); | 12 | super.onRequest(options, handler); |
10 | } | 13 | } |
lib/pages/login/loginpage/bloc/login_bloc.dart
1 | -import 'dart:js'; | ||
2 | - | ||
3 | import 'package:flutter/cupertino.dart'; | 1 | import 'package:flutter/cupertino.dart'; |
4 | import 'package:flutter_bloc/flutter_bloc.dart'; | 2 | import 'package:flutter_bloc/flutter_bloc.dart'; |
5 | import 'package:flutter_easyloading/flutter_easyloading.dart'; | 3 | import 'package:flutter_easyloading/flutter_easyloading.dart'; |
6 | - | ||
7 | -import '../../../../common/request/api_response/api_response_entity.dart'; | ||
8 | -import '../../../../common/request/apis.dart'; | ||
9 | -import '../../../../common/request/request.dart'; | ||
10 | -import '../../../../common/request/request_client.dart'; | ||
11 | -import '../../../../models/user_entity.dart'; | 4 | +import 'package:wow_english/common/request/config.dart'; |
5 | +import 'package:wow_english/common/request/dao/user_dao.dart'; | ||
6 | +import 'package:wow_english/models/user_entity.dart'; | ||
7 | +import 'package:wow_english/utils/loading.dart'; | ||
12 | 8 | ||
13 | part 'login_event.dart'; | 9 | part 'login_event.dart'; |
14 | part 'login_state.dart'; | 10 | part 'login_state.dart'; |
@@ -73,29 +69,22 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> { | @@ -73,29 +69,22 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> { | ||
73 | var checkKey = _isSmsLoginType ? 'smsCode' : 'password'; | 69 | var checkKey = _isSmsLoginType ? 'smsCode' : 'password'; |
74 | var type = _isSmsLoginType ? 'sms_code' : 'pwd'; | 70 | var type = _isSmsLoginType ? 'sms_code' : 'pwd'; |
75 | 71 | ||
76 | - request(() async { | ||
77 | - var params = {'phoneNum': phoneNumber, 'type': type, checkKey: checkNumber}; | ||
78 | - await requestClient.post( | ||
79 | - Apis.login, | ||
80 | - data: params, | ||
81 | - onResponse: (ApiResponse<UserEntity> response) { | ||
82 | - print('response=$response'); | ||
83 | - // todo 持久化用户对象 | ||
84 | - // todo 写入全局对象 | ||
85 | - //emitter.call(LoginResultChangeState()); | ||
86 | - }, | ||
87 | - onError: (e) { | ||
88 | - EasyLoading.showToast('登陆失败:${e.message}'); | ||
89 | - return true; | ||
90 | - }, | ||
91 | - ); | ||
92 | - }); | 72 | + try { |
73 | + await loading(() async { | ||
74 | + var user = await UserDao.login(phoneNumber, type, checkKey, checkNumber); | ||
75 | + print('login已执行'); | ||
76 | + print('user=$user'); | ||
77 | + RequestConfig.token = user!.token; | ||
78 | + emitter.call(LoginResultChangeState(user)); | ||
79 | + }); | ||
80 | + } catch (e) { | ||
81 | + print(e); | ||
82 | + EasyLoading.showToast('登陆失败'); | ||
83 | + } | ||
93 | } | 84 | } |
94 | 85 | ||
95 | ///请求验证码 | 86 | ///请求验证码 |
96 | - void _requestSmsCodeApi(RequestSmsCodeEvent event, Emitter<LoginState> emitter) async { | ||
97 | - | ||
98 | - } | 87 | + void _requestSmsCodeApi(RequestSmsCodeEvent event, Emitter<LoginState> emitter) async {} |
99 | 88 | ||
100 | ///切换登陆方式 | 89 | ///切换登陆方式 |
101 | void _changeLoginType(ChangeLoginTypeEvent event, Emitter<LoginState> emitter) async { | 90 | void _changeLoginType(ChangeLoginTypeEvent event, Emitter<LoginState> emitter) async { |
lib/pages/login/loginpage/bloc/login_state.dart
@@ -16,8 +16,13 @@ class SmsSendTypeChangeState extends LoginState {} | @@ -16,8 +16,13 @@ class SmsSendTypeChangeState extends LoginState {} | ||
16 | 16 | ||
17 | ///是否同意协议 | 17 | ///是否同意协议 |
18 | class AgreementTypeChangeState extends LoginState {} | 18 | class AgreementTypeChangeState extends LoginState {} |
19 | + | ||
19 | ///获取验证码 | 20 | ///获取验证码 |
20 | -class SmsCodeRequestState extends LoginState {} | 21 | +class SmsCodeRequestState extends LoginState {} |
21 | 22 | ||
22 | ///登陆请求结果 | 23 | ///登陆请求结果 |
23 | -class LoginResultChangeState extends LoginState {} | 24 | +class LoginResultChangeState extends LoginState { |
25 | + final UserEntity userEntity; | ||
26 | + | ||
27 | + LoginResultChangeState(this.userEntity); | ||
28 | +} |
lib/pages/login/loginpage/login_page.dart
@@ -25,169 +25,139 @@ class LoginPage extends StatelessWidget { | @@ -25,169 +25,139 @@ class LoginPage extends StatelessWidget { | ||
25 | class _LoginPageView extends StatelessWidget { | 25 | class _LoginPageView extends StatelessWidget { |
26 | @override | 26 | @override |
27 | Widget build(BuildContext context) { | 27 | Widget build(BuildContext context) { |
28 | - return BlocListener<LoginBloc,LoginState>( | ||
29 | - listener: (context, state){ | ||
30 | - if (state is LoginResultChangeState) { | ||
31 | - Navigator.of(context).pushNamed(AppRouteName.home); | ||
32 | - } | ||
33 | - context.read<CacheBloc>().add(UserInfoChangeEvent(null)); | ||
34 | - }, | 28 | + return BlocListener<LoginBloc, LoginState>( |
29 | + listener: (context, state) { | ||
30 | + if (state is LoginResultChangeState) { | ||
31 | + context.read<CacheBloc>().add(UserInfoChangeEvent(state.userEntity)); | ||
32 | + Navigator.of(context).pushNamed(AppRouteName.home); | ||
33 | + } | ||
34 | + }, | ||
35 | child: _buildLoginViewWidget(), | 35 | child: _buildLoginViewWidget(), |
36 | ); | 36 | ); |
37 | } | 37 | } |
38 | 38 | ||
39 | - Widget _buildLoginViewWidget() => BlocBuilder<LoginBloc,LoginState> ( | ||
40 | - builder: (context, state) { | ||
41 | - final bloc = BlocProvider.of<LoginBloc>(context); | ||
42 | - return Scaffold( | ||
43 | - body: SafeArea( | ||
44 | - child: ListView( | ||
45 | - children: [ | ||
46 | - Container( | ||
47 | - padding: EdgeInsets.only(top: 25.h), | ||
48 | - child: Stack( | ||
49 | - children: [ | ||
50 | - Positioned( | ||
51 | - right: 29.w, | ||
52 | - child: GestureDetector( | ||
53 | - onTap: () => bloc.add(ChangeLoginTypeEvent()), | ||
54 | - child: Container( | ||
55 | - decoration: BoxDecoration( | ||
56 | - image: DecorationImage( | ||
57 | - image: AssetImage( | ||
58 | - 'login_logo'.assetPng | ||
59 | - ), | ||
60 | - fit: BoxFit.fill | ||
61 | - ), | ||
62 | - ), | ||
63 | - padding: EdgeInsets.symmetric(horizontal: 18.w,vertical: 5.h), | ||
64 | - child: Text( | ||
65 | - bloc.isSmsLoginType?'密码登陆':'验证码密码', | ||
66 | - style: TextStyle( | ||
67 | - fontSize: 16.sp | 39 | + Widget _buildLoginViewWidget() => BlocBuilder<LoginBloc, LoginState>( |
40 | + builder: (context, state) { | ||
41 | + final bloc = BlocProvider.of<LoginBloc>(context); | ||
42 | + return Scaffold( | ||
43 | + body: SafeArea( | ||
44 | + child: ListView( | ||
45 | + children: [ | ||
46 | + Container( | ||
47 | + padding: EdgeInsets.only(top: 25.h), | ||
48 | + child: Stack( | ||
49 | + children: [ | ||
50 | + Positioned( | ||
51 | + right: 29.w, | ||
52 | + child: GestureDetector( | ||
53 | + onTap: () => bloc.add(ChangeLoginTypeEvent()), | ||
54 | + child: Container( | ||
55 | + decoration: BoxDecoration( | ||
56 | + image: DecorationImage(image: AssetImage('login_logo'.assetPng), fit: BoxFit.fill), | ||
57 | + ), | ||
58 | + padding: EdgeInsets.symmetric(horizontal: 18.w, vertical: 5.h), | ||
59 | + child: Text( | ||
60 | + bloc.isSmsLoginType ? '密码登陆' : '验证码密码', | ||
61 | + style: TextStyle(fontSize: 16.sp), | ||
62 | + ), | ||
68 | ), | 63 | ), |
69 | - ), | ||
70 | - ), | ||
71 | - ) | ||
72 | - ), | ||
73 | - Center( | ||
74 | - child: Column( | ||
75 | - children: [ | ||
76 | - Image.asset( | ||
77 | - 'wow_logo'.assetPng, | ||
78 | - height: 81.h, | ||
79 | - width: 131.w, | ||
80 | - ), | ||
81 | - Offstage( | ||
82 | - offstage: !bloc.isSmsLoginType, | ||
83 | - child: _buildSmsViewWidget(), | ||
84 | - ), | ||
85 | - Offstage( | ||
86 | - offstage: bloc.isSmsLoginType, | ||
87 | - child: _buildPwdViewWidget(), | ||
88 | - ), | ||
89 | - Row( | ||
90 | - mainAxisAlignment: MainAxisAlignment.center, | 64 | + )), |
65 | + Center( | ||
66 | + child: Column( | ||
91 | children: [ | 67 | children: [ |
92 | - GestureDetector( | ||
93 | - onTap: () => bloc.add(AgreementChangeEvent()), | ||
94 | - child: Icon( | ||
95 | - bloc.agreement ? Icons.check_circle_outlined:Icons.circle_outlined, | ||
96 | - color:bloc.agreement ? Colors.green:Colors.black), | 68 | + Image.asset( |
69 | + 'wow_logo'.assetPng, | ||
70 | + height: 81.h, | ||
71 | + width: 131.w, | ||
72 | + ), | ||
73 | + Offstage( | ||
74 | + offstage: !bloc.isSmsLoginType, | ||
75 | + child: _buildSmsViewWidget(), | ||
97 | ), | 76 | ), |
98 | - 6.horizontalSpace, | ||
99 | - RichText( | ||
100 | - text: TextSpan( | ||
101 | - children:[ | 77 | + Offstage( |
78 | + offstage: bloc.isSmsLoginType, | ||
79 | + child: _buildPwdViewWidget(), | ||
80 | + ), | ||
81 | + Row( | ||
82 | + mainAxisAlignment: MainAxisAlignment.center, | ||
83 | + children: [ | ||
84 | + GestureDetector( | ||
85 | + onTap: () => bloc.add(AgreementChangeEvent()), | ||
86 | + child: Icon(bloc.agreement ? Icons.check_circle_outlined : Icons.circle_outlined, | ||
87 | + color: bloc.agreement ? Colors.green : Colors.black), | ||
88 | + ), | ||
89 | + 6.horizontalSpace, | ||
90 | + RichText( | ||
91 | + text: TextSpan(children: [ | ||
102 | TextSpan( | 92 | TextSpan( |
103 | text: '我已阅读并同意', | 93 | text: '我已阅读并同意', |
104 | style: TextStyle( | 94 | style: TextStyle( |
105 | fontSize: 12.sp, | 95 | fontSize: 12.sp, |
106 | color: const Color(0xFF333333), | 96 | color: const Color(0xFF333333), |
107 | - ) | ||
108 | - ), | 97 | + )), |
109 | TextSpan( | 98 | TextSpan( |
110 | text: '《用户隐私协议》', | 99 | text: '《用户隐私协议》', |
111 | style: TextStyle( | 100 | style: TextStyle( |
112 | fontSize: 12.sp, | 101 | fontSize: 12.sp, |
113 | color: const Color(0xFF333333), | 102 | color: const Color(0xFF333333), |
114 | ), | 103 | ), |
115 | - recognizer: TapGestureRecognizer()..onTap = (){ | ||
116 | - Navigator.of(context).pushNamed( | ||
117 | - AppRouteName.webView, | ||
118 | - arguments: { | ||
119 | - 'urlStr':'https://www.zhihu.com', | ||
120 | - 'webViewTitle':'用户隐私协议' | ||
121 | - }); | ||
122 | - }), | ||
123 | - TextSpan( | ||
124 | - text: ',', | ||
125 | - style: TextStyle( | ||
126 | - fontSize: 12.sp, | ||
127 | - color: const Color(0xFF333333) | ||
128 | - ) | ||
129 | - ), | 104 | + recognizer: TapGestureRecognizer() |
105 | + ..onTap = () { | ||
106 | + Navigator.of(context).pushNamed(AppRouteName.webView, arguments: { | ||
107 | + 'urlStr': 'https://www.zhihu.com', | ||
108 | + 'webViewTitle': '用户隐私协议' | ||
109 | + }); | ||
110 | + }), | ||
111 | + TextSpan( | ||
112 | + text: ',', style: TextStyle(fontSize: 12.sp, color: const Color(0xFF333333))), | ||
130 | TextSpan( | 113 | TextSpan( |
131 | text: '《儿童隐私政策》', | 114 | text: '《儿童隐私政策》', |
132 | - style: TextStyle( | ||
133 | - fontSize: 12.sp, | ||
134 | - color: const Color(0xFF333333) | ||
135 | - ), | ||
136 | - recognizer: TapGestureRecognizer()..onTap = (){ | ||
137 | - Navigator.of(context).pushNamed( | ||
138 | - AppRouteName.webView, | ||
139 | - arguments: { | ||
140 | - 'urlStr':'https://www.zhihu.com', | ||
141 | - 'webViewTitle':'儿童隐私协议' | ||
142 | - }); | ||
143 | - }) | ||
144 | - ] | 115 | + style: TextStyle(fontSize: 12.sp, color: const Color(0xFF333333)), |
116 | + recognizer: TapGestureRecognizer() | ||
117 | + ..onTap = () { | ||
118 | + Navigator.of(context).pushNamed(AppRouteName.webView, arguments: { | ||
119 | + 'urlStr': 'https://www.zhihu.com', | ||
120 | + 'webViewTitle': '儿童隐私协议' | ||
121 | + }); | ||
122 | + }) | ||
123 | + ]), | ||
124 | + ) | ||
125 | + ], | ||
126 | + ), | ||
127 | + GestureDetector( | ||
128 | + onTap: () { | ||
129 | + if (bloc.canLogin) { | ||
130 | + bloc.add(RequestLoginEvent()); | ||
131 | + } | ||
132 | + }, | ||
133 | + child: Container( | ||
134 | + decoration: BoxDecoration( | ||
135 | + image: DecorationImage( | ||
136 | + image: AssetImage( | ||
137 | + bloc.canLogin ? 'login_enter'.assetPng : 'login_enter_dis'.assetPng), | ||
138 | + fit: BoxFit.fill), | ||
139 | + ), | ||
140 | + padding: EdgeInsets.symmetric(horizontal: 28.w, vertical: 14.h), | ||
141 | + child: Text( | ||
142 | + '登录', | ||
143 | + style: TextStyle(fontSize: 16.sp), | ||
144 | + ), | ||
145 | ), | 145 | ), |
146 | ) | 146 | ) |
147 | ], | 147 | ], |
148 | ), | 148 | ), |
149 | - GestureDetector( | ||
150 | - onTap: () { | ||
151 | - if (bloc.canLogin) { | ||
152 | - bloc.add(RequestLoginEvent()); | ||
153 | - } | ||
154 | - }, | ||
155 | - child: Container( | ||
156 | - decoration: BoxDecoration( | ||
157 | - image: DecorationImage( | ||
158 | - image: AssetImage( | ||
159 | - bloc.canLogin?'login_enter'.assetPng:'login_enter_dis'.assetPng | ||
160 | - ), | ||
161 | - fit: BoxFit.fill | ||
162 | - ), | ||
163 | - ), | ||
164 | - padding: EdgeInsets.symmetric( | ||
165 | - horizontal: 28.w, | ||
166 | - vertical: 14.h | ||
167 | - ), | ||
168 | - child: Text( | ||
169 | - '登录', | ||
170 | - style: TextStyle( | ||
171 | - fontSize: 16.sp | ||
172 | - ), | ||
173 | - ), | ||
174 | - ), | ||
175 | - ) | ||
176 | - ], | ||
177 | - ), | ||
178 | - ) | ||
179 | - ], | ||
180 | - ), | ||
181 | - ) | ||
182 | - ], | ||
183 | - ), | ||
184 | - ), | 149 | + ) |
150 | + ], | ||
151 | + ), | ||
152 | + ) | ||
153 | + ], | ||
154 | + ), | ||
155 | + ), | ||
156 | + ); | ||
157 | + }, | ||
185 | ); | 158 | ); |
186 | - }, | ||
187 | - ); | ||
188 | 159 | ||
189 | - Widget _buildSmsViewWidget()=> BlocBuilder<LoginBloc,LoginState>( | ||
190 | - builder: (context,state) { | 160 | + Widget _buildSmsViewWidget() => BlocBuilder<LoginBloc, LoginState>(builder: (context, state) { |
191 | final bloc = BlocProvider.of<LoginBloc>(context); | 161 | final bloc = BlocProvider.of<LoginBloc>(context); |
192 | return Padding( | 162 | return Padding( |
193 | padding: EdgeInsets.symmetric(horizontal: 135.w), | 163 | padding: EdgeInsets.symmetric(horizontal: 135.w), |
@@ -205,27 +175,25 @@ class _LoginPageView extends StatelessWidget { | @@ -205,27 +175,25 @@ class _LoginPageView extends StatelessWidget { | ||
205 | controller: bloc.phoneNumController, | 175 | controller: bloc.phoneNumController, |
206 | ), | 176 | ), |
207 | 6.5.verticalSpace, | 177 | 6.5.verticalSpace, |
208 | - Text('未注册用户登录默认注册', | ||
209 | - style: TextStyle( | ||
210 | - fontSize: 12.sp, | ||
211 | - color: const Color(0xFF999999) | ||
212 | - ),), | 178 | + Text( |
179 | + '未注册用户登录默认注册', | ||
180 | + style: TextStyle(fontSize: 12.sp, color: const Color(0xFF999999)), | ||
181 | + ), | ||
213 | 4.5.verticalSpace, | 182 | 4.5.verticalSpace, |
214 | Row( | 183 | Row( |
215 | mainAxisAlignment: MainAxisAlignment.spaceBetween, | 184 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
216 | children: [ | 185 | children: [ |
217 | Expanded( | 186 | Expanded( |
218 | child: TextFieldCustomerWidget( | 187 | child: TextFieldCustomerWidget( |
219 | - height: 50.h, | ||
220 | - hitText: '请输入验证码', | ||
221 | - textInputType: TextInputType.number, | ||
222 | - bgImageName: 'Input_layer_down', | ||
223 | - onChangeValue: (String value) { | ||
224 | - bloc.add(CheckFieldChangeEvent()); | ||
225 | - }, | ||
226 | - controller: bloc.checkNumController, | ||
227 | - ) | ||
228 | - ), | 188 | + height: 50.h, |
189 | + hitText: '请输入验证码', | ||
190 | + textInputType: TextInputType.number, | ||
191 | + bgImageName: 'Input_layer_down', | ||
192 | + onChangeValue: (String value) { | ||
193 | + bloc.add(CheckFieldChangeEvent()); | ||
194 | + }, | ||
195 | + controller: bloc.checkNumController, | ||
196 | + )), | ||
229 | TimerWidget(canSendSms: bloc.canSendSms) | 197 | TimerWidget(canSendSms: bloc.canSendSms) |
230 | ], | 198 | ], |
231 | ) | 199 | ) |
@@ -234,8 +202,7 @@ class _LoginPageView extends StatelessWidget { | @@ -234,8 +202,7 @@ class _LoginPageView extends StatelessWidget { | ||
234 | ); | 202 | ); |
235 | }); | 203 | }); |
236 | 204 | ||
237 | - Widget _buildPwdViewWidget()=> BlocBuilder<LoginBloc,LoginState>( | ||
238 | - builder: (context,state){ | 205 | + Widget _buildPwdViewWidget() => BlocBuilder<LoginBloc, LoginState>(builder: (context, state) { |
239 | final bloc = BlocProvider.of<LoginBloc>(context); | 206 | final bloc = BlocProvider.of<LoginBloc>(context); |
240 | return Padding( | 207 | return Padding( |
241 | padding: EdgeInsets.symmetric(horizontal: 90.w), | 208 | padding: EdgeInsets.symmetric(horizontal: 90.w), |
@@ -253,16 +220,15 @@ class _LoginPageView extends StatelessWidget { | @@ -253,16 +220,15 @@ class _LoginPageView extends StatelessWidget { | ||
253 | 10.5.horizontalSpace, | 220 | 10.5.horizontalSpace, |
254 | Expanded( | 221 | Expanded( |
255 | child: TextFieldCustomerWidget( | 222 | child: TextFieldCustomerWidget( |
256 | - height: 50.h, | ||
257 | - hitText: '请输入手机号', | ||
258 | - textInputType: TextInputType.phone, | ||
259 | - bgImageName: 'Input_layer_up', | ||
260 | - onChangeValue: (String value) { | ||
261 | - bloc.add(PhoneNumChangeEvent()); | ||
262 | - }, | ||
263 | - controller: bloc.phoneNumController, | ||
264 | - ) | ||
265 | - ), | 223 | + height: 50.h, |
224 | + hitText: '请输入手机号', | ||
225 | + textInputType: TextInputType.phone, | ||
226 | + bgImageName: 'Input_layer_up', | ||
227 | + onChangeValue: (String value) { | ||
228 | + bloc.add(PhoneNumChangeEvent()); | ||
229 | + }, | ||
230 | + controller: bloc.phoneNumController, | ||
231 | + )), | ||
266 | 5.horizontalSpace, | 232 | 5.horizontalSpace, |
267 | SizedBox( | 233 | SizedBox( |
268 | width: 100.w, | 234 | width: 100.w, |
@@ -282,14 +248,13 @@ class _LoginPageView extends StatelessWidget { | @@ -282,14 +248,13 @@ class _LoginPageView extends StatelessWidget { | ||
282 | 10.5.horizontalSpace, | 248 | 10.5.horizontalSpace, |
283 | Expanded( | 249 | Expanded( |
284 | child: TextFieldCustomerWidget( | 250 | child: TextFieldCustomerWidget( |
285 | - hitText: '请输入密码', | ||
286 | - bgImageName: 'Input_layer_down', | ||
287 | - onChangeValue: (String value) { | ||
288 | - bloc.add(CheckFieldChangeEvent()); | ||
289 | - }, | ||
290 | - controller: bloc.checkNumController, | ||
291 | - ) | ||
292 | - ), | 251 | + hitText: '请输入密码', |
252 | + bgImageName: 'Input_layer_down', | ||
253 | + onChangeValue: (String value) { | ||
254 | + bloc.add(CheckFieldChangeEvent()); | ||
255 | + }, | ||
256 | + controller: bloc.checkNumController, | ||
257 | + )), | ||
293 | 5.horizontalSpace, | 258 | 5.horizontalSpace, |
294 | GestureDetector( | 259 | GestureDetector( |
295 | onTap: () { | 260 | onTap: () { |
@@ -301,9 +266,7 @@ class _LoginPageView extends StatelessWidget { | @@ -301,9 +266,7 @@ class _LoginPageView extends StatelessWidget { | ||
301 | alignment: Alignment.centerLeft, | 266 | alignment: Alignment.centerLeft, |
302 | child: Text( | 267 | child: Text( |
303 | '忘记密码 ?', | 268 | '忘记密码 ?', |
304 | - style: TextStyle( | ||
305 | - fontSize: 12.sp | ||
306 | - ), | 269 | + style: TextStyle(fontSize: 12.sp), |
307 | ), | 270 | ), |
308 | ), | 271 | ), |
309 | ) | 272 | ) |
lib/utils/loading.dart
1 | import 'package:flutter_easyloading/flutter_easyloading.dart'; | 1 | import 'package:flutter_easyloading/flutter_easyloading.dart'; |
2 | 2 | ||
3 | -Future loading(Function block, {bool isShowLoading = true}) async { | ||
4 | - if (isShowLoading) { | ||
5 | - showLoading(); | 3 | +Future<T?> loading<T>(Function block, {String loadingText = '加载中...'}) async { |
4 | + if (loadingText.isNotEmpty) { | ||
5 | + showLoading(loadingText); | ||
6 | } | 6 | } |
7 | try { | 7 | try { |
8 | - await block(); | 8 | + return await block(); |
9 | } catch (e) { | 9 | } catch (e) { |
10 | rethrow; | 10 | rethrow; |
11 | } finally { | 11 | } finally { |
12 | dismissLoading(); | 12 | dismissLoading(); |
13 | } | 13 | } |
14 | - return; | ||
15 | } | 14 | } |
16 | 15 | ||
17 | -void showLoading() { | ||
18 | - EasyLoading.show(status: "加载中..."); | 16 | +void showLoading(String text) { |
17 | + EasyLoading.show(status: text); | ||
19 | } | 18 | } |
20 | 19 | ||
21 | void dismissLoading() { | 20 | void dismissLoading() { |