Skip to content

Commit

Permalink
fix: Flutter analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
SyifaAinnur committed Sep 9, 2024
1 parent f9bcf97 commit 483b1ea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
80 changes: 40 additions & 40 deletions lib/src/models/api_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,6 @@ class ApiResponse {
required this.clientLibrary,
});

/// Convert JSON to [ApiResponse]
factory ApiResponse.fromJson(Map<String, dynamic> 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<String, String>
static Map<String, String> _parseMap(dynamic jsonString) {
if (jsonString is String && jsonString.isNotEmpty && jsonString != '{}') {
try {
final parsed = jsonDecode(jsonString) as Map<String, dynamic>;
return parsed.map((key, value) => MapEntry(key, value.toString()));
} catch (e) {
debugPrint('Failed to parse JSON: $e');
return {};
}
} else if (jsonString is Map<String, dynamic>) {
return jsonString.map((key, value) => MapEntry(key, value.toString()));
} else {
return {};
}
}

/// Helper function to parse JSON strings into a Map<String, String>
// static Map<String, String> _parseMap(String jsonString) {
// if (jsonString.isEmpty || jsonString == '{}') {
Expand Down Expand Up @@ -112,6 +72,46 @@ class ApiResponse {
clientLibrary: '',
);

/// Convert JSON to [ApiResponse]
factory ApiResponse.fromJson(Map<String, dynamic> 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<String, String>
static Map<String, String> _parseMap(dynamic jsonString) {
if (jsonString is String && jsonString.isNotEmpty && jsonString != '{}') {
try {
final parsed = jsonDecode(jsonString) as Map<String, dynamic>;
return parsed.map((key, value) => MapEntry(key, value.toString()));
} catch (e) {
debugPrint('Failed to parse JSON: $e');
return {};
}
} else if (jsonString is Map<String, dynamic>) {
return jsonString.map((key, value) => MapEntry(key, value.toString()));
} else {
return {};
}
}

/// DateTime when request is sent
final DateTime requestTime;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/tabs/overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 483b1ea

Please sign in to comment.