Skip to content

Commit

Permalink
Merge pull request #535 from lyskouski/CR-532
Browse files Browse the repository at this point in the history
[#532] [CR] App returns to Home instead of previous screen
  • Loading branch information
lyskouski authored Dec 12, 2024
2 parents fcb27ee + 8157118 commit 0bad4e2
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 92 deletions.
7 changes: 5 additions & 2 deletions lib/_classes/controller/payments_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:app_finance/_classes/structure/payment_app_data.dart';
import 'package:app_finance/_configs/budget_type.dart';
import 'package:app_finance/_ext/data_ext.dart';
import 'package:app_finance/_ext/date_time_ext.dart';
import 'package:flutter/foundation.dart';
import 'package:home_widget/home_widget.dart';

class PaymentsController {
Expand Down Expand Up @@ -42,8 +43,10 @@ class PaymentsController {
}
}
// TODO: create iOS Widget
if (Platform.isAndroid) {
_updateWidget();
if (!kIsWeb) {
if (Platform.isAndroid) {
_updateWidget();
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions lib/_classes/math/total_recalculation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class TotalRecalculation extends AbstractRecalculation {
if (summary == null) {
return [];
}
return [AppDataType.bills, AppDataType.budgets, AppDataType.invoice].contains(type)
? summary.listActual
: summary.list;
return [AppDataType.bills, AppDataType.invoice].contains(type) ? summary.listActual : summary.list;
}

Future<void> updateTotal(AppDataType type, SummaryAppData? summary, HashMap<String, dynamic> hashTable) async {
Expand Down
1 change: 0 additions & 1 deletion lib/pages/_interfaces/abstract_add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ abstract class AbstractAddPageState<T extends AbstractAddPage> extends AbstractP
}
updateStorage();
nav.pop();
nav.pop();
});
}
}
18 changes: 11 additions & 7 deletions lib/pages/_interfaces/abstract_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@ abstract class AbstractPageState<T extends StatefulWidget> extends State<T> {
),
if (!isWide)
Builder(
builder: (context) => ToolbarButtonWidget(
icon: Icons.menu,
color: Colors.white70,
tooltip: AppLocale.labels.navigationTooltip,
onPressed: () => Scaffold.of(context).openDrawer(),
),
),
builder: (context) {
final scaffold = Scaffold.of(context);
return ToolbarButtonWidget(
icon: Icons.menu,
color: Colors.white70,
tooltip: AppLocale.labels.navigationTooltip,
onPressed: () => AppDesign.isRightToLeft() ? scaffold.openEndDrawer() : scaffold.openDrawer(),
);
},
)
];
}

