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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user