trcr/lib/status_screen.dart

82 lines
1.9 KiB
Dart
Raw Normal View History

2025-05-05 07:57:34 -07:00
import 'package:flutter/material.dart';
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
2025-06-05 23:15:05 -07:00
import 'l10n/app_localizations.dart';
2025-05-05 07:57:34 -07:00
class StatusScreen extends StatefulWidget {
const StatusScreen({super.key});
@override
State<StatusScreen> createState() => _StatusScreenState();
}
class _StatusScreenState extends State<StatusScreen> {
final List<String> _logs = [];
@override
void initState() {
super.initState();
2025-05-09 07:56:34 -07:00
_refreshLogs();
2025-05-05 07:57:34 -07:00
}
2025-05-09 07:56:34 -07:00
Future<void> _refreshLogs() async {
2025-07-09 21:37:14 -07:00
final logs = await bg.Logger.getLog(bg.SQLQuery(
order: bg.SQLQuery.ORDER_DESC,
limit: 2000,
));
2025-05-05 07:57:34 -07:00
setState(() {
_logs.clear();
2025-05-09 08:00:00 -07:00
_logs.addAll(logs.split('\n').reversed);
2025-05-05 07:57:34 -07:00
});
}
2025-06-10 22:02:37 -07:00
Future<void> _emailLogs() async {
2025-07-09 21:37:14 -07:00
await bg.Logger.emailLog("support@traccar.org", bg.SQLQuery(
order: bg.SQLQuery.ORDER_DESC,
limit: 25000,
));
2025-06-10 22:02:37 -07:00
}
2025-05-05 07:57:34 -07:00
Future<void> _clearLogs() async {
await bg.Logger.destroyLog();
setState(() => _logs.clear());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2025-05-09 07:56:34 -07:00
title: Text(AppLocalizations.of(context)!.statusTitle),
2025-05-05 07:57:34 -07:00
actions: [
IconButton(
icon: const Icon(Icons.refresh),
2025-05-09 07:56:34 -07:00
onPressed: _refreshLogs,
2025-05-05 07:57:34 -07:00
),
2025-06-10 22:02:37 -07:00
IconButton(
icon: const Icon(Icons.share),
onPressed: _emailLogs,
),
2025-05-05 07:57:34 -07:00
IconButton(
icon: const Icon(Icons.delete),
onPressed: _clearLogs,
),
],
),
2025-05-09 07:56:34 -07:00
body: ListView.builder(
reverse: true,
itemCount: _logs.length,
itemBuilder: (_, index) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
2025-05-21 07:36:04 -07:00
child: Text(
_logs[index],
style: TextStyle(
fontSize: 10,
fontFamily: 'monospace',
),
),
2025-05-09 07:56:34 -07:00
),
),
2025-05-05 07:57:34 -07:00
);
}
}