Skip to content

Commit

Permalink
update: response type
Browse files Browse the repository at this point in the history
  • Loading branch information
SyifaAinnur committed Sep 9, 2024
1 parent c3d6446 commit f9bcf97
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
9 changes: 5 additions & 4 deletions lib/src/models/api_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class ApiResponse {
static Map<String, String> _parseMap(dynamic jsonString) {
if (jsonString is String && jsonString.isNotEmpty && jsonString != '{}') {
try {
final Map<String, dynamic> parsed =
jsonDecode(jsonString) as Map<String, dynamic>;
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');
Expand Down Expand Up @@ -223,7 +222,7 @@ class ApiResponse {
String? responseType,
int? receiveTimeout,
// String? queryParameters,
Map<String, dynamic>? queryParametersMap,
Map<String, dynamic>? queryParameters,
int? connectionTimeout,
bool? checked,
String? clientLibrary,
Expand All @@ -239,7 +238,7 @@ class ApiResponse {
// headers: headers ?? this.headers,
headers: headers ?? this.headers,
// queryParameters: queryParameters ?? this.queryParameters,
queryParameters: queryParametersMap ?? this.queryParameters,
queryParameters: queryParameters ?? this.queryParameters,
receiveTimeout: receiveTimeout ?? this.receiveTimeout,
request: request ?? this.request,
requestSize: requestSize ?? this.requestSize,
Expand Down Expand Up @@ -318,9 +317,11 @@ $prettyJson''';
// }

@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(Object other) =>
other is ApiResponse && other.requestTime == requestTime;

@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => requestTime.millisecondsSinceEpoch;
}
15 changes: 9 additions & 6 deletions lib/src/view/api_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:chucker_flutter/src/view/tabs/overview.dart';
import 'package:chucker_flutter/src/view/widgets/app_bar.dart';
import 'package:chucker_flutter/src/view/widgets/sizeable_text_button.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:share_plus/share_plus.dart';

Expand Down Expand Up @@ -61,10 +60,13 @@ class _ApiDetailsPageState extends State<ApiDetailsPage> {
TextButton(
onPressed: () {
Clipboard.setData(
ClipboardData(text: _cURLRepresentation(widget.api)));
ClipboardData(text: _cURLRepresentation(widget.api)),
);
},
child: const Text('Copy cURL Command',
style: TextStyle(color: Colors.white)),
child: const Text(
'Copy cURL Command',
style: TextStyle(color: Colors.white),
),
),
],
),
Expand Down Expand Up @@ -137,7 +139,8 @@ class _ApiDetailsPageState extends State<ApiDetailsPage> {
}

String _cURLRepresentation(ApiResponse api) {
List<String> components = ['curl -i'];
// ignore: omit_local_variable_types
final List<String> components = ['curl -i'];

if (api.method.toUpperCase() != 'GET') {
components.add('-X ${api.method}');
Expand All @@ -150,7 +153,7 @@ String _cURLRepresentation(ApiResponse api) {
});

if (api.body != null && api.body.toString().isNotEmpty) {
final encodedBody = api.body.toString().replaceAll('"', '\\"');
final encodedBody = api.body.toString().replaceAll('"', r'\"');
components.add('-d "$encodedBody"');
}

Expand Down
4 changes: 2 additions & 2 deletions test/src/models/api_response_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ void main() {
const statusCode = 500;
const connectionTimeout = -1;
const contentType = 'xml';
const headers = 'bearer token';
const queryParameters = 'userId:1';
const headers = {'Content-Type': 'application/json'};
const queryParameters = {'id': '1'};
const receiveTimeout = -1;
const request = {'id': '1'};
const requestSize = 5.0;
Expand Down

0 comments on commit f9bcf97

Please sign in to comment.