forked from openfoodfacts/smooth-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 5428 - page dedicated to prices
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
1 parent
3fde3e6
commit a8651c5
Showing
2 changed files
with
167 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
packages/smooth_app/lib/pages/prices/prices_home_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
), | ||
); | ||
} |