Skip to content

Commit

Permalink
Nutrition editor: the Next key is working again on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Feb 2, 2025
1 parent ed0e8c8 commit 84f34ff
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
13 changes: 13 additions & 0 deletions packages/smooth_app/lib/helpers/collections_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ extension StringIterable on Iterable<String> {
}
}

extension IterableExtension<T> on Iterable<T> {
int indexOf(T value) {
int index = 0;
for (final T item in this) {
if (item == value) {
return index;
}
index++;
}
return -1;
}
}

extension ListExtensions<T> on List<T> {
void addAllSafe(Iterable<T>? elements) {
if (elements != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/duration_constants.dart';
import 'package:smooth_app/helpers/collections_helper.dart';
import 'package:smooth_app/helpers/text_input_formatters_helper.dart';
import 'package:smooth_app/pages/product/nutrition_page/nutrition_page.dart';
import 'package:smooth_app/pages/product/nutrition_page/widgets/nutrition_container_helper.dart';
Expand Down Expand Up @@ -115,8 +116,8 @@ class _NutrientRowState extends State<NutrientRow>
children: <Widget>[
Expanded(
child: _NutrientUnitCell(
widget.nutritionContainer,
widget.orderedNutrient,
nutritionContainer: widget.nutritionContainer,
orderedNutrient: widget.orderedNutrient,
),
),
const _NutrientUnitVisibility()
Expand Down Expand Up @@ -228,6 +229,19 @@ class _NutrientValueCell extends StatelessWidget {
),
DecimalSeparatorRewriter(decimalNumberFormat),
],
onFieldSubmitted: (final String value) {
focusNodes[orderedNutrient]?.unfocus();

if (isLast) {
return;
}

final int position =
focusNodes.keys.indexOf(orderedNutrient);

focusNodes[focusNodes.keys.elementAt(position + 1)]
?.requestFocus();
},
validator: (String? value) {
if (value == null || value.trim().isEmpty) {
return null;
Expand Down Expand Up @@ -261,10 +275,10 @@ class _NutrientValueCell extends StatelessWidget {
}

class _NutrientUnitCell extends StatefulWidget {
const _NutrientUnitCell(
this.nutritionContainer,
this.orderedNutrient,
);
const _NutrientUnitCell({
required this.nutritionContainer,
required this.orderedNutrient,
});

final NutritionContainerHelper nutritionContainer;
final OrderedNutrient orderedNutrient;
Expand Down

0 comments on commit 84f34ff

Please sign in to comment.