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

Categorie

parent 910cf1a6
No related branches found
No related tags found
No related merge requests found
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(
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: [
Icon(IconData(category.iconCodePoint, fontFamily: category.iconFontFamily)),
Text(category.title),
Container(height: 10.0, width: 10.0, color: Color(category.colorValue)),
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
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
......@@ -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
......@@ -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:
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment