Feat: Macht die Kontoauswahl funktional
This commit is contained in:
66
lib/Pages/Misc/account_select.dart
Normal file
66
lib/Pages/Misc/account_select.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:dropdown_search/dropdown_search.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../Controller/account_controller.dart';
|
||||
import '../../Entities/drift_database.dart';
|
||||
|
||||
/// Ein Dropdown, mit welchem man das Konto auswählen kann
|
||||
class AccountSelect extends StatefulWidget {
|
||||
/// Erstellt eine neue Instanz dieser Klasse
|
||||
const AccountSelect({super.key});
|
||||
|
||||
@override
|
||||
State<AccountSelect> createState() => _AccountSelectState();
|
||||
}
|
||||
|
||||
class _AccountSelectState extends State<AccountSelect> {
|
||||
final AccountController _accountController = AccountController();
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
final Future<Account?> selected = _accountController.selected;
|
||||
|
||||
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();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
65
lib/Pages/Misc/floating_creation_button.dart
Normal file
65
lib/Pages/Misc/floating_creation_button.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_expandable_fab/flutter_expandable_fab.dart';
|
||||
|
||||
import '../../Controller/account_controller.dart';
|
||||
|
||||
/// Ein Floating Action Button, der beim Klicken ein expandierendes Menü öffnet,
|
||||
/// um neue Transaktionen oder Konten anzulegen.
|
||||
class FloatingCreationButton extends StatefulWidget {
|
||||
/// Erstellt eine neue Instanz dieser Klasse
|
||||
const FloatingCreationButton({super.key});
|
||||
|
||||
@override
|
||||
State<FloatingCreationButton> createState() => _FloatingCreationButtonState();
|
||||
}
|
||||
|
||||
class _FloatingCreationButtonState extends State<FloatingCreationButton> {
|
||||
final AccountController _accountController = AccountController();
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) => ExpandableFab(
|
||||
openButtonBuilder: RotateFloatingActionButtonBuilder(
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
type: ExpandableFabType.up,
|
||||
childrenAnimation: ExpandableFabAnimation.none,
|
||||
distance: 70,
|
||||
children: <Widget>[
|
||||
_expandableButton(
|
||||
label: 'Neue Transaktion',
|
||||
icon: Icons.add,
|
||||
onPressed: () {},
|
||||
),
|
||||
_expandableButton(
|
||||
label: 'Neues Konto',
|
||||
icon: Icons.account_balance_wallet,
|
||||
onPressed: () {
|
||||
_accountController.newAccountHandler(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Widget _expandableButton({
|
||||
required final String label,
|
||||
required final IconData icon,
|
||||
required final VoidCallback onPressed,
|
||||
}) => GestureDetector(
|
||||
onTap: onPressed,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(8)),
|
||||
child: Text(label),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
FloatingActionButton.small(
|
||||
heroTag: null,
|
||||
onPressed: onPressed,
|
||||
child: Icon(icon),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user