Skip to content
Snippets Groups Projects
Commit 94a2379a authored by Florian Schindler's avatar Florian Schindler
Browse files

additional functionality

- swipe to delete
- edit
- fixed bug where the category would be the same across listtiles
parent e339715c
No related branches found
No related tags found
No related merge requests found
import 'package:flutter/material.dart';
import 'package:trackeroo/frontend/views/edit_transaction_view.dart';
import 'package:trackeroo/logic/models/category.dart';
import 'package:trackeroo/logic/models/transaction.dart';
import 'package:trackeroo/logic/services/categories_controller.dart';
import 'package:trackeroo/logic/services/locator.dart';
import 'package:trackeroo/logic/services/transactions_controller.dart';
class TransactionListtile extends StatefulWidget {
const TransactionListtile({super.key, required this.transaction});
......@@ -14,33 +16,60 @@ class TransactionListtile extends StatefulWidget {
}
class _TransactionListtileState extends State<TransactionListtile> {
late Category category;
final monthsGer = const ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
@override
void initState() {
category = locator.get<CategoriesController>().categories[widget.transaction.categoryId] ??
Category(id: 'no_category', title: '', iconCodePoint: Icons.attach_money_rounded.codePoint, colorValue: Colors.transparent.value);
super.initState();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
Category category = locator.get<CategoriesController>().catBox.get(widget.transaction.categoryId)!;
return Padding(
padding: const EdgeInsets.only(bottom: 5.0),
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(12.0)),
child: Dismissible(
key: UniqueKey(),
direction: DismissDirection.startToEnd,
onDismissed: (_) => {
locator.get<TransactionsController>().deleteTransaction(widget.transaction),
ScaffoldMessenger.of(context).removeCurrentSnackBar(),
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Transaction deleted',
style: TextStyle(
color: Theme.of(context).colorScheme.onSecondary
),
),
backgroundColor: Theme.of(context).colorScheme.secondary,
behavior: SnackBarBehavior.floating,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
action: SnackBarAction(
label: 'Undo',
textColor: Theme.of(context).colorScheme.onSecondary,
onPressed: () => locator.get<TransactionsController>().undoLastDeletion()
),
)
)
},
background: Container(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
color: Theme.of(context).colorScheme.errorContainer,
alignment: Alignment.centerLeft,
child: Icon(
Icons.delete,
color: Theme.of(context).colorScheme.error,
),
),
child: GestureDetector(
onTap: () => showModalBottomSheet<void>(
showDragHandle: true,
context: context,
builder: (BuildContext context) {
return buildModalContent(widget.transaction);
return buildModalContent(widget.transaction, category, context);
},
),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
margin: const EdgeInsets.only(bottom: 5.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: const BorderRadius.all(Radius.circular(12.0))
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
......@@ -82,10 +111,13 @@ class _TransactionListtileState extends State<TransactionListtile> {
],
),
),
),
),
),
);
}
Widget buildModalContent(Transaction transaction) {
Widget buildModalContent(Transaction transaction, Category category, BuildContext context) {
return SizedBox(
width: double.infinity,
child: SafeArea(
......@@ -164,7 +196,12 @@ class _TransactionListtileState extends State<TransactionListtile> {
const SizedBox(width: 10.0),
Expanded(
child: FilledButton.tonal(
onPressed: () => {},
onPressed: () => {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EditTransactionView(transaction: transaction))
)
},
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment