completed group batch feature

This commit is contained in:
2026-06-08 09:17:36 +02:00
parent 2dd790fe6e
commit fc616d6316
46 changed files with 4610 additions and 2669 deletions

View File

@@ -1,3 +1,6 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:qpay/abstracts/AbstractController.dart';
@@ -19,7 +22,7 @@ class VerifyController extends AbstractController {
VerifyModel model = VerifyModel();
VerifyController(this.context){
VerifyController(this.context) {
onboardingController = Provider.of<OnboardingController>(
context,
listen: false,
@@ -31,9 +34,64 @@ class VerifyController extends AbstractController {
notifyListeners();
}
Future<ApiResponse<Map<String, dynamic>>> verifyOtp () async {
/// Extracts a human-readable error message from any exception thrown during
/// an HTTP call. Supports:
/// * [DioException] the response body, request body, and a top-level
/// `message` field are inspected.
/// * Dart [Exception] / [Error] whose stringified form is a JSON object
/// (e.g. `{state: failed, status: manual, body: {...}, message: ...}`).
/// * Any other throwable falls back to its `toString()`.
String _extractErrorMessage(Object error) {
try {
if (error is DioException) {
final data = error.response?.data;
if (data is Map) {
final message = data['message'];
if (message is String && message.isNotEmpty) return message;
}
if (data is String && data.isNotEmpty) {
final parsed = _tryParseJson(data);
if (parsed is Map) {
final message = parsed['message'];
if (message is String && message.isNotEmpty) return message;
}
return data;
}
if (error.type == DioExceptionType.connectionTimeout ||
error.type == DioExceptionType.receiveTimeout ||
error.type == DioExceptionType.sendTimeout) {
return 'The request timed out. Please check your connection and try again.';
}
if (error.type == DioExceptionType.connectionError) {
return 'No internet connection. Please check your network and try again.';
}
return error.message ?? 'Network error. Please try again.';
}
final raw = error.toString();
// The server sometimes throws a stringified JSON object as an exception.
final parsed = _tryParseJson(raw);
if (parsed is Map) {
final message = parsed['message'];
if (message is String && message.isNotEmpty) return message;
}
return raw;
} catch (_) {
return 'An unexpected error occurred. Please try again.';
}
}
dynamic _tryParseJson(String input) {
try {
return jsonDecode(input);
} catch (_) {
return null;
}
}
Future<ApiResponse<Map<String, dynamic>>> verifyOtp() async {
Map user = {
"username": onboardingController.model.googleUser?.email,
"username": onboardingController.model.email,
"otpCode": model.code,
"otpType": "REGISTRATION",
"workflowId": onboardingController.model.workflowId,
@@ -41,62 +99,61 @@ class VerifyController extends AbstractController {
try {
model.isLoading = true;
model.errorMessage = null;
notifyListeners();
Map response = await http.post(
'/auth/verify',
user
);
Map response = await http.post('/auth/verify', user);
model.status = response['state'];
model.isLoading = false;
notifyListeners();
if(response['state'] == 'failed') {
model.errorMessage = response['message'];
return ApiResponse.failure(response['message'] ?? "Verification failed");
if (response['state'] == 'failed') {
final message =
response['message']?.toString() ?? "Verification failed";
model.errorMessage = message;
return ApiResponse.failure(message);
}
return ApiResponse.success(Map<String, dynamic>.from(response));
} catch (e) {
logger.e(e);
final message = _extractErrorMessage(e);
model.errorMessage = message;
model.isLoading = false;
notifyListeners();
return ApiResponse.failure(
"Problem during registration, please try again or contact support?",
);
return ApiResponse.failure(message);
}
}
Future<ApiResponse<Map<String, dynamic>>> resendOtp () async {
Future<ApiResponse<Map<String, dynamic>>> resendOtp() async {
Map user = {
"username": onboardingController.model.googleUser?.email,
"username": onboardingController.model.email,
"phone": onboardingController.model.phone,
"workflowId": onboardingController.model.workflowId,
};
try {
model.isLoading = true;
model.errorMessage = null;
notifyListeners();
Map response = await http.post(
'/auth/resend',
user
);
Map response = await http.post('/auth/resend', user);
model.status = response['state'];
model.isLoading = false;
notifyListeners();
if(response['state'] == 'failed') {
model.errorMessage = response['message'];
return ApiResponse.failure(response['message'] ?? "Resend failed");
if (response['state'] == 'failed') {
final message = response['message']?.toString() ?? "Resend failed";
model.errorMessage = message;
return ApiResponse.failure(message);
}
return ApiResponse.success(Map<String, dynamic>.from(response));
} catch (e) {
logger.e(e);
final message = _extractErrorMessage(e);
model.errorMessage = message;
model.isLoading = false;
notifyListeners();
return ApiResponse.failure(
"Problem during registration, please try again or contact support?",
);
return ApiResponse.failure(message);
}
}
}
}