Feat: Macht die Kontoliste und Versionsanzeige funktional
This commit is contained in:
@@ -15,52 +15,59 @@ class AccountSelect extends StatefulWidget {
|
||||
|
||||
class _AccountSelectState extends State<AccountSelect> {
|
||||
final AccountController _accountController = AccountController();
|
||||
Account? _selected;
|
||||
List<Account> _accounts = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_selected = _accountController.selected.value;
|
||||
_accounts = _accountController.accounts.value;
|
||||
|
||||
_accountController.selected.addListener(() {
|
||||
setState(() {
|
||||
if (context.mounted) {
|
||||
_selected = _accountController.selected.value;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
_accountController.accounts.addListener(() {
|
||||
setState(() {
|
||||
if (context.mounted) {
|
||||
_accounts = _accountController.accounts.value;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
final Future<Account?> selected = _accountController.selected;
|
||||
if (_selected != null && _accounts != []) {
|
||||
return DropdownSearch<Account>(
|
||||
items: (final f, final cs) => _accounts,
|
||||
selectedItem: _selected,
|
||||
onChanged: (final Account? account) {
|
||||
if (account != null) {
|
||||
_accountController.selected = account;
|
||||
}
|
||||
},
|
||||
|
||||
return FutureBuilder(
|
||||
future: selected,
|
||||
builder:
|
||||
(final BuildContext context, final AsyncSnapshot<Account?> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return DropdownSearch<Account>(
|
||||
items: (final f, final cs) => _accountController.getAccounts(),
|
||||
selectedItem: snapshot.data,
|
||||
onChanged: (final Account? account) {
|
||||
if (account != null) {
|
||||
_accountController.selected = account;
|
||||
}
|
||||
},
|
||||
|
||||
itemAsString: (final Account account) => account.name,
|
||||
compareFn: (final Account a1, final Account a2) =>
|
||||
a1.id == a2.id,
|
||||
popupProps: const PopupProps<Account>.menu(
|
||||
showSearchBox: true,
|
||||
searchFieldProps: TextFieldProps(
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Konto suchen...',
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return const Row(
|
||||
children: [
|
||||
Icon(Icons.error, color: Colors.red),
|
||||
Text('Fehler beim Laden der Konten!'),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
},
|
||||
);
|
||||
itemAsString: (final Account account) => account.name,
|
||||
compareFn: (final Account a1, final Account a2) => a1.id == a2.id,
|
||||
popupProps: const PopupProps<Account>.menu(
|
||||
showSearchBox: true,
|
||||
searchFieldProps: TextFieldProps(
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Konto suchen...',
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
92
lib/Pages/Misc/editable_list.dart
Normal file
92
lib/Pages/Misc/editable_list.dart
Normal file
@@ -0,0 +1,92 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../Entities/list_item.dart';
|
||||
|
||||
/// Eine editierbare Liste mit Funktionen zur Bearbeitung
|
||||
class EditableList extends StatelessWidget {
|
||||
/// Erstellt eine neue Instanz dieser Klasse
|
||||
const EditableList({
|
||||
required this.name,
|
||||
required this.items,
|
||||
required this.onAdd,
|
||||
required this.onRename,
|
||||
required this.onDelete,
|
||||
this.icon,
|
||||
this.addTooltip,
|
||||
this.menuTooltip,
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// Der Name, der oben angezeigt wird
|
||||
final String name;
|
||||
|
||||
/// Die
|
||||
final List<ListItem> items;
|
||||
|
||||
/// Die Funktion, die aufgerufen wird,
|
||||
/// wenn ein neuer Eintrag hinzugefügt werden soll
|
||||
final void Function() onAdd;
|
||||
|
||||
/// Die Funktion, die beim umbenennen aufgerufen wird
|
||||
final void Function(int) onRename;
|
||||
|
||||
///Die Funktion, die beim Löschen aufgerufen wird
|
||||
final void Function(int) onDelete;
|
||||
|
||||
/// Das Icon, das angezeigt wird
|
||||
final Icon? icon;
|
||||
|
||||
/// Der Tooltip, der beim erstellen-Button angezeigt wird
|
||||
final String? addTooltip;
|
||||
|
||||
/// Der Tooltip, der auf dem Menü angezeigt wird
|
||||
final String? menuTooltip;
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) => Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
name,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onAdd,
|
||||
icon: const Icon(Icons.add),
|
||||
tooltip: addTooltip,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: items.length,
|
||||
separatorBuilder: (_, _) => const Divider(),
|
||||
itemBuilder: (final context, final index) => ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(items[index].name),
|
||||
leading: icon,
|
||||
trailing: PopupMenuButton<String>(
|
||||
tooltip: menuTooltip,
|
||||
onSelected: (final value) {
|
||||
if (value == 'rename') {
|
||||
onRename(items[index].id);
|
||||
} else if (value == 'delete') {
|
||||
onDelete(items[index].id);
|
||||
}
|
||||
},
|
||||
itemBuilder: (_) => const [
|
||||
PopupMenuItem(value: 'rename', child: Text('Umbenennen')),
|
||||
PopupMenuItem(value: 'delete', child: Text('Entfernen')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -33,9 +33,7 @@ class _FloatingCreationButtonState extends State<FloatingCreationButton> {
|
||||
_expandableButton(
|
||||
label: 'Neues Konto',
|
||||
icon: Icons.account_balance_wallet,
|
||||
onPressed: () {
|
||||
_accountController.newAccountHandler(context);
|
||||
},
|
||||
onPressed: _accountController.newAccountHandler,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user