Skip to content
Snippets Groups Projects
Commit e339715c authored by Celine Schmitt's avatar Celine Schmitt
Browse files

Icons and Color switch

parent d3e47e92
No related branches found
No related tags found
No related merge requests found
...@@ -15,12 +15,24 @@ class EditCategoryPage extends StatefulWidget { ...@@ -15,12 +15,24 @@ class EditCategoryPage extends StatefulWidget {
class _EditCategoryPageState extends State<EditCategoryPage> { class _EditCategoryPageState extends State<EditCategoryPage> {
TextEditingController _nameController = TextEditingController(); TextEditingController _nameController = TextEditingController();
Color _selectedColor = Colors.red; Color _selectedColor = Colors.red;
IconData _selectedIcon = Icons.star;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_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);
}
IconData _getValidIconData(int codePoint) {
if (codePoint == Icons.star.codePoint) {
return Icons.star;
} else if (codePoint == Icons.favorite.codePoint) {
return Icons.favorite;
} else {
return Icons.star;
}
} }
@override @override
...@@ -34,8 +46,8 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -34,8 +46,8 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
Category updatedCategory = Category( Category updatedCategory = Category(
id: widget.category.id, id: widget.category.id,
title: newName, title: newName,
iconCodePoint: widget.category.iconCodePoint, iconCodePoint: _selectedIcon.codePoint,
iconFontFamily: widget.category.iconFontFamily, iconFontFamily: 'MaterialIcons',
colorValue: _selectedColor.value, colorValue: _selectedColor.value,
spendings: widget.category.spendings, spendings: widget.category.spendings,
budget: widget.category.budget, budget: widget.category.budget,
...@@ -85,6 +97,27 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -85,6 +97,27 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
); );
} }
void _onIconChanged(IconData? newIcon) {
if (newIcon != null) {
setState(() {
_selectedIcon = newIcon;
});
}
}
Widget _buildIconContainer(IconData iconData) {
return Container(
decoration: BoxDecoration(
color: _selectedColor,
shape: BoxShape.circle,
),
child: Icon(
iconData,
color: Colors.white,
),
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
...@@ -108,37 +141,94 @@ class _EditCategoryPageState extends State<EditCategoryPage> { ...@@ -108,37 +141,94 @@ class _EditCategoryPageState extends State<EditCategoryPage> {
controller: _nameController, controller: _nameController,
decoration: const InputDecoration( decoration: const InputDecoration(
labelText: 'Name', labelText: 'Name',
), ),
), ),
const SizedBox(height: 16.0), const SizedBox(height: 16.0),
Row( Row(
children: [ children: [
const Text( const Text(
'Farbe:', 'Farbe',
style: TextStyle(fontSize: 16.0), style: TextStyle(
fontSize: 19.0,
fontWeight: FontWeight.bold,
),
), ),
const SizedBox(width: 8.0), const SizedBox(width: 16.0),
GestureDetector( GestureDetector(
onTap: _showColorPicker, onTap: _showColorPicker,
child: Container( child: Container(
width: 30.0, width: 32.0,
height: 30.0, height: 32.0,
decoration: BoxDecoration( decoration: BoxDecoration(
color: _selectedColor, color: _selectedColor,
border: Border.all(color: Colors.black), shape: BoxShape.circle,
), ),
), ),
), ),
], ],
), ),
const SizedBox(height: 16.0), const SizedBox(height: 16.0),
ElevatedButton( Row(
onPressed: _updateCategoryName, children: [
child: const Text('Speichern'), const Text(
'Icon',
style: TextStyle(
fontSize: 19.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 16.0),
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: () {
_onIconChanged(iconData);
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: _selectedIcon == iconData
? Colors.blue
: Colors.transparent,
width: 2.0,
),
),
child: _buildIconContainer(iconData),
), ),
);
}).toList(),
),
),
],
),
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: _updateCategoryName,
child: const Text('Speichern'),
),
], ],
), ),
), ),
); );
} }
} }
\ No newline at end of file
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