72 lines
2.2 KiB
Dart
72 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../services/protocol_log.dart';
|
|
|
|
/// In-app view of the persistent protocol log, for field debugging.
|
|
class LogScreen extends StatelessWidget {
|
|
const LogScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final log = ProtocolLog.instance;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Protocol log'),
|
|
actions: [
|
|
IconButton(
|
|
tooltip: 'Copy all',
|
|
icon: const Icon(Icons.copy),
|
|
onPressed: () async {
|
|
await Clipboard.setData(ClipboardData(text: log.lines.join('\n')));
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(const SnackBar(content: Text('Log copied to clipboard')));
|
|
}
|
|
},
|
|
),
|
|
IconButton(
|
|
tooltip: 'Clear',
|
|
icon: const Icon(Icons.delete_outline),
|
|
onPressed: log.clear,
|
|
),
|
|
],
|
|
),
|
|
body: ListenableBuilder(
|
|
listenable: log,
|
|
builder: (context, _) {
|
|
final lines = log.lines;
|
|
return Column(
|
|
children: [
|
|
if (log.path != null)
|
|
Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: SelectableText(
|
|
'adb pull ${log.path}',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
reverse: true,
|
|
itemCount: lines.length,
|
|
itemBuilder: (context, i) {
|
|
final line = lines[lines.length - 1 - i];
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 1),
|
|
child: SelectableText(
|
|
line,
|
|
style: const TextStyle(fontFamily: 'monospace', fontSize: 11),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|