From 0fad285991d83ac47b75a5e5519077610fe8a9f5 Mon Sep 17 00:00:00 2001 From: dreautall <109872040+dreautall@users.noreply.github.com> Date: Wed, 3 Jan 2024 18:11:46 +0000 Subject: [PATCH] implement piggy bank groups resolves #221 --- devtools_options.yaml | 1 + lib/pages/home/piggybank.dart | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 devtools_options.yaml diff --git a/devtools_options.yaml b/devtools_options.yaml new file mode 100644 index 00000000..7e7e7f67 --- /dev/null +++ b/devtools_options.yaml @@ -0,0 +1 @@ +extensions: diff --git a/lib/pages/home/piggybank.dart b/lib/pages/home/piggybank.dart index c39d126f..cb3ac1a4 100644 --- a/lib/pages/home/piggybank.dart +++ b/lib/pages/home/piggybank.dart @@ -31,7 +31,7 @@ class _HomePiggybankState extends State with AutomaticKeepAliveClientMixin { final Logger log = Logger("Pages.Home.Piggybank"); - final int _numberOfItemsPerRequest = 50; + final int _numberOfItemsPerRequest = 100; final PagingController _pagingController = PagingController( firstPageKey: 1, @@ -58,6 +58,7 @@ class _HomePiggybankState extends State final FireflyIii api = context.read().api; final Response respAccounts = await api.v1PiggyBanksGet( page: pageKey, + limit: _numberOfItemsPerRequest, ); if (!respAccounts.isSuccessful || respAccounts.body == null) { if (context.mounted) { @@ -75,6 +76,9 @@ class _HomePiggybankState extends State if (mounted) { final List piggyList = respAccounts.body!.data; + piggyList.sortByCompare( + (PiggyBankRead element) => element.attributes.objectGroupOrder, + (int? a, int? b) => (a ?? 0).compareTo(b ?? 0)); final bool isLastPage = piggyList.length < _numberOfItemsPerRequest; if (isLastPage) { _pagingController.appendLastPage(piggyList); @@ -97,12 +101,30 @@ class _HomePiggybankState extends State super.build(context); log.finest(() => "build()"); + int lastGroupId = -1; + return RefreshIndicator( onRefresh: () => Future.sync(() => _pagingController.refresh()), child: PagedListView( pagingController: _pagingController, builderDelegate: PagedChildBuilderDelegate( itemBuilder: (BuildContext context, PiggyBankRead piggy, int index) { + Widget? groupHeader; + final int groupId = + (int.tryParse(piggy.attributes.objectGroupId ?? "") ?? 0); + if (groupId != lastGroupId && + groupId != 0 && + (piggy.attributes.objectGroupTitle ?? "").isNotEmpty) { + lastGroupId = groupId; + groupHeader = Padding( + padding: const EdgeInsets.only(top: 16, left: 16), + child: Text( + piggy.attributes.objectGroupTitle ?? "(no title)", + textAlign: TextAlign.start, + style: Theme.of(context).textTheme.labelLarge, + ), + ); + } final double currentAmount = double.tryParse(piggy.attributes.currentAmount ?? "") ?? 0; final CurrencyRead currency = CurrencyRead( @@ -121,7 +143,9 @@ class _HomePiggybankState extends State return const SizedBox.shrink(); } return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ + groupHeader ?? const SizedBox.shrink(), ListTile( title: Text(piggy.attributes.name), subtitle: (piggy.attributes.accountName != null)