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

101 lines
3.5 KiB
Dart
Raw Permalink Normal View History

2024-05-23 17:41:51 +02:00
import 'package:flutter/material.dart';
2024-05-25 18:09:39 +02:00
import 'package:hive_flutter/hive_flutter.dart';
import 'package:intl/intl.dart';
import 'package:simplecloudnotifier/pages/debug/debug_request_view.dart';
import 'package:simplecloudnotifier/state/request_log.dart';
import 'package:simplecloudnotifier/utils/navi.dart';
2024-05-23 17:41:51 +02:00
class DebugRequestsPage extends StatefulWidget {
@override
_DebugRequestsPageState createState() => _DebugRequestsPageState();
}
class _DebugRequestsPageState extends State<DebugRequestsPage> {
2024-05-25 18:09:39 +02:00
Box<SCNRequest> requestsBox = Hive.box<SCNRequest>('scn-requests');
static final _dateFormat = DateFormat('yyyy-MM-dd kk:mm');
2024-05-23 17:41:51 +02:00
@override
Widget build(BuildContext context) {
2024-05-25 18:09:39 +02:00
return Container(
child: ValueListenableBuilder(
valueListenable: requestsBox.listenable(),
builder: (context, Box<SCNRequest> box, _) {
return ListView.builder(
itemCount: requestsBox.length,
itemBuilder: (context, listIndex) {
final req = requestsBox.getAt(requestsBox.length - listIndex - 1)!;
if (req.type == 'SUCCESS') {
2024-05-25 21:36:05 +02:00
return buildItemSuccess(context, req);
2024-05-25 18:09:39 +02:00
} else {
2024-05-25 21:36:05 +02:00
return buildItemError(context, req);
2024-05-25 18:09:39 +02:00
}
},
);
},
),
);
2024-05-23 17:41:51 +02:00
}
2024-05-25 21:36:05 +02:00
Padding buildItemError(BuildContext context, SCNRequest req) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 2.0),
child: GestureDetector(
onTap: () => Navi.push(context, () => DebugRequestViewPage(request: req)),
2024-05-25 21:36:05 +02:00
child: ListTile(
tileColor: Theme.of(context).colorScheme.errorContainer,
textColor: Theme.of(context).colorScheme.onErrorContainer,
title: Row(
children: [
SizedBox(
width: 120,
child: Text(_dateFormat.format(req.timestampStart), style: TextStyle(fontSize: 12)),
),
Expanded(
child: Text(req.name, style: TextStyle(fontWeight: FontWeight.bold)),
),
SizedBox(width: 2),
Text('${req.timestampEnd.difference(req.timestampStart).inMilliseconds}ms', style: TextStyle(fontSize: 12)),
],
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(req.type),
Text(
req.error,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
)),
),
);
}
Padding buildItemSuccess(BuildContext context, SCNRequest req) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 2.0),
child: GestureDetector(
onTap: () => Navi.push(context, () => DebugRequestViewPage(request: req)),
2024-05-25 21:36:05 +02:00
child: ListTile(
title: Row(
children: [
SizedBox(
width: 120,
child: Text(_dateFormat.format(req.timestampStart), style: TextStyle(fontSize: 12)),
),
Expanded(
child: Text(req.name, style: TextStyle(fontWeight: FontWeight.bold)),
),
SizedBox(width: 2),
Text('${req.timestampEnd.difference(req.timestampStart).inMilliseconds}ms', style: TextStyle(fontSize: 12)),
],
),
subtitle: Text(req.type),
),
),
);
}
2024-05-23 17:41:51 +02:00
}