import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:moxxyv2/i18n/strings.g.dart'; import 'package:moxxyv2/shared/models/preferences.dart'; import 'package:moxxyv2/ui/bloc/preferences_bloc.dart'; import 'package:moxxyv2/ui/constants.dart'; import 'package:moxxyv2/ui/widgets/settings/row.dart'; import 'package:moxxyv2/ui/widgets/settings/title.dart'; import 'package:moxxyv2/ui/widgets/topbar.dart'; class DebuggingPage extends StatelessWidget { DebuggingPage({super.key}) : _ipController = TextEditingController(), _passphraseController = TextEditingController(), _portController = TextEditingController(); final TextEditingController _ipController; final TextEditingController _portController; final TextEditingController _passphraseController; static MaterialPageRoute get route => MaterialPageRoute( builder: (_) => DebuggingPage(), settings: const RouteSettings( name: debuggingRoute, ), ); @override Widget build(BuildContext context) { return Scaffold( appBar: BorderlessTopbar.title(t.pages.settings.debugging.title), body: BlocBuilder( builder: (context, state) => ListView( children: [ SectionTitle(t.pages.settings.debugging.generalSection), SettingsRow( title: t.pages.settings.debugging.generalEnableDebugging, suffix: Switch( value: state.debugEnabled, onChanged: (value) { context.read().add( PreferencesChangedEvent( state.copyWith(debugEnabled: value), ), ); }, ), ), SettingsRow( title: t.pages.settings.debugging.generalEncryptionPassword, description: t.pages.settings.debugging.generalEncryptionPasswordSubtext, onTap: () { showDialog( context: context, builder: (BuildContext context) => AlertDialog( title: Text( t.pages.settings.debugging.generalEncryptionPassword, ), content: TextField( minLines: 1, obscureText: true, controller: _passphraseController, ), actions: [ TextButton( child: Text(t.global.dialogAccept), onPressed: () { context.read().add( PreferencesChangedEvent( state.copyWith( debugPassphrase: _passphraseController.text, ), ), ); Navigator.of(context).pop(); }, ) ], ), ); }, ), SettingsRow( title: t.pages.settings.debugging.generalLoggingIp, description: t.pages.settings.debugging.generalLoggingIpSubtext, onTap: () { showDialog( context: context, builder: (BuildContext context) => AlertDialog( title: Text(t.pages.settings.debugging.generalLoggingIp), content: TextField( minLines: 1, obscureText: true, controller: _ipController, ), actions: [ TextButton( child: Text(t.global.dialogAccept), onPressed: () { context.read().add( PreferencesChangedEvent( state.copyWith(debugIp: _ipController.text), ), ); Navigator.of(context).pop(); }, ) ], ), ); }, ), SettingsRow( title: t.pages.settings.debugging.generalLoggingPort, description: t.pages.settings.debugging.generalLoggingPortSubtext, onTap: () { showDialog( context: context, builder: (BuildContext context) => AlertDialog( title: Text(t.pages.settings.debugging.generalLoggingPort), content: TextField( minLines: 1, controller: _portController, keyboardType: TextInputType.number, ), actions: [ TextButton( child: Text(t.global.dialogAccept), onPressed: () { context.read().add( PreferencesChangedEvent( state.copyWith( debugPort: int.parse(_portController.text), ), ), ); Navigator.of(context).pop(); }, ) ], ), ); }, ), // Hide the testing commands outside of debug mode ...kDebugMode ? [ const SectionTitle('Testing'), SettingsRow( title: 'Reset showDebugMenu state', onTap: () { context.read().add( PreferencesChangedEvent( state.copyWith( showDebugMenu: false, ), ), ); }, ), ] : [], ], ), ), ); } }