|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:get/get.dart'; |
| 3 | +import 'package:taskwarrior/app/utils/debug_logger/log_databse_helper.dart'; |
| 4 | +import '../controllers/logs_controller.dart'; |
| 5 | + |
| 6 | +class LogsView extends GetView<LogsController> { |
| 7 | + const LogsView({super.key}); |
| 8 | + |
| 9 | + @override |
| 10 | + Widget build(BuildContext context) { |
| 11 | + return Scaffold( |
| 12 | + appBar: AppBar( |
| 13 | + title: const Text('Debug Logs'), |
| 14 | + actions: [ |
| 15 | + Obx( |
| 16 | + () => IconButton( |
| 17 | + icon: const Icon(Icons.refresh), |
| 18 | + onPressed: |
| 19 | + controller.isLoading.value ? null : controller.loadLogs, |
| 20 | + tooltip: 'Refresh Logs', |
| 21 | + ), |
| 22 | + ), |
| 23 | + Obx( |
| 24 | + () => IconButton( |
| 25 | + icon: const Icon(Icons.delete_forever), |
| 26 | + onPressed: |
| 27 | + controller.isLoading.value ? null : controller.clearLogs, |
| 28 | + tooltip: 'Clear All Logs', |
| 29 | + ), |
| 30 | + ), |
| 31 | + ], |
| 32 | + ), |
| 33 | + body: Obx( |
| 34 | + () { |
| 35 | + if (controller.isLoading.value) { |
| 36 | + return const Center(child: CircularProgressIndicator()); |
| 37 | + } else if (controller.logs.isEmpty) { |
| 38 | + return const Center( |
| 39 | + child: Text( |
| 40 | + 'No debug logs found.', |
| 41 | + style: TextStyle(fontSize: 16, color: Colors.grey), |
| 42 | + ), |
| 43 | + ); |
| 44 | + } else { |
| 45 | + return ListView.builder( |
| 46 | + padding: const EdgeInsets.all(8.0), |
| 47 | + itemCount: controller.logs.length, |
| 48 | + itemBuilder: (context, index) { |
| 49 | + final log = controller.logs[index]; |
| 50 | + return Card( |
| 51 | + margin: const EdgeInsets.symmetric(vertical: 4.0), |
| 52 | + child: Padding( |
| 53 | + padding: const EdgeInsets.all(12.0), |
| 54 | + child: Column( |
| 55 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 56 | + children: [ |
| 57 | + Text( |
| 58 | + log[LogDatabaseHelper.columnMessage] ?? 'No message', |
| 59 | + style: const TextStyle(fontSize: 15), |
| 60 | + ), |
| 61 | + const SizedBox(height: 4), |
| 62 | + Text( |
| 63 | + 'Timestamp: ${log[LogDatabaseHelper.columnTimestamp] ?? 'N/A'}', |
| 64 | + style: |
| 65 | + const TextStyle(fontSize: 12, color: Colors.grey), |
| 66 | + ), |
| 67 | + ], |
| 68 | + ), |
| 69 | + ), |
| 70 | + ); |
| 71 | + }, |
| 72 | + ); |
| 73 | + } |
| 74 | + }, |
| 75 | + ), |
| 76 | + ); |
| 77 | + } |
| 78 | +} |
0 commit comments