Skip to content

Commit

Permalink
0 amount update bug fix (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk authored May 12, 2024
1 parent 650f05b commit cee7f04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/controllers/edit_assets/edit_asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import 'package:how_much/custom_types.dart';

class EditAssetController extends GetxController {
final _selectedCategory = "crypto".obs;
final amount = 0.0.obs;
final amount = Rxn<double>();

final TextEditingController amountTextController = TextEditingController();

EditAssetController() {
// Listen for changes in the text fields and update them accordingly
amountTextController.addListener(() {
double? parsedAmount =
amount.value =
double.tryParse(amountTextController.text.replaceAll(',', '.'));
amount.value = parsedAmount ?? 0.0;
});
}

Expand All @@ -30,7 +29,7 @@ class EditAssetController extends GetxController {
void resetValues() {
_selectedCategory.value = "crypto";

amount.value = 0.0;
amount.value = null;
amountTextController.text = "";
}

Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/widgets/drawer_contents/edit_asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class AssetEdit extends StatelessWidget {
small: true,
onTap: () {
{
double newAmount = editAssetController.amount.value;
if (newAmount != 0) {
double? newAmount = editAssetController.amount.value;
if (newAmount != null) {
userAssetsController.updateAssetAmount(category,
assetType, assetId, newAmount - currentAmount);
}
Expand Down

0 comments on commit cee7f04

Please sign in to comment.