This commit is contained in:
otsmr 2025-04-21 17:12:20 +02:00
parent d8155765a6
commit cbe2619a06

View file

@ -4,13 +4,30 @@ import 'package:path_provider/path_provider.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:twonly/src/utils/misc.dart'; import 'package:twonly/src/utils/misc.dart';
class DiagnosticsView extends StatelessWidget { class DiagnosticsView extends StatefulWidget {
const DiagnosticsView({super.key}); const DiagnosticsView({super.key});
@override
State<DiagnosticsView> createState() => _DiagnosticsViewState();
}
class _DiagnosticsViewState extends State<DiagnosticsView> {
final ScrollController _scrollController = ScrollController();
void _scrollToBottom() {
// Assuming the button is at the bottom of the scroll view
_scrollController.animateTo(
_scrollController.position.maxScrollExtent, // Scroll to the bottom
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SafeArea( return Scaffold(
child: FutureBuilder<String>( appBar: AppBar(title: const Text('Diagnostics')),
body: FutureBuilder<String>(
future: _loadLogFile(), future: _loadLogFile(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) { if (snapshot.connectionState == ConnectionState.waiting) {
@ -20,54 +37,56 @@ class DiagnosticsView extends StatelessWidget {
} else { } else {
final logText = snapshot.data ?? ''; final logText = snapshot.data ?? '';
return Scaffold( return Column(
appBar: AppBar(title: const Text('Diagnostics')), children: [
body: Column( Expanded(
children: [ child: SingleChildScrollView(
Expanded( controller: _scrollController,
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Text(logText),
),
),
Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Row( child: Text(logText),
mainAxisAlignment: MainAxisAlignment.spaceBetween, ),
children: [ ),
TextButton( Padding(
onPressed: () { padding: const EdgeInsets.all(16.0),
Clipboard.setData(ClipboardData(text: logText)); child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
Clipboard.setData(ClipboardData(text: logText));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Log copied to clipboard!')),
);
},
child: const Text('Copy All Text'),
),
TextButton(
onPressed: _scrollToBottom,
child: const Text('Scroll to Bottom'),
),
TextButton(
onPressed: () async {
if (await deleteLogFile()) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( const SnackBar(
content: Text('Log copied to clipboard!')), content: Text('Log file deleted!')),
); );
}, } else {
child: const Text('Copy All Text'), if (!context.mounted) return;
), ScaffoldMessenger.of(context).showSnackBar(
TextButton( const SnackBar(
onPressed: () async { content: Text('Log file does not exist.')),
if (await deleteLogFile()) { );
if (!context.mounted) return; }
ScaffoldMessenger.of(context).showSnackBar( },
const SnackBar( child: const Text('Delete Log File'),
content: Text('Log file deleted!')), ),
); ],
} else {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Log file does not exist.')),
);
}
},
child: const Text('Delete Log File'),
),
],
),
), ),
], ),
), ],
); );
} }
}, },