Skip to content

Commit

Permalink
feat: Configure main responsive layout with auto_router
Browse files Browse the repository at this point in the history
  • Loading branch information
enrique-lozano committed Nov 26, 2023
1 parent e4a11ba commit ef850ff
Show file tree
Hide file tree
Showing 44 changed files with 1,899 additions and 840 deletions.
41 changes: 16 additions & 25 deletions lib/app/accounts/account_details.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:auto_route/auto_route.dart';
import 'package:drift/drift.dart' as drift;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'package:monekin/app/accounts/account_form.dart';
import 'package:monekin/app/transactions/transactions.page.dart';
import 'package:monekin/app/transactions/widgets/transaction_list.dart';
import 'package:monekin/core/database/services/account/account_service.dart';
import 'package:monekin/core/database/services/exchange-rate/exchange_rate_service.dart';
Expand All @@ -18,11 +17,13 @@ import 'package:monekin/core/presentation/widgets/inline_info_card.dart';
import 'package:monekin/core/presentation/widgets/monekin_quick_actions_buttons.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/currency_displayer.dart';
import 'package:monekin/core/presentation/widgets/transaction_filter/transaction_filters.dart';
import 'package:monekin/core/routes/app_router.dart';
import 'package:monekin/core/utils/list_tile_action_item.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../transactions/form/transaction_form.page.dart';

@RoutePage()
class AccountDetailsPage extends StatefulWidget {
const AccountDetailsPage({super.key, required this.account});

Expand All @@ -42,15 +43,10 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {

return [
ListTileActionItem(
label: t.general.edit,
icon: Icons.edit,
onClick: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AccountFormPage(
account: account,
)),
)),
label: t.general.edit,
icon: Icons.edit,
onClick: () => context.pushRoute(AccountFormRoute(account: account)),
),
ListTileActionItem(
label: t.transfer.create,
icon: TransactionType.transfer.icon,
Expand All @@ -75,13 +71,12 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {
},
);

navigateToTransferForm() => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TransactionFormPage(
fromAccount: account,
mode: TransactionFormMode.transfer,
)));
navigateToTransferForm() => context.pushRoute(
TransactionFormRoute(
fromAccount: account,
mode: TransactionFormMode.transfer,
),
);

final numberOfAccounts =
(await AccountService.instance.getAccounts().first)
Expand Down Expand Up @@ -408,14 +403,10 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {
CardWithHeader(
title: t.home.last_transactions,
onHeaderButtonClick: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TransactionsPage(
context.pushRoute(
TransactionsRoute(
filters: TransactionFilters(
accountsIDs: [widget.account.id]),
),
),
accountsIDs: [widget.account.id])),
);
},
body: TransactionListComponent(
Expand Down
2 changes: 2 additions & 0 deletions lib/app/accounts/account_form.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:auto_route/auto_route.dart';
import 'package:drift/drift.dart' as drift;
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
Expand All @@ -24,6 +25,7 @@ import 'package:monekin/core/utils/text_field_utils.dart';
import 'package:monekin/i18n/translations.g.dart';
import 'package:uuid/uuid.dart';

@RoutePage()
class AccountFormPage extends StatefulWidget {
const AccountFormPage({Key? key, this.account}) : super(key: key);

Expand Down
11 changes: 5 additions & 6 deletions lib/app/accounts/all_accounts_balance.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:async';
import 'dart:math';

import 'package:auto_route/auto_route.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.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';
import 'package:monekin/core/routes/app_router.dart';
import 'package:monekin/core/presentation/widgets/animated_progress_bar.dart';
import 'package:monekin/core/presentation/widgets/card_with_header.dart';
import 'package:monekin/core/presentation/widgets/transaction_filter/transaction_filters.dart';
Expand All @@ -14,7 +16,6 @@ import 'package:monekin/i18n/translations.g.dart';
import '../../core/database/services/currency/currency_service.dart';
import '../../core/presentation/widgets/number_ui_formatters/currency_displayer.dart';
import '../../core/presentation/widgets/skeleton.dart';
import 'account_form.dart';

class AccountWithMoney {
final double money;
Expand Down Expand Up @@ -140,11 +141,9 @@ class _AllAccountBalancePageState extends State<AllAccountBalancePage> {
size: 22,
color: Theme.of(context).colorScheme.primary,
)),
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => AccountFormPage(
account: accountWithMoney.account),
),
onTap: () => context.pushRoute(
AccountFormRoute(
account: accountWithMoney.account),
),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
25 changes: 9 additions & 16 deletions lib/app/accounts/all_accounts_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:monekin/app/accounts/account_details.dart';
import 'package:monekin/app/accounts/account_form.dart';
import 'package:monekin/core/database/services/account/account_service.dart';
import 'package:monekin/core/routes/app_router.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../../core/presentation/widgets/empty_indicator.dart';

@RoutePage()
class AllAccountsPage extends StatelessWidget {
const AllAccountsPage({super.key});

Expand All @@ -16,14 +17,10 @@ class AllAccountsPage extends StatelessWidget {
return Scaffold(
appBar: AppBar(title: Text(t.home.my_accounts)),
floatingActionButton: FloatingActionButton.extended(
icon: const Icon(Icons.add_rounded),
label: Text(t.account.form.create),
onPressed: () => {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AccountFormPage()))
}),
icon: const Icon(Icons.add_rounded),
label: Text(t.account.form.create),
onPressed: () => context.pushRoute(AccountFormRoute()),
),
body: StreamBuilder(
stream: AccountService.instance.getAccounts(),
builder: (context, snapshot) {
Expand Down Expand Up @@ -76,12 +73,8 @@ class AllAccountsPage extends StatelessWidget {
child: account.displayIcon(context),
),
subtitle: Text(account.type.title(context)),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AccountDetailsPage(account: account)),
),
onTap: () => context
.pushRoute(AccountDetailsRoute(account: account)),
);
});
}),
Expand Down
16 changes: 8 additions & 8 deletions lib/app/budgets/budget_details_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:async';

