- Replace decommissioned llama-3.2-11b-vision-preview with meta-llama/llama-4-scout-17b-16e-instruct (Groq deprecation) - Use XFile.readAsBytes() instead of File(path).readAsBytes() so Android content URIs (from gallery picks) are read correctly - Add maxWidth/maxHeight constraints to image picker calls to reduce payload size - Increase receiveTimeout from 30s to 120s to accommodate slow vision AI - Log recognition errors via debugPrint instead of swallowing them Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
58 lines
1.7 KiB
Dart
58 lines
1.7 KiB
Dart
import 'package:dio/dio.dart';
|
|
import '../auth/secure_storage.dart';
|
|
import 'auth_interceptor.dart';
|
|
|
|
class ApiClient {
|
|
late final Dio _dio;
|
|
|
|
ApiClient({required String baseUrl, required SecureStorageService storage}) {
|
|
_dio = Dio(BaseOptions(
|
|
baseUrl: baseUrl,
|
|
connectTimeout: const Duration(seconds: 10),
|
|
receiveTimeout: const Duration(seconds: 120),
|
|
headers: {'Content-Type': 'application/json'},
|
|
));
|
|
|
|
_dio.interceptors.addAll([
|
|
AuthInterceptor(storage: storage, dio: _dio),
|
|
LogInterceptor(requestBody: true, responseBody: true),
|
|
]);
|
|
}
|
|
|
|
/// Exposed for testing only.
|
|
ApiClient.withDio(this._dio);
|
|
|
|
Future<Map<String, dynamic>> get(String path,
|
|
{Map<String, dynamic>? params}) async {
|
|
final response = await _dio.get(path, queryParameters: params);
|
|
return response.data;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> post(String path, {dynamic data}) async {
|
|
final response = await _dio.post(path, data: data);
|
|
return response.data;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> put(String path, {dynamic data}) async {
|
|
final response = await _dio.put(path, data: data);
|
|
return response.data;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> delete(String path) async {
|
|
final response = await _dio.delete(path);
|
|
return response.data;
|
|
}
|
|
|
|
/// Returns a list for endpoints that respond with a JSON array.
|
|
Future<List<dynamic>> getList(String path,
|
|
{Map<String, dynamic>? params}) async {
|
|
final response = await _dio.get(path, queryParameters: params);
|
|
return response.data as List<dynamic>;
|
|
}
|
|
|
|
/// Deletes a resource and expects no response body (204 No Content).
|
|
Future<void> deleteVoid(String path) async {
|
|
await _dio.delete(path);
|
|
}
|
|
}
|