diff --git a/trackeroo/lib/frontend/utils/category_listtile.dart b/trackeroo/lib/frontend/utils/category_listtile.dart index f6ee61f4f52338a1dca3148b453836d89c423767..b3de6e0aeac56a7c50598c42e1beb437bc67df28 100644 --- a/trackeroo/lib/frontend/utils/category_listtile.dart +++ b/trackeroo/lib/frontend/utils/category_listtile.dart @@ -1,19 +1,89 @@ import 'package:flutter/material.dart'; import 'package:trackeroo/logic/models/category.dart'; +import 'package:trackeroo/frontend/views/edit_category_view.dart'; class CategoryListtile extends StatelessWidget { - const CategoryListtile({super.key, required this.category}); + const CategoryListtile({Key? key, required this.category}) : super(key: key); final Category category; @override Widget build(BuildContext context) { - return Row( - children: [ - Icon(IconData(category.iconCodePoint, fontFamily: category.iconFontFamily)), - Text(category.title), - Container(height: 10.0, width: 10.0, color: Color(category.colorValue)), - ], + return Container( + margin: const EdgeInsets.symmetric(vertical: 8.0), + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8.0), + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.3), + spreadRadius: 2, + blurRadius: 5, + offset: const Offset(0, 3), // Ändert die Position des Schattens + ), + ], + ), + child: Row( + children: [ + Container( + width: 50.0, + height: 50.0, + decoration: BoxDecoration( + color: Color(category.colorValue), + borderRadius: BorderRadius.circular(8.0), + ), + child: Icon( + IconData( + category.iconCodePoint, + fontFamily: category.iconFontFamily, + ), + color: Colors.white, + size: 30.0, + ), + ), + const SizedBox(width: 8.0), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: Text( + category.title, + style: const TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.bold, + ), + ), + ), + IconButton( + icon: const Icon(Icons.edit), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => EditCategoryPage(category: category), + ), + ); + }, + ), + ], + ), + const SizedBox(height: 48.0), + Container( + height: 6.0, + decoration: BoxDecoration( + color: Color(category.colorValue), + borderRadius: BorderRadius.circular(8.0), + ), + ), + ], + ), + ), + ], + ), ); } -} +} \ No newline at end of file diff --git a/trackeroo/lib/frontend/views/edit_category_view.dart b/trackeroo/lib/frontend/views/edit_category_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..eaad8a286717242153bb3cf99543a0a5160c9129 --- /dev/null +++ b/trackeroo/lib/frontend/views/edit_category_view.dart @@ -0,0 +1,144 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_colorpicker/flutter_colorpicker.dart'; +import 'package:trackeroo/logic/models/category.dart'; +import 'package:hive/hive.dart'; + +class EditCategoryPage extends StatefulWidget { + final Category category; + + const EditCategoryPage({Key? key, required this.category}) : super(key: key); + + @override + _EditCategoryPageState createState() => _EditCategoryPageState(); +} + +class _EditCategoryPageState extends State<EditCategoryPage> { + TextEditingController _nameController = TextEditingController(); + Color _selectedColor = Colors.red; + + @override + void initState() { + super.initState(); + _nameController.text = widget.category.title; + _selectedColor = Color(widget.category.colorValue); + } + + @override + void dispose() { + _nameController.dispose(); + super.dispose(); + } + + void _updateCategoryName() async { + String newName = _nameController.text; + Category updatedCategory = Category( + id: widget.category.id, + title: newName, + iconCodePoint: widget.category.iconCodePoint, + iconFontFamily: widget.category.iconFontFamily, + colorValue: _selectedColor.value, + spendings: widget.category.spendings, + budget: widget.category.budget, + ); + + final categoryBox = await Hive.openBox<Category>('categories'); + categoryBox.put(widget.category.id, updatedCategory); + categoryBox.close(); + + Navigator.pop(context); + } + + void _showColorPicker() { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Farbe auswählen'), + content: SingleChildScrollView( + child: ColorPicker( + pickerColor: _selectedColor, + onColorChanged: (color) { + setState(() { + _selectedColor = color; + }); + }, + showLabel: true, + pickerAreaHeightPercent: 0.8, + ), + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('Abbrechen'), + ), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + ); + }, + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Kategorie bearbeiten'), + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const Text( + 'Kategorie bearbeiten', + style: TextStyle( + fontSize: 24.0, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 16.0), + TextField( + controller: _nameController, + decoration: const InputDecoration( + labelText: 'Name', + ), + ), + const SizedBox(height: 16.0), + Row( + children: [ + const Text( + 'Farbe:', + style: TextStyle(fontSize: 16.0), + ), + const SizedBox(width: 8.0), + GestureDetector( + onTap: _showColorPicker, + child: Container( + width: 30.0, + height: 30.0, + decoration: BoxDecoration( + color: _selectedColor, + border: Border.all(color: Colors.black), + ), + ), + ), + ], + ), + const SizedBox(height: 16.0), + ElevatedButton( + onPressed: _updateCategoryName, + child: const Text('Speichern'), + ), + ], + ), + ), + ); + } +} \ No newline at end of file diff --git a/trackeroo/lib/logic/models/category.dart b/trackeroo/lib/logic/models/category.dart index f68cace88983e4fcfa4c61c1cb14d3bea2495f52..de5c9571b678d756ae2a9fb603a866fad712ff1c 100644 --- a/trackeroo/lib/logic/models/category.dart +++ b/trackeroo/lib/logic/models/category.dart @@ -32,7 +32,7 @@ class Category { this.iconFontFamily = 'MaterialIcons', required this.colorValue, this.spendings = 0, - this.budget = -1 + this.budget = -1, }); factory Category.fromJson(Map<String, dynamic> parsedJson) { @@ -42,7 +42,7 @@ class Category { iconCodePoint: parsedJson['icon_code_point'], iconFontFamily: parsedJson['icon_font_family'], colorValue: parsedJson['color_value'], - budget: parsedJson['budget'] ?? -1 + budget: parsedJson['budget'] ?? -1, ); } -} +} \ No newline at end of file diff --git a/trackeroo/pubspec.lock b/trackeroo/pubspec.lock index fced3fdd423f09544cc85004a924e5146d05557a..1091aeee26b687316fb51a7189c4823e393b6850 100644 --- a/trackeroo/pubspec.lock +++ b/trackeroo/pubspec.lock @@ -230,6 +230,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_colorpicker: + dependency: "direct main" + description: + name: flutter_colorpicker + sha256: "458a6ed8ea480eb16ff892aedb4b7092b2804affd7e046591fb03127e8d8ef8b" + url: "https://pub.dev" + source: hosted + version: "1.0.3" flutter_lints: dependency: "direct dev" description: diff --git a/trackeroo/pubspec.yaml b/trackeroo/pubspec.yaml index b7476b290e653d0be26e3d1667c8a9c7a0f4fd78..5694bfdd520a1a53bd32405f5239f60999a20f6f 100644 --- a/trackeroo/pubspec.yaml +++ b/trackeroo/pubspec.yaml @@ -40,6 +40,7 @@ dependencies: hive_flutter: ^1.1.0 hive_generator: ^2.0.0 get_it: ^7.6.0 + flutter_colorpicker: ^1.0.3 dev_dependencies: flutter_test: