Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: Prevent user to create budgets for income categories #184

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/pages/categories/add_category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import '../../providers/categories_provider.dart';
final showCategoryIconsProvider = StateProvider.autoDispose<bool>((ref) => false);

class AddCategory extends ConsumerStatefulWidget {
const AddCategory({super.key});
final bool hideIncome;

const AddCategory({super.key, this.hideIncome = false});

@override
ConsumerState<AddCategory> createState() => _AddCategoryState();
Expand Down Expand Up @@ -98,7 +100,10 @@ class _AddCategoryState extends ConsumerState<AddCategory> with Functions {
value: categoryType,
underline: const SizedBox(),
isExpanded: true,
items: CategoryTransactionType.values.map((CategoryTransactionType type) {
items: (widget.hideIncome
? [CategoryTransactionType.expense] // Only show 'expense' if true
: CategoryTransactionType.values) // Otherwise, show all values
.map((CategoryTransactionType type) {
return DropdownMenuItem<CategoryTransactionType>(
value: type,
child: Text(
Expand Down
10 changes: 9 additions & 1 deletion lib/pages/onboarding_page/widgets/budget_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../categories/add_category.dart';
import '/constants/constants.dart';
import '/constants/style.dart';
import '/model/budget.dart';
Expand Down Expand Up @@ -84,7 +85,14 @@ class _BudgetSetupState extends ConsumerState<BudgetSetup> {
));
} else {
return GestureDetector(
onTap: () => Navigator.of(context).pushNamed('/add-category'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddCategory(hideIncome: true),
),
);
},
child: const AddCategoryButton(),
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/pages/planning_page/manage_budget_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class _ManageBudgetPageState extends ConsumerState<ManageBudgetPage> {

void _loadCategories() async {
categories = await ref.read(categoriesProvider.notifier).getCategories();
categories.removeWhere((element) => element.type == CategoryTransactionType.income);
budgets = await ref.read(budgetsProvider.notifier).getBudgets();
setState(() {});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/categories_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final selectedCategoryProvider =
StateProvider<CategoryTransaction?>((ref) => null);

final categoryTypeProvider = StateProvider<CategoryTransactionType>(
(ref) => CategoryTransactionType.income); //default as 'Income'
(ref) => CategoryTransactionType.expense); //default as 'Expense'

final categoryIconProvider =
StateProvider<String>((ref) => iconList.keys.first);
Expand Down
Loading