-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 5205 - new "my prices" page (#5347)
* feat: 5205 - new "my prices" page Deleted files: * `product_price_item.dart` * `product_prices_page.dart` New files: * `get_prices_model.dart`: Model that stores what we need to know for "get latest prices" queries. * `price_button.dart`: Simple price button: displaying data with optional action. * `price_count_widget.dart`: Price Count display. * `price_data_widget.dart`: Price Data display (no product data here). * `price_product_widget.dart`: Price Product display (no price data here). * `prices_page.dart`: Page that displays the latest prices according to a model. Impacted files: * `labeler.yml`: deleted and new files * `prices_card.dart`: refactored using new classes * `product_prices_list.dart`: refactored using new classes * `user_preferences_account.dart`: refactored using new classes * typo fix * typo fix
- Loading branch information
1 parent
e94d61f
commit 13072eb
Showing
11 changed files
with
411 additions
and
159 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
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
38 changes: 38 additions & 0 deletions
38
packages/smooth_app/lib/pages/prices/get_prices_model.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,38 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
|
||
/// Model that stores what we need to know for "get latest prices" queries. | ||
class GetPricesModel { | ||
const GetPricesModel({ | ||
required this.parameters, | ||
required this.displayOwner, | ||
required this.displayProduct, | ||
required this.uri, | ||
required this.title, | ||
this.subtitle, | ||
this.addButton, | ||
}); | ||
|
||
/// Query parameters. | ||
final GetPricesParameters parameters; | ||
|
||
/// Should we display the owner for each price? No if it's an owner query. | ||
final bool displayOwner; | ||
|
||
/// Should we display the product for each price? No if it's a product query. | ||
final bool displayProduct; | ||
|
||
/// Related web app URI. | ||
final Uri uri; | ||
|
||
/// Page title. | ||
final String title; | ||
|
||
/// Page subtitle. | ||
final String? subtitle; | ||
|
||
/// "Add a price" callback. | ||
final VoidCallback? addButton; | ||
|
||
static const int pageSize = 10; | ||
} |
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,40 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Simple price button: displaying data with optional action. | ||
class PriceButton extends StatelessWidget { | ||
const PriceButton({ | ||
this.title, | ||
this.iconData, | ||
this.buttonStyle, | ||
required this.onPressed, | ||
}); | ||
|
||
final String? title; | ||
final IconData? iconData; | ||
final ButtonStyle? buttonStyle; | ||
final VoidCallback? onPressed; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (iconData == null) { | ||
return ElevatedButton( | ||
onPressed: onPressed, | ||
style: buttonStyle, | ||
child: Text(title!), | ||
); | ||
} | ||
if (title == null) { | ||
return ElevatedButton( | ||
onPressed: onPressed, | ||
style: buttonStyle, | ||
child: Icon(iconData), | ||
); | ||
} | ||
return ElevatedButton.icon( | ||
onPressed: onPressed, | ||
icon: Icon(iconData), | ||
label: Text(title!), | ||
style: buttonStyle, | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/smooth_app/lib/pages/prices/price_count_widget.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,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:smooth_app/pages/prices/price_button.dart'; | ||
|
||
/// Price Count display. | ||
class PriceCountWidget extends StatelessWidget { | ||
const PriceCountWidget(this.count); | ||
|
||
final int count; | ||
|
||
@override | ||
Widget build(BuildContext context) => PriceButton( | ||
onPressed: null, | ||
iconData: Icons.label, | ||
title: '$count', | ||
buttonStyle: ElevatedButton.styleFrom( | ||
disabledForegroundColor: _getForegroundColor(), | ||
disabledBackgroundColor: _getBackgroundColor(), | ||
), | ||
); | ||
|
||
Color? _getForegroundColor() => switch (count) { | ||
0 => Colors.red, | ||
1 => Colors.orange, | ||
_ => Colors.green, | ||
}; | ||
|
||
Color? _getBackgroundColor() => switch (count) { | ||
0 => Colors.red[100], | ||
1 => Colors.orange[100], | ||
_ => Colors.green[100], | ||
}; | ||
} |
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
Oops, something went wrong.