Commit 8de2f9cb by tanghuan

网络请求异常捕获处理

1 parent bd25deab
......@@ -98,6 +98,10 @@ class LoginPhoneCubit extends Cubit<LoginPhoneState> {
// 发送验证码
var result = await _phoneAuthRepository.verifyCode(phone, 1);
if (result == null) {
Fluttertoast.showToast(msg: '发送请求失败', gravity: ToastGravity.TOP, backgroundColor: Colors.red);
return;
}
if (result['code'] != 0) {
Fluttertoast.showToast(msg: result['error'], gravity: ToastGravity.TOP, backgroundColor: Colors.red);
return;
......
import 'dart:io';
import 'package:appframe/config/locator.dart';
import 'package:appframe/services/api_service.dart';
import 'package:dio/dio.dart';
......@@ -22,13 +24,17 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> bindCheck(String userid) async {
try {
Response resp = await _appService.get(
'/api/v1/comm/phone/bind/check',
queryParameters: {
"userid": userid,
},
);
return resp.data;
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -38,6 +44,7 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> bind(String userid, String phone, String verifyCode) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/bind',
{
......@@ -46,7 +53,10 @@ class PhoneAuthRepository {
"verifyCode": verifyCode,
},
);
return resp.data;
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -59,6 +69,7 @@ class PhoneAuthRepository {
/// type=0 验证码登陆下发
///
Future<dynamic> verifyCode(String phone, int type) async {
try {
Response resp = await _appService.get(
'/api/v1/comm/phone/verifycode',
queryParameters: {
......@@ -66,7 +77,10 @@ class PhoneAuthRepository {
"type": type,
},
);
return resp.data;
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -77,6 +91,7 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> login(String phone, String verifyCode) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/loginv2',
{
......@@ -84,7 +99,10 @@ class PhoneAuthRepository {
"verifyCode": verifyCode,
},
);
return resp.statusCode == 200 ? resp.data : null;
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -94,22 +112,30 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> unbind(String userid) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/unbind',
{
"userid": userid,
},
);
return resp.data;
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
Future<dynamic> unbindPhone(String phone) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/unbind',
{
"phone": phone,
},
);
return resp.data;
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}
import 'dart:io';
import 'package:appframe/config/locator.dart';
import 'package:appframe/services/api_service.dart';
import 'package:dio/dio.dart';
......@@ -10,6 +12,7 @@ class SubsRepository {
}
Future<dynamic> userGroups(String type, String userid, String classCode) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/subs/usergroups',
{
......@@ -18,6 +21,9 @@ class SubsRepository {
"classCode": classCode,
},
);
return resp.data;
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}
......@@ -18,6 +18,7 @@ class UserAuthRepository {
/// }
///
Future<dynamic> updateUser(String userid, String name, String nickName, String avatar) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/update',
{
......@@ -28,9 +29,13 @@ class UserAuthRepository {
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
Future<dynamic> appleLogin(String userid, String authorizationCode, String identityToken) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/applelogin',
{
......@@ -40,6 +45,9 @@ class UserAuthRepository {
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -49,6 +57,7 @@ class UserAuthRepository {
/// "error": "",
/// }
Future<dynamic> exchangeId(String userid) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/exchangeid',
{
......@@ -57,6 +66,9 @@ class UserAuthRepository {
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -65,6 +77,7 @@ class UserAuthRepository {
/// "code": 0,
/// }
Future<dynamic> newBinding(String userid, String bxeUserId, String type) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/newbinding',
{
......@@ -74,5 +87,8 @@ class UserAuthRepository {
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}
......@@ -13,6 +13,7 @@ class WechatAuthRepository {
}
Future<dynamic> codeToSk(String code) async {
try {
Response resp = await _apiService.post(
'/login/applet/wkbxe/codeToSkByApp?version=1.0.0',
{
......@@ -24,9 +25,14 @@ class WechatAuthRepository {
debugPrint('登录结果: $resp');
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException catch (e) {
debugPrint('codeToSk网络异常: $e');
return null;
}
}
Future<dynamic> getTicket() async {
try {
Response resp = await _apiService.post(
'/login/applet/wkbxe/getTicketByApp?version=1.0.0',
{
......@@ -38,5 +44,9 @@ class WechatAuthRepository {
debugPrint('获取ticket: $resp');
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException catch (e) {
debugPrint('getTicket网络异常: $e');
return null;
}
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!