Expand Down Expand Up @@ -272,6 +275,7 @@ abstract class AbstractPageState<T extends StatefulWidget> extends State<T> {
return Scaffold(
appBar: display.isBottom ? null : buildBar(context, constraints),
drawer: buildDrawer(),
endDrawer: buildDrawer(),
floatingActionButtonLocation: isBottom ? FloatingActionButtonLocation.centerDocked : null,
floatingActionButton: isBottom
? hasKeyboard
Expand Down
10 changes: 5 additions & 5 deletions lib/pages/_interfaces/widgets/menu_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 The terCAD team. All rights reserved.
// Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.

import 'package:app_finance/_classes/herald/app_design.dart';
import 'package:app_finance/_classes/structure/navigation/app_menu.dart';
import 'package:app_finance/_classes/structure/navigation/app_menu_item.dart';
import 'package:app_finance/_configs/screen_helper.dart';
Expand All @@ -23,6 +24,7 @@ class MenuWidget extends StatelessWidget {
});

void _navigateToPage(NavigatorState nav, String routeName) {
setState();
nav.pop();
nav.pushNamed(routeName);
}
Expand All @@ -45,10 +47,7 @@ class MenuWidget extends StatelessWidget {
NavigatorState nav = Navigator.of(context);

return InkWell(
onTap: () {
setState();
_navigateToPage(nav, menu.route);
},
onTap: () => _navigateToPage(nav, menu.route),
focusNode: isSelected && !isWide ? (focus..requestFocus()) : focus,
onHover: _onHover,
child: Container(
Expand All @@ -60,10 +59,11 @@ class MenuWidget extends StatelessWidget {
: null,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
textDirection: AppDesign.getAlignment<TextDirection>(),
children: [
Icon(menu.icon, color: color),
Padding(
padding: EdgeInsets.only(left: indent),
padding: EdgeInsets.only(left: indent, right: indent),
child: TextWrapper(
menu.name,
style: textTheme.headlineMedium?.copyWith(color: color),
Expand Down
11 changes: 0 additions & 11 deletions lib/pages/automation/payment_add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ class PaymentAddPageState<T extends PaymentAddPage> extends AbstractAddPageState
@override
String getTitle() => AppLocale.labels.paymentsHeadline;

@override
void triggerActionButton(NavigatorState nav) {
setState(() {
if (hasFormErrors()) {
return;
}
updateStorage();
nav.pop();
});
}

@override
bool hasFormErrors() {
setState(() => hasErrors = itemType == null || intervalType == null);
Expand Down
6 changes: 6 additions & 0 deletions lib/pages/bill/bill_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class BillPageState extends AbstractPageState<BillPage> {

@override
Widget buildContent(BuildContext context, BoxConstraints constraints) {
state.addListener(() {
itemsShown = [];
final now = DateTime.now();
timer = DateTime(now.year, now.month, now.day);
stream = null;
});
if (stream == null) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => setState(() {
Expand Down
22 changes: 7 additions & 15 deletions lib/pages/bill/widgets/expenses_edit_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:app_finance/_classes/herald/app_locale.dart';
import 'package:app_finance/_classes/structure/bill_app_data.dart';
import 'package:app_finance/_ext/double_ext.dart';
import 'package:app_finance/pages/bill/widgets/expenses_tab.dart';
import 'package:flutter_currency_picker/flutter_currency_picker.dart';

class ExpensesEditTab extends ExpensesTab {
final String uuid;
Expand All @@ -15,20 +14,13 @@ class ExpensesEditTab extends ExpensesTab {
required this.uuid,
required super.state,
required super.callback,
String? account,
String? budget,
Currency? currency,
double? bill,
String? description,
DateTime? createdAt,
}) : super(
account: account,
budget: budget,
currency: currency,
bill: bill,
description: description,
createdAt: createdAt,
);
super.account,
super.budget,
super.currency,
super.bill,
super.description,
super.createdAt,
});

@override
ExpensesEditTabState createState() => ExpensesEditTabState();
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/bill/widgets/expenses_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:app_finance/_classes/controller/exchange_controller.dart';
import 'package:app_finance/_classes/herald/app_design.dart';
import 'package:app_finance/_classes/herald/app_locale.dart';
import 'package:app_finance/_classes/structure/currency/exchange.dart';
import 'package:app_finance/_classes/structure/navigation/app_route.dart';
import 'package:app_finance/_classes/structure/bill_app_data.dart';
import 'package:app_finance/_classes/controller/focus_controller.dart';
import 'package:app_finance/_classes/storage/app_preferences.dart';
Expand Down Expand Up @@ -148,7 +147,7 @@ class ExpensesTabState<T extends ExpensesTab> extends State<T> {
return;
}
updateStorage();
nav.popAndPushNamed(AppRoute.homeRoute);
nav.pop();
})
},
title: getButtonName(),
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/bill/widgets/income_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:app_finance/_classes/herald/app_design.dart';
import 'package:app_finance/_classes/herald/app_locale.dart';
import 'package:app_finance/_classes/structure/currency/exchange.dart';
import 'package:app_finance/_classes/structure/invoice_app_data.dart';
import 'package:app_finance/_classes/structure/navigation/app_route.dart';
import 'package:app_finance/_classes/controller/focus_controller.dart';
import 'package:app_finance/_classes/storage/app_preferences.dart';
import 'package:app_finance/_classes/storage/app_data.dart';
Expand Down Expand Up @@ -127,7 +126,7 @@ class IncomeTabState<T extends IncomeTab> extends State<IncomeTab> {
return;
}
updateStorage();
nav.popAndPushNamed(AppRoute.homeRoute);
nav.pop();
})
},
title: getButtonName(),
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/bill/widgets/transfer_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:app_finance/_classes/herald/app_design.dart';
import 'package:app_finance/_classes/herald/app_locale.dart';
import 'package:app_finance/_classes/structure/currency/exchange.dart';
import 'package:app_finance/_classes/structure/invoice_app_data.dart';
import 'package:app_finance/_classes/structure/navigation/app_route.dart';
import 'package:app_finance/_classes/controller/focus_controller.dart';
import 'package:app_finance/_classes/storage/app_data.dart';
import 'package:app_finance/_configs/theme_helper.dart';
Expand Down Expand Up @@ -128,7 +127,7 @@ class TransferTabState<T extends TransferTab> extends State<T> {
return;
}
updateStorage();
nav.popAndPushNamed(AppRoute.homeRoute);
nav.pop();
})
},
title: getButtonName(),
Expand Down
11 changes: 0 additions & 11 deletions lib/pages/currency/currency_add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ class CurrencyAddPageState extends AbstractAddPageState<CurrencyAddPage> {
state.update(exchange.uuid, exchange, true);
}

@override
void triggerActionButton(NavigatorState nav) {
setState(() {
if (hasFormErrors()) {
return;
}
updateStorage();
nav.pop();
});
}

@override
Widget buildButton(BuildContext context, BoxConstraints constraints) {
NavigatorState nav = Navigator.of(context);
Expand Down
19 changes: 6 additions & 13 deletions lib/pages/goal/goal_add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import 'package:app_finance/_classes/storage/app_data.dart';
import 'package:app_finance/_configs/theme_helper.dart';
import 'package:app_finance/_classes/storage/app_preferences.dart';
import 'package:app_finance/design/wrapper/input_wrapper.dart';
import 'package:app_finance/pages/_interfaces/abstract_page_state.dart';
import 'package:app_finance/pages/_interfaces/abstract_add_page.dart';
import 'package:app_finance/design/button/full_sized_button_widget.dart';
import 'package:app_finance/design/form/simple_input.dart';
import 'package:app_finance/design/wrapper/row_widget.dart';
import 'package:app_finance/design/wrapper/single_scroll_wrapper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_currency_picker/flutter_currency_picker.dart';

class GoalAddPage extends StatefulWidget {
class GoalAddPage extends AbstractAddPage {
final String? title;
final IconData? icon;
final MaterialColor? color;
Expand All @@ -40,15 +40,14 @@ class GoalAddPage extends StatefulWidget {
GoalAddPageState createState() => GoalAddPageState();
}

class GoalAddPageState<T extends GoalAddPage> extends AbstractPageState<GoalAddPage> {
class GoalAddPageState<T extends GoalAddPage> extends AbstractAddPageState<GoalAddPage> {
late FocusController focus;
late TextEditingController title;
late TextEditingController details;
IconData? icon;
MaterialColor? color;
Currency? currency;
DateTime? closedAt;
bool hasError = false;

@override
void initState() {
Expand All @@ -74,11 +73,13 @@ class GoalAddPageState<T extends GoalAddPage> extends AbstractPageState<GoalAddP
@override
String getTitle() => AppLocale.labels.createGoalHeader;

@override
bool hasFormErrors() {
setState(() => hasError = title.text.isEmpty || closedAt == null);
return hasError;
}

@override
void updateStorage() {
if (currency != null) {
CurrencyProvider.pin(currency!);
Expand All @@ -105,15 +106,7 @@ class GoalAddPageState<T extends GoalAddPage> extends AbstractPageState<GoalAddP
return FullSizedButtonWidget(
constraints: constraints,
controller: focus,
onPressed: () => {
setState(() {
if (hasFormErrors()) {
return;
}
updateStorage();
nav.pop();
})
},
onPressed: () => triggerActionButton(nav),
title: getButtonName(),
icon: Icons.save,
);
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ class HomePageState extends AbstractPageState<HomePage> {
}
return Builder(
builder: (BuildContext context) {
final scaffold = Scaffold.of(context);
return ToolbarButtonWidget(
icon: Icons.menu,
color: Colors.white70,
tooltip: AppLocale.labels.navigationTooltip,
onPressed: () => Scaffold.of(context).openDrawer(),
onPressed: () => AppDesign.isRightToLeft() ? scaffold.openEndDrawer() : scaffold.openDrawer(),
);
},
);
Expand Down
33 changes: 17 additions & 16 deletions test/e2e/_steps/given/on_defined_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2023 The terCAD team. All rights reserved.
// Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_gherkin_wrapper/flutter_gherkin_wrapper.dart';
import 'package:flutter_test/flutter_test.dart';
// ignore: depend_on_referenced_packages
Expand All @@ -15,25 +14,27 @@ class OnDefinedPage extends Given1<String> {

@override
Future<void> executeStep(String route) async {
// TBD: check flow (unexpected currency selector "force to action")
try {
final btn = find.byTooltip('Return Back');
expectSync(btn, findsOneWidget);
await FileRunner.tester.ensureVisible(btn);
await FileRunner.tester.tap(btn, warnIfMissed: false);
await FileRunner.tester.pumpAndSettle();
} catch (_) {
// skip
}
ScreenCapture.seize(runtimeType.toString());
final ScaffoldState scafState = FileRunner.tester.firstState(find.byType(Scaffold).at(1));
scafState.openDrawer();
final btn = find.byTooltip('Open main menu');
expectSync(btn, findsOneWidget);
await FileRunner.tester.ensureVisible(btn);
await FileRunner.tester.tap(btn);
await FileRunner.tester.pumpAndSettle();
final header = find.text(route);
ScreenCapture.seize(runtimeType.toString());
expectSync(header, findsOneWidget);

ScreenCapture.seize('${runtimeType.toString()}_$route');
Finder header = find.text(route);
final matchCount = FileRunner.tester.widgetList(header).length;
if (matchCount == 1) {
// do nothing
} else if (matchCount > 1) {
header = header.first;
} else {
fail('No widget found with text "$route"');
}
await FileRunner.tester.ensureVisible(header);
await FileRunner.tester.tap(header);
await FileRunner.tester.pumpAndSettle();

ScreenCapture.seize(runtimeType.toString());
}
}
1 change: 1 addition & 0 deletions test/e2e/account/create_and_view_accounts.resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Feature: Verify Account Functionality
And I enter "<amount>" to "Set Balance" text field
And I select "<currency>" from "CurrencySelector" with "Currency Type (Code)" tooltip
And I tap "Create new Account" button
Given I am on "Home" page
Then I can see "Accounts, total" component
And I can see "<type>" component
And I can see "<result>" component
Expand Down
1 change: 1 addition & 0 deletions test/e2e/budget/create_and_view_budgets.resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Feature: Verify Budget Functionality
And I enter "<amount>" to "Set Balance" text field
And I select "<currency>" from "CurrencySelector" with "Currency Type (Code)" tooltip
And I tap "Create new Budget Category" button
Given I am on "Home" page
Then I can see "Budgets, left" component
And I can see "<name_result>" component
And I can see "<result>" component
Expand Down
Loading

0 comments on commit 0bad4e2

Please sign in to comment.