From 69e7e9d8172fa68c3b205d3b6dee786451250b8a Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Mon, 22 Dec 2025 00:56:58 +0100 Subject: [PATCH] =?UTF-8?q?Feat:=20F=C3=BCgt=20eine=20Dummy-Settings-Seite?= =?UTF-8?q?=20hinzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Pages/Settings/settings.dart | 200 ++++++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 2 deletions(-) diff --git a/lib/Pages/Settings/settings.dart b/lib/Pages/Settings/settings.dart index 5cc6f09..b5e4e96 100644 --- a/lib/Pages/Settings/settings.dart +++ b/lib/Pages/Settings/settings.dart @@ -1,6 +1,202 @@ import 'package:flutter/material.dart'; -class Settings extends StatelessWidget { +class Settings extends StatefulWidget { + const Settings({super.key}); + @override - Widget build(final BuildContext context) => const Text('SETTINGS'); + State createState() => _SettingsState(); +} + +class _SettingsState extends State { + final List _accounts = [ + 'Girokonto', + 'Sparkonto', + 'Kreditkarte', + ]; + + Future _addAccount() async { + final TextEditingController controller = TextEditingController(); + + await showDialog( + context: context, + builder: (final BuildContext context) => AlertDialog( + title: const Text('Konto hinzufügen'), + content: TextField( + controller: controller, + decoration: const InputDecoration( + labelText: 'Kontoname', + border: OutlineInputBorder(), + ), + autofocus: true, + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Abbrechen'), + ), + ElevatedButton( + onPressed: () { + if (controller.text.isNotEmpty) { + setState(() => _accounts.add(controller.text)); + } + Navigator.pop(context); + }, + child: const Text('Hinzufügen'), + ), + ], + ), + ); + } + + Future _renameAccount(final int index) async { + final TextEditingController controller = TextEditingController( + text: _accounts[index], + ); + + await showDialog( + context: context, + builder: (final BuildContext context) => AlertDialog( + title: const Text('Konto umbenennen'), + content: TextField( + controller: controller, + decoration: const InputDecoration( + labelText: 'Neuer Name', + border: OutlineInputBorder(), + ), + autofocus: true, + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Abbrechen'), + ), + ElevatedButton( + onPressed: () { + if (controller.text.isNotEmpty) { + setState(() => _accounts[index] = controller.text); + } + Navigator.pop(context); + }, + child: const Text('Speichern'), + ), + ], + ), + ); + } + + Future _removeAccount(final int index) async { + await showDialog( + context: context, + builder: (final BuildContext context) => AlertDialog( + title: const Text('Konto entfernen'), + content: Text( + 'Möchtest du das Konto "${_accounts[index]}" wirklich löschen?', + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Abbrechen'), + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Theme.of(context).colorScheme.error, + ), + onPressed: () { + setState(() => _accounts.removeAt(index)); + Navigator.pop(context); + }, + child: const Text('Löschen'), + ), + ], + ), + ); + } + + @override + Widget build(final BuildContext context) { + final ThemeData theme = Theme.of(context); + + return Scaffold( + body: SafeArea( + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'Einstellungen', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + + const SizedBox(height: 24), + _accountHeader(), + + const SizedBox(height: 8), + _accountList(), + + const SizedBox(height: 8), + _versionNumber(theme), + ], + ), + ), + ), + ); + } + + Widget _accountHeader() => Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + 'Konten', + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + IconButton( + onPressed: _addAccount, + icon: const Icon(Icons.add), + tooltip: 'Konto hinzufügen', + ), + ], + ); + + Widget _accountList() => Expanded( + child: ListView.separated( + itemCount: _accounts.length, + separatorBuilder: (_, _) => const Divider(), + itemBuilder: (final BuildContext context, final int index) => ListTile( + contentPadding: EdgeInsets.zero, + title: Text(_accounts[index]), + leading: const Icon(Icons.account_balance_wallet), + trailing: PopupMenuButton( + onSelected: (final String value) async { + if (value == 'rename') { + await _renameAccount(index); + } else if (value == 'delete') { + await _removeAccount(index); + } + }, + itemBuilder: (final BuildContext context) => + const >[ + PopupMenuItem( + value: 'rename', + child: Text('Umbenennen'), + ), + PopupMenuItem( + value: 'delete', + child: Text('Entfernen'), + ), + ], + ), + ), + ), + ); + + Widget _versionNumber(final ThemeData theme) => Align( + alignment: Alignment.bottomRight, + child: Text( + 'Version 0.0.0+0', + style: theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.onSurface.withAlpha((0.6 * 255).round()), + ), + ), + ); }