Skip to content

Commit

Permalink
add refresh functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
dreautall committed Oct 26, 2024
1 parent 911bca1 commit 25dae82
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/pages/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ class _AccountDetailsState extends State<AccountDetails>
child: PagedListView<int, AccountRead>(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<AccountRead>(
itemBuilder: accountRowBuilder,
itemBuilder: (BuildContext context, AccountRead item, int index) =>
accountRowBuilder(context, item, index, _pagingController),
),
),
);
Expand Down
19 changes: 16 additions & 3 deletions lib/pages/home/accounts/row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ import 'package:logging/logging.dart';
import 'package:provider/provider.dart';

import 'package:chopper/chopper.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';

import 'package:waterflyiii/auth.dart';
import 'package:waterflyiii/extensions.dart';
import 'package:waterflyiii/generated/swagger_fireflyiii_api/firefly_iii.swagger.dart';
import 'package:waterflyiii/pages/home/transactions.dart';
import 'package:waterflyiii/widgets/fabs.dart';

Widget accountRowBuilder(BuildContext context, AccountRead account, int index) {
Widget accountRowBuilder(
BuildContext context,
AccountRead account,
int index,
PagingController<int, AccountRead> pagingController,
) {
String name = account.attributes.name;
late double currentAmount;
if (account.attributes.type == ShortAccountTypeProperty.liability) {
currentAmount = double.tryParse(account.attributes.currentDebt ?? "") ?? 0;
Expand Down Expand Up @@ -99,7 +106,10 @@ Widget accountRowBuilder(BuildContext context, AccountRead account, int index) {
}
return OpenContainer(
openBuilder: (BuildContext context, Function closedContainer) =>
AccountTXpage(account: account),
AccountTXpage(
account: account,
nameUpdateFunc: (_) => pagingController.refresh(),
),
openColor: Theme.of(context).cardColor,
closedColor: Theme.of(context).cardColor,
closedShape: const RoundedRectangleBorder(
Expand All @@ -111,7 +121,7 @@ Widget accountRowBuilder(BuildContext context, AccountRead account, int index) {
closedElevation: 0,
closedBuilder: (BuildContext context, Function openContainer) => ListTile(
title: Text(
account.attributes.name,
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Expand Down Expand Up @@ -165,9 +175,11 @@ class AccountTXpage extends StatefulWidget {
const AccountTXpage({
super.key,
required this.account,
required this.nameUpdateFunc,
});

final AccountRead account;
final Function(String) nameUpdateFunc;

@override
State<AccountTXpage> createState() => _AccountTXpageState();
Expand Down Expand Up @@ -234,6 +246,7 @@ class _AccountTXpageState extends State<AccountTXpage> {
apiThrowErrorIfEmpty(response, mounted ? context : null);

_name = response.body!.data.attributes.name;
widget.nameUpdateFunc(_name);
} catch (e, stackTrace) {
log.severe("Error while submitting new name to API", e, stackTrace);
}
Expand Down
9 changes: 8 additions & 1 deletion lib/pages/home/accounts/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ class _AccountSearchState extends State<AccountSearch> {
? PagedListView<int, AccountRead>(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<AccountRead>(
itemBuilder: accountRowBuilder,
itemBuilder:
(BuildContext context, AccountRead item, int index) =>
accountRowBuilder(
context,
item,
index,
_pagingController,
),
),
)
: const SizedBox.expand(),
Expand Down

0 comments on commit 25dae82

Please sign in to comment.