Skip to content

Commit

Permalink
feat: 5428 - page dedicated to prices
Browse files Browse the repository at this point in the history
New file:
* `prices_home_page.dart`: Home page of Prices

Impacted file:
* `user_preferences_account.dart`: replaced the whole prices items with a single item linking to new page `PricesHomePage`
  • Loading branch information
monsieurtanuki committed Oct 24, 2024
1 parent 3fde3e6 commit a8651c5
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import 'package:smooth_app/pages/preferences/lazy_counter_widget.dart';
import 'package:smooth_app/pages/preferences/user_preferences_item.dart';
import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/pages/prices/get_prices_model.dart';
import 'package:smooth_app/pages/prices/price_user_button.dart';
import 'package:smooth_app/pages/prices/prices_page.dart';
import 'package:smooth_app/pages/prices/prices_proofs_page.dart';
import 'package:smooth_app/pages/prices/prices_users_page.dart';
import 'package:smooth_app/pages/prices/product_price_add_page.dart';
import 'package:smooth_app/pages/prices/prices_home_page.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
import 'package:smooth_app/pages/user_management/login_page.dart';
import 'package:smooth_app/query/paged_product_query.dart';
Expand Down Expand Up @@ -218,90 +213,14 @@ class UserPreferencesAccount extends AbstractUserPreferences {
const LazyCounterUserSearch(UserSearchType.TO_BE_COMPLETED),
),
_getListTile(
PriceUserButton.showUserTitle(
user: ProductQuery.getWriteUser().userId,
context: context,
),
() async => PriceUserButton.showUserPrices(
user: ProductQuery.getWriteUser().userId,
context: context,
),
CupertinoIcons.money_dollar_circle,
lazyCounter: LazyCounterPrices(ProductQuery.getWriteUser().userId),
),
_getListTile(
appLocalizations.user_search_proofs_title,
() async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => const PricesProofsPage(
selectProof: false,
),
),
),
Icons.receipt,
),
_getListTile(
appLocalizations.prices_add_a_receipt,
() async => ProductPriceAddPage.showProductPage(
context: context,
proofType: ProofType.receipt,
),
Icons.add_shopping_cart,
),
_getListTile(
appLocalizations.prices_add_price_tags,
() async => ProductPriceAddPage.showProductPage(
context: context,
proofType: ProofType.priceTag,
),
Icons.add_shopping_cart,
),
_getListTile(
appLocalizations.all_search_prices_latest_title,
() async => Navigator.of(context).push(
appLocalizations.prices_generic_title,
() async => Navigator.push<void>(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => PricesPage(
GetPricesModel(
parameters: GetPricesParameters()
..orderBy = <OrderBy<GetPricesOrderField>>[
const OrderBy<GetPricesOrderField>(
field: GetPricesOrderField.created,
ascending: false,
),
]
..pageSize = GetPricesModel.pageSize
..pageNumber = 1,
displayOwner: true,
displayProduct: true,
uri: OpenPricesAPIClient.getUri(
path: 'prices',
uriHelper: ProductQuery.uriPricesHelper,
),
title: appLocalizations.all_search_prices_latest_title,
lazyCounterPrices: const LazyCounterPrices(null),
),
),
builder: (BuildContext context) => const PricesHomePage(),
),
),
CupertinoIcons.money_dollar_circle,
lazyCounter: const LazyCounterPrices(null),
),
_getListTile(
appLocalizations.all_search_prices_top_user_title,
() async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => const PricesUsersPage(),
),
),
Icons.account_box,
),
_getPriceListTile(
appLocalizations.all_search_prices_top_location_title,
'locations',
),
_getPriceListTile(
appLocalizations.all_search_prices_top_product_title,
'products',
),
_buildProductQueryTile(
productQuery: PagedToBeCompletedProductQuery(
Expand Down Expand Up @@ -356,21 +275,6 @@ class UserPreferencesAccount extends AbstractUserPreferences {
];
}

UserPreferencesItem _getPriceListTile(
final String title,
final String path,
) =>
_getListTile(
title,
() async => LaunchUrlHelper.launchURL(
OpenPricesAPIClient.getUri(
path: path,
uriHelper: ProductQuery.uriPricesHelper,
).toString(),
),
Icons.open_in_new,
);

Future<bool?> _confirmLogout() async => showDialog<bool>(
context: context,
builder: (BuildContext context) {
Expand Down
162 changes: 162 additions & 0 deletions packages/smooth_app/lib/pages/prices/prices_home_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_back_button.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';
import 'package:smooth_app/pages/preferences/lazy_counter.dart';
import 'package:smooth_app/pages/preferences/lazy_counter_widget.dart';
import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart';
import 'package:smooth_app/pages/prices/get_prices_model.dart';
import 'package:smooth_app/pages/prices/price_user_button.dart';
import 'package:smooth_app/pages/prices/prices_page.dart';
import 'package:smooth_app/pages/prices/prices_proofs_page.dart';
import 'package:smooth_app/pages/prices/prices_users_page.dart';
import 'package:smooth_app/pages/prices/product_price_add_page.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/themes/constant_icons.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Home page of Prices
class PricesHomePage extends StatelessWidget {
const PricesHomePage();

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return SmoothScaffold(
appBar: SmoothAppBar(
centerTitle: false,
leading: const SmoothBackButton(),
title: Text(
appLocalizations.prices_generic_title,
),
),
body: ListView(
children: <Widget>[
_getListTile(
title: PriceUserButton.showUserTitle(
user: ProductQuery.getWriteUser().userId,
context: context,
),
onTap: () async => PriceUserButton.showUserPrices(
user: ProductQuery.getWriteUser().userId,
context: context,
),
lazyCounter: LazyCounterPrices(ProductQuery.getWriteUser().userId),
),
_getListTile(
title: appLocalizations.user_search_proofs_title,
onTap: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => const PricesProofsPage(
selectProof: false,
),
),
),
trailingIconData: Icons.receipt,
),
_getListTile(
title: appLocalizations.prices_add_a_receipt,
onTap: () async => ProductPriceAddPage.showProductPage(
context: context,
proofType: ProofType.receipt,
),
trailingIconData: Icons.add_shopping_cart,
),
_getListTile(
title: appLocalizations.prices_add_price_tags,
onTap: () async => ProductPriceAddPage.showProductPage(
context: context,
proofType: ProofType.priceTag,
),
trailingIconData: Icons.add_shopping_cart,
),
_getListTile(
title: appLocalizations.all_search_prices_latest_title,
onTap: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => PricesPage(
GetPricesModel(
parameters: GetPricesParameters()
..orderBy = <OrderBy<GetPricesOrderField>>[
const OrderBy<GetPricesOrderField>(
field: GetPricesOrderField.created,
ascending: false,
),
]
..pageSize = GetPricesModel.pageSize
..pageNumber = 1,
displayOwner: true,
displayProduct: true,
uri: OpenPricesAPIClient.getUri(
path: 'prices',
uriHelper: ProductQuery.uriPricesHelper,
),
title: appLocalizations.all_search_prices_latest_title,
lazyCounterPrices: const LazyCounterPrices(null),
),
),
),
),
lazyCounter: const LazyCounterPrices(null),
),
_getListTile(
title: appLocalizations.all_search_prices_top_user_title,
onTap: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => const PricesUsersPage(),
),
),
trailingIconData: ConstantIcons.instance.getForwardIcon(),
),
_getListTile(
title: appLocalizations.all_search_prices_top_location_title,
onTap: () async => LaunchUrlHelper.launchURL(
OpenPricesAPIClient.getUri(
path: 'locations',
uriHelper: ProductQuery.uriPricesHelper,
).toString(),
),
trailingIconData: Icons.open_in_new,
),
_getListTile(
title: appLocalizations.all_search_prices_top_product_title,
onTap: () async => LaunchUrlHelper.launchURL(
OpenPricesAPIClient.getUri(
path: 'products',
uriHelper: ProductQuery.uriPricesHelper,
).toString(),
),
trailingIconData: Icons.open_in_new,
),
],
),
);
}

Widget _getListTile({
required final String title,
required final VoidCallback onTap,
final IconData? trailingIconData,
final LazyCounter? lazyCounter,
}) =>
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 5,
child: UserPreferencesListTile(
title: Text(title),
onTap: onTap,
trailing: lazyCounter != null
? LazyCounterWidget(lazyCounter)
: trailingIconData == null
? null
: Padding(
padding: EdgeInsets.only(right: 12),
child: Icon(trailingIconData),
),
),
);
}

0 comments on commit a8651c5

Please sign in to comment.