Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare button enabled only for two or more products #1199

Merged
merged 2 commits into from
Mar 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions packages/smooth_app/lib/pages/product/common/product_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,37 @@ class _ProductListPageState extends State<ProductListPage> {
backgroundColor: Colors.white, // TODO(monsieurtanuki): night mode
foregroundColor: Colors.black,
title: Row(
mainAxisAlignment: _selectionMode && _selectedBarcodes.isEmpty
? MainAxisAlignment.end // just the cancel button, at the end
: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
if (_selectionMode && _selectedBarcodes.isNotEmpty)
if (_selectionMode)
ElevatedButton(
child: Text(
appLocalizations.plural_compare_x_products(
_selectedBarcodes.length,
),
),
onPressed: () async {
final List<Product> list = <Product>[];
for (final Product product in products) {
if (_selectedBarcodes.contains(product.barcode)) {
list.add(product);
}
}
await Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) =>
PersonalizedRankingPage.fromItems(
products: list,
title: 'Your ranking',
),
),
);
setState(() => _selectionMode = false);
},
onPressed: _selectedBarcodes.length >=
2 // compare button is enabled only if 2 or more products have been selected
? () async {
final List<Product> list = <Product>[];
for (final Product product in products) {
if (_selectedBarcodes.contains(product.barcode)) {
list.add(product);
}
}
await Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) =>
PersonalizedRankingPage.fromItems(
products: list,
title: 'Your ranking', // TODO(X): Translate
),
),
);
setState(() => _selectionMode = false);
}
: null,
),
if (_selectionMode)
ElevatedButton(
Expand Down