Skip to content

Commit

Permalink
fix: 5 bugfixes (icons color, better network mgmt / Japanese…) (openf…
Browse files Browse the repository at this point in the history
…oodfacts#6127)

* Fix the elevated button color

* Scan tagline : when there is an error, hide the image

* Better management of errors for the `ProductPicture`

* Force a loader for the gallery

* Fix Japanese issue with tables

* Update packages/smooth_app/lib/cards/product_cards/smooth_product_image.dart

Co-authored-by: monsieurtanuki <[email protected]>

* Force a color for Price buttons

---------

Co-authored-by: monsieurtanuki <[email protected]>
  • Loading branch information
g123k and monsieurtanuki authored Jan 6, 2025
1 parent 87b51cc commit 43d282a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,35 @@ class _ProductPictureWithImageProvider extends StatelessWidget {
height: size.height,
fit: BoxFit.contain,
image: imageProvider,
loadingBuilder: (_, Widget child, ImageChunkEvent? loadingProgress) {
loadingBuilder: (
BuildContext context,
Widget child,
ImageChunkEvent? loadingProgress,
) {
if (loadingProgress == null) {
return child;
}

return const Center(
child: CircularProgressIndicator(),
);
return _loadingPlaceholder(context);
},
errorBuilder: (_, __, ___) {
onError.call();
return EMPTY_WIDGET;
},
frameBuilder: (
BuildContext context,
Widget child,
int? frame,
_,
) {
/// Force a loader, as the [loadingBuilder] has a [loadingProgress] of null,
/// which is not expected.
if (frame == null) {
return _loadingPlaceholder(context);
}

return child;
},
);

if (heroTag != null) {
Expand All @@ -436,6 +452,21 @@ class _ProductPictureWithImageProvider extends StatelessWidget {
return image;
}
}

Widget _loadingPlaceholder(BuildContext context) => DecoratedBox(
decoration: BoxDecoration(
borderRadius: borderRadius,
border: border > 0.0
? Border.all(
color: Theme.of(context).dividerColor,
width: 1.0,
)
: null,
),
child: const Center(
child: CircularProgressIndicator(),
),
);
}

class _OutdatedProductPictureIcon extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class SmoothImage extends StatelessWidget {
fit: fit,
loadingBuilder: _loadingBuilder,
errorBuilder: _errorBuilder,
frameBuilder: (_, Widget child, int? frame, ____) {
if (frame == null) {
return const Center(
child: CircularProgressIndicator(),
);
}

return child;
},
cacheWidth: cacheWidth,
cacheHeight: cacheHeight,
),
Expand Down Expand Up @@ -89,33 +98,38 @@ class SmoothImage extends StatelessWidget {

return ExcludeSemantics(
child: AnimatedCrossFade(
crossFadeState: progress == null
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: SmoothAnimationsDuration.long,
firstChild: child,
secondChild: Container(
color: theme.primaryColor.withValues(alpha: 0.1),
alignment: AlignmentDirectional.center,
padding: const EdgeInsets.all(SMALL_SPACE),
child: const SmoothAnimatedLogo(),
),
layoutBuilder: (Widget topChild, Key topChildKey, Widget bottomChild,
Key bottomChildKey) {
return Stack(
clipBehavior: Clip.none,
children: <Widget>[
Positioned.fill(
key: bottomChildKey,
child: bottomChild,
),
Positioned.fill(
key: topChildKey,
child: topChild,
),
],
);
}),
crossFadeState: progress == null
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: SmoothAnimationsDuration.long,
firstChild: child,
secondChild: Container(
color: theme.primaryColor.withValues(alpha: 0.1),
alignment: AlignmentDirectional.center,
padding: const EdgeInsets.all(SMALL_SPACE),
child: const SmoothAnimatedLogo(),
),
layoutBuilder: (
Widget topChild,
Key topChildKey,
Widget bottomChild,
Key bottomChildKey,
) {
return Stack(
clipBehavior: Clip.none,
children: <Widget>[
Positioned.fill(
key: bottomChildKey,
child: bottomChild,
),
Positioned.fill(
key: topChildKey,
child: topChild,
),
],
);
},
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ class _KnowledgePanelTableCardState extends State<KnowledgePanelTableCard> {

/// Ensure the columns are not too wide or too narrow.
final int sum = _columnsMaxLength.sum;
final int maxWidth = (sum ~/ _columnsMaxLength.length) - 4;
final int minWidth = maxWidth ~/ 4;
final int maxWidth = math.max((sum ~/ _columnsMaxLength.length) - 4, 1);
final int minWidth = math.max(maxWidth ~/ 4, 1);

for (int i = 0; i < _columnsMaxLength.length; i++) {
if (_columnsType[i] == _TableCellType.PERCENT) {
Expand Down
13 changes: 10 additions & 3 deletions packages/smooth_app/lib/pages/prices/price_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,31 @@ class PriceButton extends StatelessWidget {
Widget build(BuildContext context) {
final Widget widget;

ButtonStyle? buttonStyleOverride;
if (buttonStyle != null && buttonStyle!.foregroundColor != null) {
buttonStyleOverride = buttonStyle!.copyWith(
iconColor: buttonStyle!.foregroundColor,
);
}

if (iconData == null) {
widget = ElevatedButton(
onPressed: onPressed,
style: buttonStyle,
style: buttonStyleOverride ?? buttonStyle,
child: Text(title!),
);
} else if (title == null) {
widget = ElevatedButton(
onPressed: onPressed,
style: buttonStyle,
style: buttonStyleOverride ?? buttonStyle,
child: Icon(iconData),
);
} else {
widget = ElevatedButton.icon(
onPressed: onPressed,
icon: Icon(iconData),
label: Text(title!),
style: buttonStyle,
style: buttonStyleOverride ?? buttonStyle,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ class _TagLineContentBody extends StatefulWidget {
class _TagLineContentBodyState extends State<_TagLineContentBody> {
bool _imageError = false;

static const EdgeInsetsGeometry _contentPadding = EdgeInsetsDirectional.only(
top: SMALL_SPACE,
bottom: VERY_SMALL_SPACE,
);

@override
Widget build(BuildContext context) {
final ThemeProvider themeProvider = context.watch<ThemeProvider>();
Expand All @@ -333,16 +338,16 @@ class _TagLineContentBodyState extends State<_TagLineContentBody> {
),
);

if (widget.image == null) {
return text;
if (widget.image == null || _imageError) {
return Padding(
padding: _contentPadding,
child: text,
);
}

final int imageFlex = ((widget.image!.width ?? 0.2) * 10).toInt();
return Padding(
padding: const EdgeInsetsDirectional.only(
top: SMALL_SPACE,
bottom: VERY_SMALL_SPACE,
),
padding: _contentPadding,
child: Row(
children: <Widget>[
if (!_imageError) ...<Widget>[
Expand Down Expand Up @@ -375,6 +380,7 @@ class _TagLineContentBodyState extends State<_TagLineContentBody> {
widget.image!.src,
semanticsLabel: widget.image!.alt,
loadingBuilder: (_) => _onLoading(),
errorBuilder: (_, __) => _onError(),
);
} else {
return Image.network(
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/themes/smooth_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SmoothTheme {
? Colors.white
: myColorScheme.onPrimary,
),
iconColor: WidgetStateProperty.all<Color>(Colors.white),
iconColor: WidgetStateProperty.all<Color>(myColorScheme.onPrimary),
),
),
floatingActionButtonTheme: FloatingActionButtonThemeData(
Expand Down

0 comments on commit 43d282a

Please sign in to comment.