Skip to content

Commit 6a91625

Browse files
committed
refactor: list tile in one shared file
- Add a PanelListTile that does the job for both AccountListTile and CategoriesListTile - Use of ExpansionPanel instead of custom implementation
1 parent 4b3b2c9 commit 6a91625

File tree

10 files changed

+348
-734
lines changed

10 files changed

+348
-734
lines changed

lib/pages/transactions/transactions_page.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
33

44
import '../../providers/transactions_provider.dart';
55
import '../../ui/snack_bars/transactions_snack_bars.dart';
6+
import '../../ui/widgets/transaction_type_button.dart';
67
import 'widgets/accounts_tab.dart';
78
import 'widgets/categories_tab.dart';
89
import 'widgets/custom_sliver_delegate.dart';
@@ -33,6 +34,8 @@ class _TransactionsPageState extends ConsumerState<TransactionsPage>
3334
void initState() {
3435
super.initState();
3536
_tabController = TabController(vsync: this, length: myTabs.length);
37+
// Reset the selected index when switch tab
38+
_tabController.addListener(() => ref.invalidate(selectedListIndexProvider));
3639
_scrollController = ScrollController();
3740
}
3841

lib/pages/transactions/widgets/account_list_tile.dart

Lines changed: 0 additions & 269 deletions
This file was deleted.

lib/pages/transactions/widgets/accounts_pie_chart.dart

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import '../../../ui/widgets/rounded_icon.dart';
88
import '../../../model/bank_account.dart';
99
import '../../../providers/currency_provider.dart';
1010
import '../../../ui/device.dart';
11-
import 'accounts_tab.dart';
11+
import '../../../ui/widgets/transaction_type_button.dart';
1212

1313
class AccountsPieChart extends ConsumerWidget {
1414
const AccountsPieChart({
@@ -24,7 +24,7 @@ class AccountsPieChart extends ConsumerWidget {
2424

2525
@override
2626
Widget build(BuildContext context, WidgetRef ref) {
27-
final selectedAccountIndex = ref.watch(selectedAccountIndexProvider);
27+
final selectedIndex = ref.watch(selectedListIndexProvider);
2828
final currencyState = ref.watch(currencyStateNotifier);
2929
return SizedBox(
3030
height: 200,
@@ -37,7 +37,7 @@ class AccountsPieChart extends ConsumerWidget {
3737
centerSpaceRadius: 70,
3838
sectionsSpace: 0,
3939
borderData: FlBorderData(show: false),
40-
sections: showingSections(selectedAccountIndex),
40+
sections: showingSections(selectedIndex),
4141
pieTouchData: PieTouchData(
4242
touchCallback: (FlTouchEvent event, pieTouchResponse) {
4343
// expand category when tapped
@@ -46,7 +46,7 @@ class AccountsPieChart extends ConsumerWidget {
4646
pieTouchResponse.touchedSection == null) {
4747
return;
4848
}
49-
ref.read(selectedAccountIndexProvider.notifier).state =
49+
ref.read(selectedListIndexProvider.notifier).state =
5050
pieTouchResponse.touchedSection!.touchedSectionIndex;
5151
},
5252
),
@@ -55,30 +55,27 @@ class AccountsPieChart extends ConsumerWidget {
5555
Column(
5656
mainAxisSize: MainAxisSize.min,
5757
children: [
58-
(selectedAccountIndex != -1)
59-
? RoundedIcon(
60-
icon: accountIconList[
61-
accounts[selectedAccountIndex].symbol] ??
62-
Icons.swap_horiz_rounded,
63-
backgroundColor: accountColorList[
64-
accounts[selectedAccountIndex].color],
65-
padding: const EdgeInsets.all(Sizes.sm),
66-
)
67-
: const SizedBox(),
58+
if (selectedIndex != -1)
59+
RoundedIcon(
60+
icon: accountIconList[accounts[selectedIndex].symbol] ??
61+
Icons.swap_horiz_rounded,
62+
backgroundColor:
63+
accountColorList[accounts[selectedIndex].color],
64+
padding: const EdgeInsets.all(Sizes.sm),
65+
),
6866
Text(
69-
(selectedAccountIndex != -1)
70-
? "${amounts[accounts[selectedAccountIndex].id]!.toStringAsFixed(2)} ${currencyState.selectedCurrency.symbol}"
67+
(selectedIndex != -1)
68+
? "${amounts[accounts[selectedIndex].id]!.toStringAsFixed(2)} ${currencyState.selectedCurrency.symbol}"
7169
: "${total.toStringAsFixed(2)} ${currencyState.selectedCurrency.symbol}",
7270
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
73-
color: ((selectedAccountIndex != -1 &&
74-
amounts[accounts[selectedAccountIndex].id]! >
75-
0) ||
76-
(selectedAccountIndex == -1 && total > 0))
71+
color: ((selectedIndex != -1 &&
72+
amounts[accounts[selectedIndex].id]! > 0) ||
73+
(selectedIndex == -1 && total > 0))
7774
? green
7875
: red),
7976
),
80-
(selectedAccountIndex != -1)
81-
? Text(accounts[selectedAccountIndex].name)
77+
(selectedIndex != -1)
78+
? Text(accounts[selectedIndex].name)
8279
: const Text("Total"),
8380
],
8481
),

0 commit comments

Comments
 (0)