From 483b1eacff7366df202830753c9854af59f23e73 Mon Sep 17 00:00:00 2001 From: Siff Date: Mon, 9 Sep 2024 13:41:19 +0700 Subject: [PATCH] fix: Flutter analyze --- lib/src/models/api_response.dart | 80 ++++++++++++++++---------------- lib/src/view/tabs/overview.dart | 2 +- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/src/models/api_response.dart b/lib/src/models/api_response.dart index 52aeeda..187d1ad 100644 --- a/lib/src/models/api_response.dart +++ b/lib/src/models/api_response.dart @@ -28,46 +28,6 @@ class ApiResponse { required this.clientLibrary, }); - /// Convert JSON to [ApiResponse] - factory ApiResponse.fromJson(Map json) => ApiResponse( - body: json['body'] as dynamic, - baseUrl: json['baseUrl'] as String, - method: json['method'] as String, - statusCode: json['statusCode'] as int, - connectionTimeout: json['connectionTimeout'] as int, - contentType: json['contentType'] as String?, - headers: _parseMap(json['headers']), - queryParameters: _parseMap(json['queryParameters']), - receiveTimeout: json['receiveTimeout'] as int, - request: json['request'] as dynamic, - requestSize: (json['requestSize'] as num).toDouble(), - requestTime: DateTime.parse(json['requestTime'] as String), - responseSize: (json['responseSize'] as num).toDouble(), - responseTime: DateTime.parse(json['responseTime'] as String), - responseType: json['responseType'] as String, - sendTimeout: json['sendTimeout'] as int, - path: json['path'] as String, - checked: json['checked'] as bool? ?? false, - clientLibrary: (json['clientLibrary'] as String?) ?? 'N/A', - ); - - /// Helper function to parse JSON strings into a Map - static Map _parseMap(dynamic jsonString) { - if (jsonString is String && jsonString.isNotEmpty && jsonString != '{}') { - try { - final parsed = jsonDecode(jsonString) as Map; - return parsed.map((key, value) => MapEntry(key, value.toString())); - } catch (e) { - debugPrint('Failed to parse JSON: $e'); - return {}; - } - } else if (jsonString is Map) { - return jsonString.map((key, value) => MapEntry(key, value.toString())); - } else { - return {}; - } - } - /// Helper function to parse JSON strings into a Map // static Map _parseMap(String jsonString) { // if (jsonString.isEmpty || jsonString == '{}') { @@ -112,6 +72,46 @@ class ApiResponse { clientLibrary: '', ); + /// Convert JSON to [ApiResponse] + factory ApiResponse.fromJson(Map json) => ApiResponse( + body: json['body'] as dynamic, + baseUrl: json['baseUrl'] as String, + method: json['method'] as String, + statusCode: json['statusCode'] as int, + connectionTimeout: json['connectionTimeout'] as int, + contentType: json['contentType'] as String?, + headers: _parseMap(json['headers']), + queryParameters: _parseMap(json['queryParameters']), + receiveTimeout: json['receiveTimeout'] as int, + request: json['request'] as dynamic, + requestSize: (json['requestSize'] as num).toDouble(), + requestTime: DateTime.parse(json['requestTime'] as String), + responseSize: (json['responseSize'] as num).toDouble(), + responseTime: DateTime.parse(json['responseTime'] as String), + responseType: json['responseType'] as String, + sendTimeout: json['sendTimeout'] as int, + path: json['path'] as String, + checked: json['checked'] as bool? ?? false, + clientLibrary: (json['clientLibrary'] as String?) ?? 'N/A', + ); + + /// Helper function to parse JSON strings into a Map + static Map _parseMap(dynamic jsonString) { + if (jsonString is String && jsonString.isNotEmpty && jsonString != '{}') { + try { + final parsed = jsonDecode(jsonString) as Map; + return parsed.map((key, value) => MapEntry(key, value.toString())); + } catch (e) { + debugPrint('Failed to parse JSON: $e'); + return {}; + } + } else if (jsonString is Map) { + return jsonString.map((key, value) => MapEntry(key, value.toString())); + } else { + return {}; + } + } + /// DateTime when request is sent final DateTime requestTime; diff --git a/lib/src/view/tabs/overview.dart b/lib/src/view/tabs/overview.dart index a8a5dc4..825c556 100644 --- a/lib/src/view/tabs/overview.dart +++ b/lib/src/view/tabs/overview.dart @@ -73,7 +73,7 @@ class OverviewTabView extends StatelessWidget { value: api.responseTime.toString(), ), _dataRow(context, - attribute: 'Headers', value: api.headers.toString()), + attribute: 'Headers', value: api.headers.toString(),), _dataRow( context, attribute: 'Query Parameters',