@@ -96,6 +96,17 @@ class _NutrientRowState extends State<NutrientRow>
9696 PerSize .oneHundredGrams,
9797 );
9898
99+ String ? extractionValue = robotoffNutrientEntity? .value;
100+
101+ // We need to make sure the value is formatted properly
102+ // We also ignore text extractions such as "traces" until the API is ready
103+ if (extractionValue != null ) {
104+ final num ? extractionValueNum = NumberFormat ().tryParse (extractionValue);
105+ if (extractionValueNum == null ) {
106+ extractionValue = extractionValueNum.toString ();
107+ }
108+ }
109+
99110 return ColoredBox (
100111 color: color,
101112 child: Padding (
@@ -143,8 +154,7 @@ class _NutrientRowState extends State<NutrientRow>
143154 ),
144155 ],
145156 ),
146- if (robotoffNutrientEntity? .value != null &&
147- robotoffNutrientEntity! .value! != controller.text)
157+ if (extractionValue != null && extractionValue != controller.text)
148158 Container (
149159 margin: const EdgeInsetsDirectional .only (
150160 bottom: SMALL_SPACE ,
@@ -167,7 +177,7 @@ class _NutrientRowState extends State<NutrientRow>
167177 ),
168178 ),
169179 Text (
170- robotoffNutrientEntity.text ! ,
180+ extractionValue ,
171181 style: TextStyle (
172182 color: extension .success,
173183 fontWeight: FontWeight .bold,
@@ -178,8 +188,8 @@ class _NutrientRowState extends State<NutrientRow>
178188 .edit_product_form_item_add_suggestion,
179189 child: IconButton (
180190 onPressed: () {
181- controller.text = robotoffNutrientEntity.value ! ;
182- final Unit ? unit = robotoffNutrientEntity.unit;
191+ controller.text = extractionValue ! ;
192+ final Unit ? unit = robotoffNutrientEntity? .unit;
183193 if (unit != null ) {
184194 widget.nutritionContainer.setNutrientUnit (
185195 widget.orderedNutrient.nutrient! ,
@@ -307,7 +317,8 @@ class _NutrientValueCell extends StatelessWidget {
307317 inputFormatters: < TextInputFormatter > [
308318 FilteringTextInputFormatter .allow (
309319 SimpleInputNumberField .getNumberRegExp (
310- decimal: true ),
320+ decimal: true ,
321+ ),
311322 ),
312323 DecimalSeparatorRewriter (decimalNumberFormat),
313324 ],
0 commit comments