From d706332351e151e32bea13084e3b6f64eb65c467 Mon Sep 17 00:00:00 2001 From: Florian <74116125+florianschndlr@users.noreply.github.com> Date: Mon, 3 Jul 2023 18:55:12 +0200 Subject: [PATCH] whaeva --- .../lib/frontend/views/details_view.dart | 2 +- .../frontend/views/edit_transaction_view.dart | 37 +++++++++++++++++-- trackeroo/lib/logic/models/transaction.dart | 2 + .../services/transactions_controller.dart | 1 + trackeroo/pubspec.lock | 8 ---- trackeroo/pubspec.yaml | 4 -- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/trackeroo/lib/frontend/views/details_view.dart b/trackeroo/lib/frontend/views/details_view.dart index e37cf15..ceb94ee 100644 --- a/trackeroo/lib/frontend/views/details_view.dart +++ b/trackeroo/lib/frontend/views/details_view.dart @@ -131,7 +131,7 @@ class _DetailsViewState extends State<DetailsView> { context: context, builder: (context) => StatefulBuilder( builder: (BuildContext context, StateSetter setState) => Container( - height: 650.0, + // height: 650.0, width: double.infinity, padding: const EdgeInsets.symmetric(horizontal: 20.0), child: Column( diff --git a/trackeroo/lib/frontend/views/edit_transaction_view.dart b/trackeroo/lib/frontend/views/edit_transaction_view.dart index cdd6f66..bd8dd80 100644 --- a/trackeroo/lib/frontend/views/edit_transaction_view.dart +++ b/trackeroo/lib/frontend/views/edit_transaction_view.dart @@ -51,11 +51,9 @@ class _EditTransactionViewState extends State<EditTransactionView> { scrolledUnderElevation: 0.0, actions: [ IconButton( - onPressed: () async => { - if(await saveChanges()) Navigator.pop(context), - }, + onPressed: () => Navigator.pop(context), padding: const EdgeInsets.all(12.0), - icon: const Icon(Icons.check_rounded) + icon: const Icon(Icons.close_rounded) ), const SizedBox(width: 16.0) ], @@ -233,10 +231,41 @@ class _EditTransactionViewState extends State<EditTransactionView> { ) ) ), + floatingActionButton: FloatingActionButton( + onPressed: () async => { + if(await saveChanges()) Navigator.pop(context), + }, + child: Icon(transExists ? Icons.save_rounded : Icons.check_rounded), + ), ); } Future<bool> saveChanges() async { + if(_titleController.text.isEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Title cannot be empty') + ) + ); + return false; + } + if(_amountController.text.isEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Amount cannot be empty') + ) + ); + return false; + } + if(categoryId.isEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Category cannot be empty') + ) + ); + return false; + } + if(transExists) { widget.transaction!.title = _titleController.text; widget.transaction!.amount = isExpense ? -double.parse(_amountController.text) : double.parse(_amountController.text); diff --git a/trackeroo/lib/logic/models/transaction.dart b/trackeroo/lib/logic/models/transaction.dart index e25781a..90ecacc 100644 --- a/trackeroo/lib/logic/models/transaction.dart +++ b/trackeroo/lib/logic/models/transaction.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; part 'transaction.g.dart'; @@ -32,6 +33,7 @@ class Transaction { factory Transaction.fromJson(Map<String, dynamic> parsedJson) { return Transaction( + id: UniqueKey().hashCode, title: parsedJson['title'], amount: parsedJson['amount'], categoryId: parsedJson['category_id'], diff --git a/trackeroo/lib/logic/services/transactions_controller.dart b/trackeroo/lib/logic/services/transactions_controller.dart index 3b365c1..ec26929 100644 --- a/trackeroo/lib/logic/services/transactions_controller.dart +++ b/trackeroo/lib/logic/services/transactions_controller.dart @@ -38,6 +38,7 @@ class TransactionsController extends ChangeNotifier { await transactionsBox.put(transaction.id, transaction); transactionsList = transactionsBox.values.toList(); } catch (e) { + print(e); return false; } return true; diff --git a/trackeroo/pubspec.lock b/trackeroo/pubspec.lock index 4a35c63..1acc7c9 100644 --- a/trackeroo/pubspec.lock +++ b/trackeroo/pubspec.lock @@ -161,14 +161,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be - url: "https://pub.dev" - source: hosted - version: "1.0.5" dart_style: dependency: transitive description: diff --git a/trackeroo/pubspec.yaml b/trackeroo/pubspec.yaml index e5b06fb..eef35ba 100644 --- a/trackeroo/pubspec.yaml +++ b/trackeroo/pubspec.yaml @@ -31,10 +31,6 @@ dependencies: flutter: sdk: flutter - - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 fl_chart: ^0.62.0 hive: ^2.2.3 hive_flutter: ^1.1.0 -- GitLab