diff --git a/lib/main_screen.dart b/lib/main_screen.dart index 4087da8..d1b4239 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:traccar_client/status_screen.dart'; class MainScreen extends StatelessWidget { const MainScreen({super.key}); @@ -114,6 +115,18 @@ class MainScreen extends StatelessWidget { child: const Text('Advanced settings'), ), ), + Align( + alignment: Alignment.centerRight, + child: OutlinedButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (_) => const StatusScreen()), + ); + }, + child: const Text('Show status'), + ), + ), ], ), ), diff --git a/lib/status_screen.dart b/lib/status_screen.dart new file mode 100644 index 0000000..38ad990 --- /dev/null +++ b/lib/status_screen.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg; + +class StatusScreen extends StatefulWidget { + const StatusScreen({super.key}); + + @override + State createState() => _StatusScreenState(); +} + +class _StatusScreenState extends State { + final List _logs = []; + + @override + void initState() { + super.initState(); + _loadLogs(); + } + + Future _loadLogs() async { + final logs = await bg.Logger.getLog(); // Fetch logs + setState(() { + _logs.clear(); + _logs.addAll(logs.split('\n').reversed); // Latest logs first + }); + } + + Future _clearLogs() async { + await bg.Logger.destroyLog(); + setState(() => _logs.clear()); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Background Geolocation Logs'), + actions: [ + IconButton( + icon: const Icon(Icons.refresh), + onPressed: _loadLogs, + ), + IconButton( + icon: const Icon(Icons.delete), + onPressed: _clearLogs, + ), + ], + ), + body: _logs.isEmpty + ? const Center(child: Text('No logs available.')) + : ListView.builder( + itemCount: _logs.length, + itemBuilder: (_, index) => Padding( + padding: const EdgeInsets.symmetric( + vertical: 2.0, horizontal: 8.0), + child: Text( + _logs[index], + style: const TextStyle(fontSize: 12.0), + ), + ), + ), + ); + } +}