import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:monekin/app/budgets/budget_form_page.dart';
import 'package:monekin/app/budgets/budgets_page.dart';
import 'package:monekin/app/budgets/components/budget_evolution_chart.dart';
import 'package:monekin/app/transactions/widgets/transaction_list.dart';
Expand All @@ -16,11 +16,13 @@ import 'package:monekin/core/presentation/widgets/monekin_popup_menu_button.dart
import 'package:monekin/core/presentation/widgets/number_ui_formatters/currency_displayer.dart';
import 'package:monekin/core/presentation/widgets/skeleton.dart';
import 'package:monekin/core/presentation/widgets/transaction_filter/transaction_filters.dart';
import 'package:monekin/core/routes/app_router.dart';
import 'package:monekin/core/utils/list_tile_action_item.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../../core/presentation/widgets/empty_indicator.dart';

@RoutePage()
class BudgetDetailsPage extends StatefulWidget {
const BudgetDetailsPage({super.key, required this.budget});

Expand Down Expand Up @@ -88,13 +90,11 @@ class _BudgetDetailsPageState extends State<BudgetDetailsPage> {
label: t.budgets.form.edit,
icon: Icons.edit,
onClick: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BudgetFormPage(
prevPage: const BudgetsPage(),
budgetToEdit: budget),
));
context.pushRoute(
BudgetFormRoute(
prevPage: const BudgetsPage(),
budgetToEdit: budget),
);
},
),
ListTileActionItem(
Expand Down
2 changes: 2 additions & 0 deletions lib/app/budgets/budget_form_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:monekin/app/accounts/account_selector.dart';
Expand All @@ -18,6 +19,7 @@ import 'package:uuid/uuid.dart';
import '../../core/models/account/account.dart';
import '../../core/presentation/widgets/persistent_footer_button.dart';

@RoutePage()
class BudgetFormPage extends StatefulWidget {
const BudgetFormPage({super.key, this.budgetToEdit, required this.prevPage});

Expand Down
21 changes: 7 additions & 14 deletions lib/app/budgets/budgets_page.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:monekin/app/budgets/budget_details_page.dart';
import 'package:monekin/app/budgets/budget_form_page.dart';
import 'package:monekin/core/database/services/budget/budget_service.dart';
import 'package:monekin/core/models/budget/budget.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/animated_progress_bar.dart';
import 'package:monekin/core/presentation/widgets/empty_indicator.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/currency_displayer.dart';
import 'package:monekin/core/presentation/widgets/skeleton.dart';
import 'package:monekin/core/routes/app_router.dart';
import 'package:monekin/i18n/translations.g.dart';

@RoutePage()
class BudgetsPage extends StatelessWidget {
const BudgetsPage({super.key});

Widget buildBudgetCard(BuildContext context, Budget budget) {
return InkWell(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BudgetDetailsPage(budget: budget))),
onTap: () => context.pushRoute(BudgetDetailsRoute(budget: budget)),
child: Container(
padding: const EdgeInsets.all(16),
child: Column(
Expand Down Expand Up @@ -110,14 +108,9 @@ class BudgetsPage extends StatelessWidget {
floatingActionButton: FloatingActionButton.extended(
icon: const Icon(Icons.add_rounded),
label: Text(t.budgets.form.create),
onPressed: () => {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const BudgetFormPage(
prevPage: BudgetsPage(),
)))
}),
onPressed: () => context.pushRoute(
BudgetFormRoute(prevPage: const BudgetsPage()),
)),
body: TabBarView(children: [
StreamBuilder(
stream: BudgetServive.instance
Expand Down
25 changes: 11 additions & 14 deletions lib/app/categories/categories_list.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:monekin/app/categories/subcategory_selector.dart';
import 'package:monekin/core/database/services/category/category_service.dart';
Expand All @@ -6,11 +7,10 @@ import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/bottomSheetFooter.dart';
import 'package:monekin/core/presentation/widgets/persistent_footer_button.dart';
import 'package:monekin/core/presentation/widgets/scrollable_with_bottom_gradient.dart';
import 'package:monekin/core/routes/app_router.dart';
import 'package:monekin/core/utils/color_utils.dart';
import 'package:monekin/i18n/translations.g.dart';

import 'form/category_form.dart';

enum CategoriesListMode {
page,
modalSelectSubcategory,
Expand Down Expand Up @@ -39,6 +39,12 @@ Future<List<Category>?> showCategoryListModal(
);
}

@RoutePage()
class CategoriesListPage extends CategoriesList {
const CategoriesListPage()
: super(mode: CategoriesListMode.page, selectedCategories: const []);
}

class CategoriesList extends StatefulWidget {
const CategoriesList(
{super.key, required this.mode, this.selectedCategories = const []});
Expand Down Expand Up @@ -78,13 +84,8 @@ class _CategoriesListState extends State<CategoriesList> {
itemBuilder: (context, index) {
final category = categoriesToDisplay[index];

goToCategoryForm() => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CategoryFormPage(
categoryUUID: category.id,
)),
);
goToCategoryForm() =>
context.pushRoute(CategoryFormRoute(categoryUUID: category.id));

if (widget.mode != CategoriesListMode.modalSelectMultiCategory) {
return ListTile(
Expand Down Expand Up @@ -192,11 +193,7 @@ class _CategoriesListState extends State<CategoriesList> {
PersistentFooterButton(
child: FilledButton.icon(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const CategoryFormPage()));
context.pushRoute(CategoryFormRoute());
},
icon: const Icon(Icons.add),
label: Text(t.categories.create),
Expand Down
2 changes: 2 additions & 0 deletions lib/app/categories/form/category_form.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:auto_route/auto_route.dart';
import 'package:drift/drift.dart' as drift;
import 'package:flutter/material.dart';
import 'package:monekin/app/categories/form/category_form_functions.dart';
Expand All @@ -15,6 +16,7 @@ import 'package:monekin/core/utils/text_field_utils.dart';
import 'package:monekin/i18n/translations.g.dart';
import 'package:uuid/uuid.dart';

@RoutePage()
class CategoryFormPage extends StatefulWidget {
const CategoryFormPage({super.key, this.categoryUUID});

Expand Down
12 changes: 5 additions & 7 deletions lib/app/currencies/currency_manager.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:monekin/app/currencies/exchange_rate_details.dart';
import 'package:monekin/app/currencies/exchange_rate_form.dart';
import 'package:monekin/core/database/services/currency/currency_service.dart';
import 'package:monekin/core/database/services/exchange-rate/exchange_rate_service.dart';
import 'package:monekin/core/database/services/user-setting/user_setting_service.dart';
import 'package:monekin/core/models/currency/currency.dart';
import 'package:monekin/core/presentation/widgets/currency_selector_modal.dart';
import 'package:monekin/core/presentation/widgets/skeleton.dart';
import 'package:monekin/core/routes/app_router.dart';
import 'package:monekin/i18n/translations.g.dart';

import '../../core/presentation/widgets/empty_indicator.dart';

@RoutePage()
class CurrencyManagerPage extends StatefulWidget {
const CurrencyManagerPage({super.key});

Expand Down Expand Up @@ -184,12 +186,8 @@ class _CurrencyManagerPageState extends State<CurrencyManagerPage> {

if (currency == null) return;

Navigator.push(
onTapContext,
MaterialPageRoute(
builder: (context) => ExchangeRateDetailsPage(
currency: currency,
)));
onTapContext.pushRoute(
ExchangeRateDetailsRoute(currency: currency));
},
);
},
Expand Down
Loading

0 comments on commit ef850ff

Please sign in to comment.