Skip to content

Commit

Permalink
Merge pull request #296 from enrique-lozano/fix/scrollable-modals
Browse files Browse the repository at this point in the history
Scrolling issues and confirmation literals
  • Loading branch information
enrique-lozano authored Jan 10, 2025
2 parents 3f3d88f + 6519083 commit ac36da4
Show file tree
Hide file tree
Showing 35 changed files with 865 additions and 395 deletions.
47 changes: 10 additions & 37 deletions lib/app/accounts/account_selector.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:drift/drift.dart' as drift;
import 'package:flutter/material.dart';
import 'package:monekin/app/categories/selectors/draggableScrollableKeyboardAware.mixin.dart';
import 'package:monekin/core/database/app_db.dart';
import 'package:monekin/core/database/services/account/account_service.dart';
import 'package:monekin/core/models/account/account.dart';
Expand Down Expand Up @@ -42,53 +43,26 @@ class AccountSelectorModal extends StatefulWidget {
State<AccountSelectorModal> createState() => _AccountSelectorModalState();
}

class _AccountSelectorModalState extends State<AccountSelectorModal> {
class _AccountSelectorModalState extends State<AccountSelectorModal>
with DraggableScrollableKeyboardAware {
late List<Account> selectedAccounts;

String searchValue = '';

final DraggableScrollableController controller =
DraggableScrollableController();

@override
void initState() {
super.initState();

selectedAccounts = [...widget.selectedAccounts];
}

@override
void dispose() {
controller.dispose();

super.dispose();
}

_moveSheetTo(double position) {
if (controller.isAttached && mounted) {
controller.jumpTo(position);
}
}

@override
Widget build(BuildContext context) {
final t = Translations.of(context);

final bottomInsets = MediaQuery.of(context).viewInsets.bottom;

if (bottomInsets > 0) {
_moveSheetTo(1);
} else {
_moveSheetTo(0.65);
}

return DraggableScrollableSheet(
controller: controller,
expand: false,
return buildDraggableSheet(
minChildSize: 0.64,
initialChildSize: 0.65,
snap: true,
snapSizes: const [0.65],
defaultSize: 0.65,
builder: (context, scrollController) {
return ModalContainer(
title: widget.allowMultiSelection
Expand Down Expand Up @@ -128,9 +102,8 @@ class _AccountSelectorModalState extends State<AccountSelectorModal> {
border: const UnderlineInputBorder(),
),
onChanged: (value) {
setState(() {
searchValue = value;
});
searchValue = value;
rebuild();
},
),
if (widget.allowMultiSelection)
Expand Down Expand Up @@ -169,7 +142,7 @@ class _AccountSelectorModalState extends State<AccountSelectorModal> {
: null,
tristate: true,
title: Text(
t.general.select_all,
t.ui_actions.select_all,
style: const TextStyle(fontWeight: FontWeight.w700),
),
enabled: snapshot.hasData && snapshot.data!.isNotEmpty,
Expand All @@ -182,7 +155,7 @@ class _AccountSelectorModalState extends State<AccountSelectorModal> {
(selAcc) => snapshot.data!.map((e) => e.id).contains(selAcc.id));
}

setState(() {});
rebuild();
},
);
}
Expand Down Expand Up @@ -247,7 +220,7 @@ class _AccountSelectorModalState extends State<AccountSelectorModal> {
.removeWhere((element) => element.id == account.id);
}

setState(() {});
rebuild();
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/app/accounts/details/account_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {
CardWithHeader(
title: 'Info',
footer: CardFooterWithSingleButton(
text: t.general.edit,
text: t.ui_actions.edit,
onButtonClick: () => RouteUtils.pushRoute(
context, AccountFormPage(account: account)),
),
Expand Down Expand Up @@ -378,7 +378,7 @@ class _ArchiveWarnDialogState extends State<ArchiveWarnDialog> {
return ModalContainer(
title: t.account.close.title,
footer: BottomSheetFooter(
submitText: t.general.continue_text,
submitText: t.ui_actions.continue_text,
submitIcon: Icons.check,
onSaved: !hasNoTransactions || widget.currentBalance != 0
? null
Expand Down
8 changes: 4 additions & 4 deletions lib/app/accounts/details/account_details_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class AccountDetailsActions {

return [
ListTileActionItem(
label: t.general.edit,
label: t.ui_actions.edit,
icon: Icons.edit,
onClick: () =>
RouteUtils.pushRoute(context, AccountFormPage(account: account)),
Expand Down Expand Up @@ -84,7 +84,7 @@ abstract class AccountDetailsActions {
account: account, currentBalance: currentBalance);
}),
ListTileActionItem(
label: t.general.delete,
label: t.ui_actions.delete,
icon: Icons.delete,
role: ListTileActionRole.delete,
onClick: () {
Expand All @@ -105,7 +105,7 @@ abstract class AccountDetailsActions {
contentParagraphs: [
Text(t.account.reopen_descr),
],
confirmationText: t.general.confirm,
confirmationText: t.ui_actions.confirm,
).then((isConfirmed) {
AccountService.instance
.updateAccount(
Expand Down Expand Up @@ -148,7 +148,7 @@ abstract class AccountDetailsActions {
context,
dialogTitle: t.account.delete.warning_header,
contentParagraphs: [Text(t.account.delete.warning_text)],
confirmationText: t.general.continue_text,
confirmationText: t.ui_actions.continue_text,
showCancelButton: true,
icon: Icons.delete,
).then((isConfirmed) {
Expand Down
4 changes: 2 additions & 2 deletions lib/app/budgets/budget_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ class _BudgetDetailsPageState extends State<BudgetDetailsPage> {
},
),
ListTileActionItem(
label: t.general.delete,
label: t.ui_actions.delete,
icon: Icons.delete,
role: ListTileActionRole.delete,
onClick: () {
confirmDialog(
context,
dialogTitle: t.budgets.delete,
contentParagraphs: [Text(t.budgets.delete_warning)],
confirmationText: t.general.confirm,
confirmationText: t.ui_actions.confirm,
icon: Icons.delete,
).then((confirmed) {
if (confirmed != true) return;
Expand Down
8 changes: 4 additions & 4 deletions lib/app/categories/form/category_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class _CategoryFormPageState extends State<CategoryFormPage> {
}
},
icon: const Icon(Icons.check),
label: Text(t.general.save_changes),
label: Text(t.ui_actions.save_changes),
),
)
],
Expand Down Expand Up @@ -178,7 +178,7 @@ class _CategoryFormPageState extends State<CategoryFormPage> {
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.delete),
minLeadingWidth: 26,
title: Text(t.general.delete),
title: Text(t.ui_actions.delete),
))
];
},
Expand Down Expand Up @@ -337,7 +337,7 @@ class _CategoryFormPageState extends State<CategoryFormPage> {
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.edit),
minLeadingWidth: 26,
title: Text(t.general.edit),
title: Text(t.ui_actions.edit),
)),
const PopupMenuDivider(),
PopupMenuItem(
Expand All @@ -346,7 +346,7 @@ class _CategoryFormPageState extends State<CategoryFormPage> {
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.delete),
minLeadingWidth: 26,
title: Text(t.general.delete),
title: Text(t.ui_actions.delete),
))
];
},
Expand Down
53 changes: 13 additions & 40 deletions lib/app/categories/selectors/category_multi_selector.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:drift/drift.dart' as drift;
import 'package:flutter/material.dart';
import 'package:monekin/app/categories/selectors/draggableScrollableKeyboardAware.mixin.dart';
import 'package:monekin/core/database/services/category/category_service.dart';
import 'package:monekin/core/extensions/string.extension.dart';
import 'package:monekin/core/models/category/category.dart';
Expand Down Expand Up @@ -35,57 +36,29 @@ class CategoryMultiSelectorModal extends StatefulWidget {
_CategoryMultiSelectorModalState();
}

class _CategoryMultiSelectorModalState
extends State<CategoryMultiSelectorModal> {
class _CategoryMultiSelectorModalState extends State<CategoryMultiSelectorModal>
with DraggableScrollableKeyboardAware {
late List<Category> selectedCategories;

String searchValue = '';

/// IDs of the category tiles that are expanded
Set<String> expandedCategoriesTiles = {};

final DraggableScrollableController controller =
DraggableScrollableController();

@override
void initState() {
super.initState();

selectedCategories = [...widget.selectedCategories];
}

@override
void dispose() {
controller.dispose();

super.dispose();
}

_moveSheetTo(double position) {
if (controller.isAttached && mounted) {
controller.jumpTo(position);
}
}

@override
Widget build(BuildContext context) {
final t = Translations.of(context);

final bottomInsets = MediaQuery.of(context).viewInsets.bottom;

if (bottomInsets > 0) {
_moveSheetTo(1);
} else {
_moveSheetTo(0.65);
}

return DraggableScrollableSheet(
controller: controller,
expand: false,
return buildDraggableSheet(
defaultSize: 0.65,
minChildSize: 0.64,
initialChildSize: 0.65,
snap: true,
snapSizes: const [0.65],
builder: (context, sc) {
return ModalContainer(
title: t.categories.select.title,
Expand Down Expand Up @@ -119,9 +92,9 @@ class _CategoryMultiSelectorModalState
border: const UnderlineInputBorder(),
),
onChanged: (value) {
setState(() {
searchValue = value;
});
searchValue = value;

rebuild();
},
),
buildSelectAllButton(snapshot),
Expand Down Expand Up @@ -187,7 +160,7 @@ class _CategoryMultiSelectorModalState
.removeWhere((e) => e == category.id);
}

setState(() {});
rebuild();
},
leading:
IconDisplayer.fromCategory(context, category: category),
Expand All @@ -209,7 +182,7 @@ class _CategoryMultiSelectorModalState
.contains(e.id));
}

setState(() {});
rebuild();
},
),
title: Row(
Expand Down Expand Up @@ -278,7 +251,7 @@ class _CategoryMultiSelectorModalState
selectedCategories.removeWhere((e) => e.id == category.id);
}

setState(() {});
rebuild();
},
),
);
Expand All @@ -302,7 +275,7 @@ class _CategoryMultiSelectorModalState
: null,
tristate: true,
title: Text(
t.general.select_all,
t.ui_actions.select_all,
style: const TextStyle(fontWeight: FontWeight.w700),
),
enabled: snapshot.hasData && snapshot.data!.isNotEmpty,
Expand All @@ -315,7 +288,7 @@ class _CategoryMultiSelectorModalState
(selAcc) => snapshot.data!.map((e) => e.id).contains(selAcc.id));
}

setState(() {});
rebuild();
},
);
}
Expand Down
Loading

0 comments on commit ac36da4

Please sign in to comment.