Skip to content
Snippets Groups Projects
Commit 9fde4317 authored by Florian Schindler's avatar Florian Schindler
Browse files
parents 94a2379a 7e42b6f7
No related branches found
No related tags found
No related merge requests found
...@@ -71,7 +71,14 @@ class CategoryListtile extends StatelessWidget { ...@@ -71,7 +71,14 @@ class CategoryListtile extends StatelessWidget {
), ),
], ],
), ),
const SizedBox(height: 48.0), Text(
'Budget: ${category.budget}',
style: const TextStyle(
fontSize: 17.0,
color: Color.fromARGB(255, 81, 78, 78),
),
),
const SizedBox(height: 22.0),
Container( Container(
height: 6.0, height: 6.0,
decoration: BoxDecoration( decoration: BoxDecoration(
...@@ -86,4 +93,4 @@ class CategoryListtile extends StatelessWidget { ...@@ -86,4 +93,4 @@ class CategoryListtile extends StatelessWidget {
), ),
); );
} }
} }
\ No newline at end of file
...@@ -16,6 +16,8 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -16,6 +16,8 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
TextEditingController _nameController = TextEditingController(); TextEditingController _nameController = TextEditingController();
Color _selectedColor = Colors.red; Color _selectedColor = Colors.red;
IconData _selectedIcon = Icons.star; IconData _selectedIcon = Icons.star;
double _budget = 0;
bool _showIconPicker = false;
@override @override
void initState() { void initState() {
...@@ -23,6 +25,7 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -23,6 +25,7 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
_nameController.text = widget.category.title; _nameController.text = widget.category.title;
_selectedColor = Color(widget.category.colorValue); _selectedColor = Color(widget.category.colorValue);
_selectedIcon = _getValidIconData(widget.category.iconCodePoint); _selectedIcon = _getValidIconData(widget.category.iconCodePoint);
_budget = widget.category.budget ?? 0;
} }
IconData _getValidIconData(int codePoint) { IconData _getValidIconData(int codePoint) {
...@@ -50,7 +53,7 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -50,7 +53,7 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
iconFontFamily: 'MaterialIcons', iconFontFamily: 'MaterialIcons',
colorValue: _selectedColor.value, colorValue: _selectedColor.value,
spendings: widget.category.spendings, spendings: widget.category.spendings,
budget: widget.category.budget, budget: _budget,
); );
final categoryBox = await Hive.openBox<Category>('categories'); final categoryBox = await Hive.openBox<Category>('categories');
...@@ -105,8 +108,10 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -105,8 +108,10 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
} }
} }
Widget _buildIconContainer(IconData iconData) { Widget _buildIconContainer(IconData iconData, double size) {
return Container( return Container(
width: size,
height: size,
decoration: BoxDecoration( decoration: BoxDecoration(
color: _selectedColor, color: _selectedColor,
shape: BoxShape.circle, shape: BoxShape.circle,
...@@ -114,10 +119,19 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -114,10 +119,19 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
child: Icon( child: Icon(
iconData, iconData,
color: Colors.white, color: Colors.white,
size: size * 0.6,
), ),
); );
} }
void _deleteCategory() async {
final categoryBox = await Hive.openBox<Category>('categories');
categoryBox.delete(widget.category.id);
categoryBox.close();
Navigator.pop(context);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
...@@ -137,18 +151,74 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -137,18 +151,74 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
), ),
), ),
const SizedBox(height: 16.0), const SizedBox(height: 16.0),
TextField( Row(
controller: _nameController, children: [
decoration: const InputDecoration( GestureDetector(
labelText: 'Name', onTap: () {
setState(() {
), _showIconPicker = !_showIconPicker;
});
},
child: _buildIconContainer(_selectedIcon, 48.0),
),
const SizedBox(width: 16.0),
Expanded(
child: TextField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Name',
),
),
),
],
), ),
if (_showIconPicker)
Expanded(
child: GridView.count(
shrinkWrap: true,
crossAxisCount: 6,
childAspectRatio: 1.0,
children: [
Icons.star,
Icons.favorite,
Icons.attach_money,
Icons.shopping_cart,
Icons.home,
Icons.work,
Icons.school,
Icons.pets,
Icons.luggage,
Icons.savings,
Icons.liquor,
Icons.celebration,
].map((iconData) {
return GestureDetector(
onTap: () {
setState(() {
_onIconChanged(iconData);
_showIconPicker = false;
});
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: _selectedIcon == iconData
? Colors.blue
: Colors.transparent,
width: 2.0,
),
),
child: _buildIconContainer(iconData, 32.0),
),
);
}).toList(),
),
),
const SizedBox(height: 16.0), const SizedBox(height: 16.0),
Row( Row(
children: [ children: [
const Text( const Text(
'Farbe', 'Budget',
style: TextStyle( style: TextStyle(
fontSize: 19.0, fontSize: 19.0,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
...@@ -156,76 +226,120 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -156,76 +226,120 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
), ),
const SizedBox(width: 16.0), const SizedBox(width: 16.0),
GestureDetector( GestureDetector(
onTap: _showColorPicker, onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
TextEditingController _budgetController =
TextEditingController(text: _budget.toString());
return AlertDialog(
title: const Text('Budget ändern'),
content: TextField(
controller: _budgetController,
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Neues Budget',
),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Abbrechen'),
),
TextButton(
onPressed: () {
double newBudget = double.tryParse(
_budgetController.text) ??
0;
setState(() {
_budget = newBudget;
});
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
);
},
);
},
child: Container( child: Container(
width: 32.0, padding: const EdgeInsets.all(8.0),
height: 32.0,
decoration: BoxDecoration( decoration: BoxDecoration(
color: _selectedColor, border: Border.all(
shape: BoxShape.circle, color: Colors.black12,
width: 1.0,
),
),
child: Text(
'${_budget.toStringAsFixed(2)} €',
style: const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
), ),
), ),
), ),
], ],
), ),
const SizedBox(height: 16.0), const SizedBox(height: 16.0),
Row( GestureDetector(
children: [ onTap: _showColorPicker,
const Text( child: Container(
'Icon', padding: const EdgeInsets.all(8.0),
style: TextStyle( decoration: BoxDecoration(
fontSize: 19.0, color: _selectedColor,
fontWeight: FontWeight.bold, borderRadius: BorderRadius.circular(8.0),
), ),
), child: const Text(
const SizedBox(width: 16.0), 'Farbe auswählen',
Expanded( style: TextStyle(
child: GridView.count( color: Colors.black,
shrinkWrap: true, fontSize: 19.0,
crossAxisCount: 6, fontWeight: FontWeight.bold,
childAspectRatio: 1.0, ),
children: [
Icons.star,
Icons.favorite,
Icons.attach_money,
Icons.shopping_cart,
Icons.home,
Icons.work,
Icons.school,
Icons.pets,
Icons.luggage,
Icons.savings,
Icons.liquor,
Icons.celebration,
].map((iconData) {
return GestureDetector(
onTap: () {
_onIconChanged(iconData);
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: _selectedIcon == iconData
? Colors.blue
: Colors.transparent,
width: 2.0,
), ),
), ),
child: _buildIconContainer(iconData),
), ),
); const SizedBox(height: 16.0),
}).toList(), ElevatedButton(
), onPressed: _updateCategoryName,
), child: const Text('Speichern'),
], ),
), const SizedBox(height: 16.0),
const SizedBox(height: 16.0), ElevatedButton(
ElevatedButton( onPressed: () {
showDialog(
onPressed: _updateCategoryName, context: context,
child: const Text('Speichern'), builder: (BuildContext context) {
return AlertDialog(
), title: const Text('Kategorie löschen'),
content: const Text('Möchten Sie diese Kategorie wirklich löschen?'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Abbrechen'),
),
TextButton(
onPressed: () {
_deleteCategory();
},
child: const Text('Löschen'),
),
],
);
},
);
},
child: const Text('Löschen'),
),
], ],
), ),
), ),
......
...@@ -32,7 +32,7 @@ class Category { ...@@ -32,7 +32,7 @@ class Category {
this.iconFontFamily = 'MaterialIcons', this.iconFontFamily = 'MaterialIcons',
required this.colorValue, required this.colorValue,
this.spendings = 0, this.spendings = 0,
this.budget = -1, this.budget = -1,
}); });
factory Category.fromJson(Map<String, dynamic> parsedJson) { factory Category.fromJson(Map<String, dynamic> parsedJson) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment