fix(nutrition): resolve fl_chart app crash when toggling meal details in Nutritional Plan Detail screen#1202
Merged
rolandgeider merged 1 commit intoMay 22, 2026
Conversation
…d/planned macros are empty in MealDiaryBarChart Bug: Unsupported operation: Infinity or NaN toInt (package:fl_chart)
Member
|
thanks! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧩 The Problem
When a user toggles the meal details view (
_toggleDetailsinmeal.dart) on a meal that has no logged entries today but contains a planned macro goal, the application crashes with an unhandled exception:Unsupported operation: Infinity or NaN toIntThis occurs because
MealDiaryBarChartWidgetmaps target and actual calorie values straight into percentages to renderBarChartRodData. Ifwidget._logged.energy(or any other macro) evaluates to0, Dart handles the calculation asInfinity. When the underlyingfl_chartpackage attempts to paint the background grid lines and axis intervals, it attempts to convert this infinity value to an integer (~/), resulting in a hard crash on the canvas layer.🛠️ The Fix
Instead of passing raw mathematical division results directly to the chart data structures, this PR introduces a
safePercenthelper method insidelib/widgets/nutrition/charts.dart.The helper safely sanitizes inputs before they ever reach
fl_chart:0.0immediately if the planned/logged target value is less than or equal to0..isNaNand.isInfiniteanomalies to ensure unexpected data states output a clean, non-breaking0%bar representation.Related Issue(s)
Test
Added a comprehensive widget test suite (
test/nutrition/nutritional_meal_charts_test.dart) to ensure the chart renders safely under the following conditions:Please check that the PR fulfills these requirements
dart format .)📱 UI Changes & Verification