diff --git a/lib/src/views/settings/diagnostics_view.dart b/lib/src/views/settings/diagnostics_view.dart index 0f0d8cf..bb41b0c 100644 --- a/lib/src/views/settings/diagnostics_view.dart +++ b/lib/src/views/settings/diagnostics_view.dart @@ -4,13 +4,30 @@ import 'package:path_provider/path_provider.dart'; import 'package:flutter/services.dart'; import 'package:twonly/src/utils/misc.dart'; -class DiagnosticsView extends StatelessWidget { +class DiagnosticsView extends StatefulWidget { const DiagnosticsView({super.key}); + @override + State createState() => _DiagnosticsViewState(); +} + +class _DiagnosticsViewState extends State { + 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 Widget build(BuildContext context) { - return SafeArea( - child: FutureBuilder( + return Scaffold( + appBar: AppBar(title: const Text('Diagnostics')), + body: FutureBuilder( future: _loadLogFile(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { @@ -20,54 +37,56 @@ class DiagnosticsView extends StatelessWidget { } else { final logText = snapshot.data ?? ''; - return Scaffold( - appBar: AppBar(title: const Text('Diagnostics')), - body: Column( - children: [ - Expanded( - child: SingleChildScrollView( - padding: const EdgeInsets.all(16.0), - child: Text(logText), - ), - ), - Padding( + return Column( + children: [ + Expanded( + child: SingleChildScrollView( + controller: _scrollController, padding: const EdgeInsets.all(16.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TextButton( - onPressed: () { - Clipboard.setData(ClipboardData(text: logText)); + child: Text(logText), + ), + ), + Padding( + padding: const EdgeInsets.all(16.0), + 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( const SnackBar( - content: Text('Log copied to clipboard!')), + content: Text('Log file deleted!')), ); - }, - child: const Text('Copy All Text'), - ), - TextButton( - onPressed: () async { - if (await deleteLogFile()) { - if (!context.mounted) return; - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - 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'), - ), - ], - ), + } else { + if (!context.mounted) return; + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Log file does not exist.')), + ); + } + }, + child: const Text('Delete Log File'), + ), + ], ), - ], - ), + ), + ], ); } },