SimpleCloudNotifier/flutter/lib/pages/debug/debug_request_view.dart

85 lines
3.6 KiB
Dart
Raw Permalink Normal View History

2024-05-25 18:09:39 +02:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:simplecloudnotifier/components/layout/scaffold.dart';
import 'package:simplecloudnotifier/state/request_log.dart';
2024-05-31 23:21:24 +02:00
import 'package:simplecloudnotifier/utils/toaster.dart';
2024-06-08 12:55:58 +02:00
import 'package:simplecloudnotifier/utils/ui.dart';
2024-05-25 18:09:39 +02:00
class DebugRequestViewPage extends StatelessWidget {
final SCNRequest request;
DebugRequestViewPage({required this.request});
@override
Widget build(BuildContext context) {
return SCNScaffold(
title: 'Request',
showSearch: false,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: [
...buildRow(context, "Name", request.name),
...buildRow(context, "Timestamp (Start)", request.timestampStart.toString()),
...buildRow(context, "Timestamp (End)", request.timestampEnd.toString()),
...buildRow(context, "Duration", request.timestampEnd.difference(request.timestampStart).toString()),
Divider(),
...buildRow(context, "Method", request.method),
...buildRow(context, "URL", request.url),
if (request.requestHeaders.isNotEmpty) ...buildRow(context, "Request->Headers", request.requestHeaders.entries.map((v) => '${v.key} = ${v.value}').join('\n')),
if (request.requestBody != '') ...buildRow(context, "Request->Body", request.requestBody),
Divider(),
if (request.responseStatusCode != 0) ...buildRow(context, "Response->Statuscode", request.responseStatusCode.toString()),
if (request.responseBody != '') ...buildRow(context, "Reponse->Body", request.responseBody),
if (request.responseHeaders.isNotEmpty) ...buildRow(context, "Reponse->Headers", request.responseHeaders.entries.map((v) => '${v.key} = ${v.value}').join('\n')),
Divider(),
if (request.error != '') ...buildRow(context, "Error", request.error),
if (request.stackTrace != '') ...buildRow(context, "Stacktrace", request.stackTrace),
],
),
),
),
);
}
List<Widget> buildRow(BuildContext context, String title, String value) {
return [
Padding(
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8.0),
child: Row(
children: [
Expanded(
child: Text(title, style: TextStyle(fontWeight: FontWeight.bold)),
),
2024-06-08 12:55:58 +02:00
UI.buttonIconOnly(
2024-05-25 18:09:39 +02:00
iconSize: 14,
onPressed: () {
2024-06-08 12:55:58 +02:00
Clipboard.setData(new ClipboardData(text: title));
2024-05-31 23:21:24 +02:00
Toaster.info("Clipboard", 'Copied text to Clipboard');
print('================= [CLIPBOARD] =================\n${title}\n================= [/CLIPBOARD] =================');
2024-05-25 18:09:39 +02:00
},
2024-06-08 12:55:58 +02:00
icon: FontAwesomeIcons.copy,
2024-05-25 18:09:39 +02:00
),
],
),
),
Card.filled(
shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(0)),
color: request.type == 'SUCCESS' ? null : Theme.of(context).colorScheme.errorContainer,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 6.0),
child: SelectableText(
value,
minLines: 1,
maxLines: 10,
),
),
),
];
}
}