fix : dio call
This commit is contained in:
@@ -34,13 +34,15 @@ class AuthRepositoryImpl implements AuthRepository {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CaptchaResponseModel?> captcha() async {
|
Future<CaptchaResponseModel?> captcha() async {
|
||||||
final response = await safeCall(
|
final response = await safeCall<CaptchaResponseModel?>(
|
||||||
call:
|
call: () async {
|
||||||
() async => await _httpClient.post<CaptchaResponseModel>(
|
var res = await _httpClient.post<CaptchaResponseModel?>(
|
||||||
'captcha/',
|
'captcha/',
|
||||||
headers: {'Content-Type': 'application/json'},
|
fromJson: CaptchaResponseModel.fromJson,
|
||||||
fromJson: CaptchaResponseModel.fromJson
|
);
|
||||||
),
|
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
onSuccess: (response) {
|
onSuccess: (response) {
|
||||||
iLog(response);
|
iLog(response);
|
||||||
},
|
},
|
||||||
@@ -48,8 +50,7 @@ class AuthRepositoryImpl implements AuthRepository {
|
|||||||
throw Exception('Error during captcha : $error');
|
throw Exception('Error during captcha : $error');
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
return response;
|
||||||
return response?.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
38
packages/auth/lib/presentation/widget/captcha/logic.dart
Normal file
38
packages/auth/lib/presentation/widget/captcha/logic.dart
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:rasadyar_auth/data/di/auth_di.dart';
|
||||||
|
import 'package:rasadyar_auth/data/models/response/captcha/captcha_response_model.dart';
|
||||||
|
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
|
||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
|
class CaptchaWidgetLogic extends GetxController
|
||||||
|
with StateMixin<CaptchaResponseModel> {
|
||||||
|
TextEditingController textController = TextEditingController();
|
||||||
|
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||||
|
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
|
||||||
|
getCaptcha();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> getCaptcha() async {
|
||||||
|
change(null, status: RxStatus.loading());
|
||||||
|
safeCall(
|
||||||
|
call: () async => await authRepository.captcha(),
|
||||||
|
onSuccess: (value) {
|
||||||
|
change(value, status: RxStatus.success());
|
||||||
|
},
|
||||||
|
onError: (error, stackTrace) {
|
||||||
|
change(null, status: RxStatus.error(error.toString()));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
98
packages/auth/lib/presentation/widget/captcha/view.dart
Normal file
98
packages/auth/lib/presentation/widget/captcha/view.dart
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:rasadyar_auth/presentation/widget/clear_button.dart';
|
||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
|
import 'logic.dart';
|
||||||
|
|
||||||
|
class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
|
||||||
|
CaptchaWidget({super.key});
|
||||||
|
|
||||||
|
final CaptchaWidgetLogic logic = Get.put(CaptchaWidgetLogic());
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 135,
|
||||||
|
height: 48,
|
||||||
|
clipBehavior: Clip.antiAliasWithSaveLayer,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColor.whiteNormalHover,
|
||||||
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: Expanded(child:controller.obx((state) {
|
||||||
|
return Container(color: Colors.blue,);
|
||||||
|
},
|
||||||
|
onLoading: const Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: AppColor.blueNormal,
|
||||||
|
strokeWidth: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
IconButton(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: controller.getCaptcha,
|
||||||
|
icon: Icon(CupertinoIcons.refresh, size: 16),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Form(
|
||||||
|
key: controller.formKey,
|
||||||
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller.textController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
gapPadding: 11,
|
||||||
|
),
|
||||||
|
labelText: 'کد امنیتی',
|
||||||
|
labelStyle: AppFonts.yekan13,
|
||||||
|
errorStyle: AppFonts.yekan10.copyWith(
|
||||||
|
color: AppColor.redNormal,
|
||||||
|
fontSize: 8,
|
||||||
|
),
|
||||||
|
suffixIconConstraints: BoxConstraints(
|
||||||
|
maxHeight: 24,
|
||||||
|
minHeight: 24,
|
||||||
|
maxWidth: 24,
|
||||||
|
minWidth: 24,
|
||||||
|
),
|
||||||
|
suffix:
|
||||||
|
controller.textController.text
|
||||||
|
.trim()
|
||||||
|
.isNotEmpty
|
||||||
|
? clearButton(() => controller.textController.clear())
|
||||||
|
: null,
|
||||||
|
counterText: '',
|
||||||
|
),
|
||||||
|
keyboardType: TextInputType.numberWithOptions(
|
||||||
|
decimal: false,
|
||||||
|
signed: false,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
maxLength: 6,
|
||||||
|
onChanged: (value) {},
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'کد امنیتی را وارد کنید';
|
||||||
|
}
|
||||||
|
/*if (value != controller.captchaCode.toString()) {
|
||||||
|
return '⚠️کد امنیتی وارد شده اشتباه است';
|
||||||
|
}*/
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
style: AppFonts.yekan13,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
import 'package:rasadyar_core/infrastructure/remote/interfaces/i_form_data.dart';
|
import 'package:rasadyar_core/infrastructure/remote/interfaces/i_form_data.dart';
|
||||||
|
|
||||||
import 'dio_form_data.dart';
|
|
||||||
import 'dio_response.dart';
|
|
||||||
import 'interfaces/i_http_client.dart';
|
import 'interfaces/i_http_client.dart';
|
||||||
|
|
||||||
class DioRemote implements IHttpClient {
|
class DioRemote implements IHttpClient {
|
||||||
@@ -29,7 +28,7 @@ class DioRemote implements IHttpClient {
|
|||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
ProgressCallback? onReceiveProgress,
|
ProgressCallback? onReceiveProgress,
|
||||||
}) async {
|
}) async {
|
||||||
final response = await _dio.get<T>(
|
final response = await _dio.get(
|
||||||
path,
|
path,
|
||||||
queryParameters: queryParameters,
|
queryParameters: queryParameters,
|
||||||
options: Options(headers: headers),
|
options: Options(headers: headers),
|
||||||
@@ -48,7 +47,7 @@ class DioRemote implements IHttpClient {
|
|||||||
ProgressCallback? onSendProgress,
|
ProgressCallback? onSendProgress,
|
||||||
ProgressCallback? onReceiveProgress,
|
ProgressCallback? onReceiveProgress,
|
||||||
}) async {
|
}) async {
|
||||||
final response = await _dio.post<T>(
|
final response = await _dio.post(
|
||||||
path,
|
path,
|
||||||
data: data,
|
data: data,
|
||||||
queryParameters: queryParameters,
|
queryParameters: queryParameters,
|
||||||
@@ -57,6 +56,8 @@ class DioRemote implements IHttpClient {
|
|||||||
onReceiveProgress: onReceiveProgress,
|
onReceiveProgress: onReceiveProgress,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
eLog(response.toString());
|
||||||
|
|
||||||
if (fromJson != null) {
|
if (fromJson != null) {
|
||||||
final rawData = response.data;
|
final rawData = response.data;
|
||||||
final parsedData =
|
final parsedData =
|
||||||
@@ -77,7 +78,7 @@ class DioRemote implements IHttpClient {
|
|||||||
ProgressCallback? onSendProgress,
|
ProgressCallback? onSendProgress,
|
||||||
ProgressCallback? onReceiveProgress,
|
ProgressCallback? onReceiveProgress,
|
||||||
}) async {
|
}) async {
|
||||||
final response = await _dio.put<T>(
|
final response = await _dio.put(
|
||||||
path,
|
path,
|
||||||
data: data,
|
data: data,
|
||||||
queryParameters: queryParameters,
|
queryParameters: queryParameters,
|
||||||
@@ -124,7 +125,7 @@ class DioRemote implements IHttpClient {
|
|||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
ProgressCallback? onSendProgress,
|
ProgressCallback? onSendProgress,
|
||||||
}) async {
|
}) async {
|
||||||
final response = await _dio.post<T>(
|
final response = await _dio.post(
|
||||||
path,
|
path,
|
||||||
data: (formData as DioFormData).raw,
|
data: (formData as DioFormData).raw,
|
||||||
options: Options(headers: headers, contentType: 'multipart/form-data'),
|
options: Options(headers: headers, contentType: 'multipart/form-data'),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import 'interfaces/i_http_response.dart';
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
class DioResponse<T> implements IHttpResponse<T> {
|
class DioResponse<T> implements IHttpResponse<T> {
|
||||||
final Response<T> _response;
|
final Response<dynamic> _response;
|
||||||
|
|
||||||
DioResponse(this._response);
|
DioResponse(this._response);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
typedef AsyncCallback<T> = Future<T> Function();
|
typedef AsyncCallback<T> = Future<T> Function();
|
||||||
typedef ErrorCallback = void Function(dynamic error, StackTrace? stackTrace);
|
typedef ErrorCallback = void Function(dynamic error, StackTrace? stackTrace);
|
||||||
@@ -27,12 +28,14 @@ Future<T?> safeCall<T>({
|
|||||||
|
|
||||||
final result = await call();
|
final result = await call();
|
||||||
|
|
||||||
|
iLog(result.toString());
|
||||||
|
|
||||||
if (showSuccess) {
|
if (showSuccess) {
|
||||||
(onShowSuccessMessage ?? _defaultShowSuccessMessage)();
|
(onShowSuccessMessage ?? _defaultShowSuccessMessage)();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSuccess?.call(result);
|
onSuccess?.call(result);
|
||||||
return result; // اضافه کردن بازگشت نتیجه
|
return result;
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
if (showError) {
|
if (showError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user