Skip to content

feat: Added price count badges #6493

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

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
66 changes: 47 additions & 19 deletions packages/smooth_app/lib/pages/prices/price_proof_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _PriceProofPageState extends State<PriceProofPage> {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final DateFormat dateFormat =
DateFormat.yMd(ProductQuery.getLocaleString()).add_Hms();

return SmoothScaffold(
floatingActionButton: _existingPrices == null
? null
Expand Down Expand Up @@ -77,27 +78,54 @@ class _PriceProofPageState extends State<PriceProofPage> {
),
],
),
body: Center(
child: Image.network(
_getUrl(false),
fit: BoxFit.cover,
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) {
return child;
}
return Center(
child: SizedBox(
width: double.maxFinite,
height: double.maxFinite,
child: Image.network(
_getUrl(true),
fit: BoxFit.contain,
body: Stack(
children: <Widget>[
Center(
child: Image.network(
_getUrl(false),
fit: BoxFit.cover,
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) {
return child;
}
return Center(
child: SizedBox(
width: double.maxFinite,
height: double.maxFinite,
child: Image.network(
_getUrl(true),
fit: BoxFit.contain,
),
),
);
},
),
),

// Price count badge at top-right
if (_existingPrices != null)
Positioned(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a Stack and a Positioned, please just us a Badge, cf. prices_card.dart.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

top: 16.0,
right: 16.0,
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.circular(12.0),
),
child: Text(
'${_existingPrices!.length} Prices',
style: const TextStyle(
color: Colors.white,
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
),
);
},
),
),
],
),
);
}
Expand Down
69 changes: 45 additions & 24 deletions packages/smooth_app/lib/pages/prices/prices_proofs_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/images/smooth_image.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_back_button.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
Expand Down Expand Up @@ -70,22 +68,18 @@ class _PricesProofsPageState extends State<PricesProofsPage>
if (snapshot.hasError) {
return Text(snapshot.error!.toString());
}
// highly improbable
if (!snapshot.hasData) {
return const Text('no data');
}
if (snapshot.data!.isError) {
return Text(snapshot.data!.error!);
}
final GetProofsResult result = snapshot.data!.value;
// highly improbable
if (result.items == null) {
return const Text('empty list');
}
final double squareSize = MediaQuery.sizeOf(context).width / _columns;

final AppLocalizations appLocalizations =
AppLocalizations.of(context);
final String title = result.numberOfPages == 1
? appLocalizations.prices_proofs_list_length_one_page(
result.items!.length,
Expand Down Expand Up @@ -117,7 +111,6 @@ class _PricesProofsPageState extends State<PricesProofsPage>
) {
final Proof proof = result.items![index];
if (proof.filePath == null) {
// highly improbable
return SizedBox(
width: squareSize,
height: squareSize,
Expand All @@ -138,7 +131,7 @@ class _PricesProofsPageState extends State<PricesProofsPage>
),
),
);
}, // PriceProofPage
},
child: _PriceProofImage(proof,
squareSize: squareSize),
);
Expand Down Expand Up @@ -192,7 +185,7 @@ class _PricesProofsPageState extends State<PricesProofsPage>
}
}

// TODO(monsieurtanuki): reuse whatever will be coded in https://github.com/openfoodfacts/smooth-app/pull/5366
// Updated class to use the 'badges' package
class _PriceProofImage extends StatelessWidget {
const _PriceProofImage(
this.proof, {
Expand All @@ -207,6 +200,10 @@ class _PriceProofImage extends StatelessWidget {
final DateFormat dateFormat =
DateFormat.yMd(ProductQuery.getLocaleString());
final String date = dateFormat.format(proof.created);

// Fetch price count (assuming proof.priceCount exists)
final int priceCount = proof.priceCount;

return Stack(
children: <Widget>[
SmoothImage(
Expand All @@ -222,25 +219,49 @@ class _PriceProofImage extends StatelessWidget {
),
rounded: false,
),
SizedBox(
width: squareSize,
height: squareSize,
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(SMALL_SPACE),
child: Container(
height: VERY_LARGE_SPACE,
color: Colors.white.withAlpha(128),
child: Center(
child: AutoSizeText(
date,
maxLines: 1,
),

// Price count badge (only if price count is greater than 0)
if (priceCount > 0)
Align(
alignment: Alignment.topLeft,
child: Container(
margin: const EdgeInsets.all(6.0),
padding:
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.circular(12.0),
),
child: Text(
'$priceCount',
style: const TextStyle(
color: Colors.white,
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
),
),

// Date badge (bottom center)
Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: const EdgeInsets.all(6.0),
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
decoration: BoxDecoration(
color: Colors.black54,
borderRadius: BorderRadius.circular(8.0),
),
child: Text(
date,
style: const TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.bold,
),
),
),
),
],
);
Expand Down