budget mockup, account settings & transactions filter
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tunas/pages/budgets/widgets/budgets_actions.dart';
|
||||
import 'package:tunas/pages/budgets/widgets/month_distribution.dart';
|
||||
|
||||
class BudgetsPage extends StatelessWidget {
|
||||
const BudgetsPage({super.key});
|
||||
@@ -14,6 +15,7 @@ class BudgetsPage extends StatelessWidget {
|
||||
child: const Column(
|
||||
children: [
|
||||
BudgetsActions(),
|
||||
MonthDistribution()
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
73
lib/pages/budgets/widgets/month_distribution.dart
Normal file
73
lib/pages/budgets/widgets/month_distribution.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tunas/pages/common/titled_container.dart';
|
||||
|
||||
class MonthDistribution extends StatelessWidget {
|
||||
const MonthDistribution({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
TitledContainer(
|
||||
title: 'Prepare',
|
||||
child: Column(
|
||||
children: [
|
||||
Text('Money to spare: 2300 €'),
|
||||
Text('Loyer'),
|
||||
Slider(
|
||||
min: 0,
|
||||
max: 2300,
|
||||
value: 200,
|
||||
onChanged: (value) => {},
|
||||
),
|
||||
Text('Loyer'),
|
||||
Slider(
|
||||
min: 0,
|
||||
max: 2300,
|
||||
value: 200,
|
||||
onChanged: (value) => {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TitledContainer(
|
||||
title: 'Compare',
|
||||
height: 500,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Budget'),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () => {},
|
||||
icon: const Icon(Icons.skip_previous)
|
||||
),
|
||||
Text('Fev 2024'),
|
||||
IconButton(
|
||||
onPressed: () => {},
|
||||
icon: const Icon(Icons.skip_next)
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,35 @@ import 'package:flutter/material.dart';
|
||||
class TitledContainer extends StatelessWidget {
|
||||
final String title;
|
||||
final Widget child;
|
||||
final Widget? action;
|
||||
final double? height;
|
||||
final double? width;
|
||||
|
||||
const TitledContainer({super.key, required this.title, required this.child});
|
||||
const TitledContainer({super.key, required this.title, required this.child, this.action, this.height, this.width});
|
||||
|
||||
Widget _computeTitleRow() {
|
||||
List<Widget> children = [];
|
||||
children.add(Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w300,
|
||||
fontSize: 20,
|
||||
),
|
||||
));
|
||||
Widget? actionWidget = action;
|
||||
if (actionWidget != null) {
|
||||
children.add(actionWidget);
|
||||
}
|
||||
return Row(
|
||||
children: children
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: height,
|
||||
width: width,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
@@ -36,13 +59,7 @@ class TitledContainer extends StatelessWidget {
|
||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w300,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
child: _computeTitleRow()
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -2,28 +2,71 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/account/account_bloc.dart';
|
||||
import 'package:tunas/pages/common/titled_container.dart';
|
||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
||||
|
||||
class AccountSettings extends StatelessWidget {
|
||||
const AccountSettings({super.key});
|
||||
|
||||
List<Widget> _computeCategoryList(List<String> subAccounts) {
|
||||
return subAccounts.map((subAccount) => Row(
|
||||
List<Widget> _computeCategoryList(BuildContext context, List<Account> accounts) {
|
||||
return accounts.map((account) => Row(
|
||||
children: [
|
||||
Text(subAccount),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.palette),
|
||||
color: account.rgbToColor(),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => context.read<AccountBloc>().add(AccountEditSaving(account, !account.saving)),
|
||||
icon: const Icon(Icons.savings),
|
||||
color: account.saving ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||
),
|
||||
Container(width: 5),
|
||||
Expanded(
|
||||
child: Text(account.label)
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.edit),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => context.read<AccountBloc>().add(AccountRemove(account)),
|
||||
icon: const Icon(Icons.delete),
|
||||
),
|
||||
],
|
||||
)).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AccountBloc, AccountState>(
|
||||
return BlocConsumer<AccountBloc, AccountState>(
|
||||
listener: (context, state) {
|
||||
if (state is AccountRemoveSucess) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
backgroundColor: Colors.green,
|
||||
content: Text('Account succesfuly removed !'),
|
||||
)
|
||||
);
|
||||
} else if (state is AccountRemoveFail) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
backgroundColor: Colors.red,
|
||||
content: Text('Cannot remove account. Still present on some transactions.'),
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) => TitledContainer(
|
||||
title: "Accounts",
|
||||
action: IconButton(
|
||||
onPressed: () => context.read<AccountBloc>().add(AccountAdd()),
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _computeCategoryList(state.accounts.map((account) => account.label).toList()),
|
||||
children: _computeCategoryList(context, state.accounts),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -17,8 +17,8 @@ class CategoriesSettings extends StatelessWidget {
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.savings),
|
||||
color: category.saving ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||
icon: const Icon(Icons.swap_horiz),
|
||||
color: category.transfert ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
|
||||
35
lib/pages/transactions/widgets/category_filter.dart
Normal file
35
lib/pages/transactions/widgets/category_filter.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart' as tunas_category;
|
||||
|
||||
class CategoryFilter extends StatelessWidget {
|
||||
const CategoryFilter({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final categoryState = context.watch<CategoryBloc>().state;
|
||||
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||
buildWhen: (previous, current) => previous.categoryFilter != current.categoryFilter,
|
||||
builder: (context, state) => SizedBox(
|
||||
width: 500,
|
||||
child: DropdownButtonFormField<tunas_category.Category>(
|
||||
value: state.categoryFilter,
|
||||
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterCategory(value!)),
|
||||
items: categoryState.categories.map((e) => DropdownMenuItem(value: e, child: Text(e.label))).toList(),
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.filter_alt_off),
|
||||
onPressed: () => context.read<TransactionBloc>().add(const TransactionFilterCategory(null)),
|
||||
),
|
||||
hintText: 'Category',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/category_filter.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||
|
||||
class TransactionsActions extends StatelessWidget {
|
||||
@@ -22,6 +23,7 @@ class TransactionsActions extends StatelessWidget {
|
||||
fontSize: 35,
|
||||
),
|
||||
),
|
||||
CategoryFilter(),
|
||||
IconButton(
|
||||
onPressed: () => TransactionAddDialog.show(context, null),
|
||||
icon: const Icon(
|
||||
|
||||
@@ -9,13 +9,13 @@ class TransactionsList extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||
buildWhen: (previous, current) => previous.transactionsLines != current.transactionsLines,
|
||||
buildWhen: (previous, current) => previous.transactionsLinesFiltered != current.transactionsLinesFiltered,
|
||||
builder: (context, state) => Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: state.transactionsLines.length,
|
||||
itemCount: state.transactionsLinesFiltered.length,
|
||||
itemBuilder: (context, index) => TransactionLine(
|
||||
transaction: state.transactionsLines[index].transaction,
|
||||
subTotal: state.transactionsLines[index].subTotal
|
||||
transaction: state.transactionsLinesFiltered[index].transaction,
|
||||
subTotal: state.transactionsLinesFiltered[index].subTotal
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user