fix product search/filter

This commit is contained in:
Phuoc Nguyen
2025-11-19 15:48:51 +07:00
parent 03a7b7940a
commit 841d77d886
19 changed files with 638 additions and 142 deletions

View File

@@ -572,7 +572,7 @@ LoggingInterceptor loggingInterceptor(Ref ref) {
const bool isDebug = true; // TODO: Replace with kDebugMode from Flutter
return LoggingInterceptor(
enableRequestLogging: isDebug,
enableRequestLogging: false,
enableResponseLogging: isDebug,
enableErrorLogging: isDebug,
);

View File

@@ -189,7 +189,7 @@ final class LoggingInterceptorProvider
}
String _$loggingInterceptorHash() =>
r'f3dedaeb3152d5188544232f6f270bb6908c2827';
r'6afa480caa6fcd723dab769bb01601b8a37e20fd';
/// Provider for ErrorTransformerInterceptor

View File

@@ -8,7 +8,8 @@
/// - Retry logic
library;
import 'package:curl_logger_dio_interceptor/curl_logger_dio_interceptor.dart';
import 'dart:developer' as developer;
import 'package:dio/dio.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart';
@@ -238,6 +239,87 @@ class DioClient {
}
}
// ============================================================================
// Custom Curl Logger Interceptor
// ============================================================================
/// Custom Curl Logger that uses debugPrint instead of print
class CustomCurlLoggerInterceptor extends Interceptor {
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final curl = _cURLRepresentation(options);
// debugPrint(
// '╔╣ CURL Request ╠══════════════════════════════════════════════════',
// );
// debugPrint(curl);
// debugPrint(
// '╚═════════════════════════════════════════════════════════════════',
// );
// Also log to dart:developer for better filtering in DevTools
developer.log(curl, name: 'DIO_CURL', time: DateTime.now());
handler.next(options);
}
String _cURLRepresentation(RequestOptions options) {
final components = ['curl --location'];
// Add method
if (options.method.toUpperCase() != 'GET') {
components.add('-X ${options.method}');
}
// Add headers (INCLUDING Cookie this time!)
options.headers.forEach((key, value) {
// Escape single quotes in header values
final escapedValue = value.toString().replaceAll("'", "'\\''");
components.add("--header '$key: $escapedValue'");
});
// Add data with proper JSON formatting
if (options.data != null) {
if (options.data is FormData) {
components.add('--data-binary [FormData]');
} else {
// Convert data to proper JSON string
String jsonData;
if (options.data is Map || options.data is List) {
// Use dart:convert to properly encode JSON
jsonData = _jsonEncode(options.data);
} else {
jsonData = options.data.toString();
}
// Escape single quotes for shell
final escapedData = jsonData.replaceAll("'", "'\\''");
components.add("--data '$escapedData'");
}
}
// Add URL
final uri = options.uri.toString();
components.add("'$uri'");
return components.join(' \\\n');
}
/// Simple JSON encoder (without importing dart:convert in this file)
String _jsonEncode(dynamic data) {
if (data == null) return 'null';
if (data is String) return '"${data.replaceAll('"', r'\"')}"';
if (data is num || data is bool) return data.toString();
if (data is List) {
final items = data.map((e) => _jsonEncode(e)).join(',');
return '[$items]';
}
if (data is Map) {
final pairs = data.entries
.map((e) => '"${e.key}":${_jsonEncode(e.value)}')
.join(',');
return '{$pairs}';
}
return data.toString();
}
}
// ============================================================================
// Retry Interceptor
// ============================================================================
@@ -383,8 +465,9 @@ Future<Dio> dio(Ref ref) async {
},
)
// Add interceptors in order
// 1. Curl interceptor (first to log cURL commands)
..interceptors.add(CurlLoggerDioInterceptor())
// 1. Custom Curl interceptor (first to log cURL commands)
// Uses debugPrint and developer.log for better visibility
..interceptors.add(CustomCurlLoggerInterceptor())
// 2. Logging interceptor
..interceptors.add(ref.watch(loggingInterceptorProvider))
// 3. Auth interceptor (add tokens to requests)

View File

@@ -131,7 +131,7 @@ final class DioProvider
}
}
String _$dioHash() => r'40bb4b1008c8259c9db4b19bcee674aa6732810c';
String _$dioHash() => r'd15bfe824d6501e5cbd56ff152de978030d97be4';
/// Provider for DioClient