Skip to content

Conversation

@LGKentang
Copy link

@LGKentang LGKentang commented Aug 20, 2025

This PR fixes the issue #262

Summary

  • Prevents the on-screen keyboard from dismissing while editing Base quantity.
  • Reduces rebuild scope during typing for smoother UX.
  • Fixes unit label logic to reflect the selected unit and metric/imperial mode.
  • Uses selected unit during save-time conversions and disposes controllers properly.

What changed

  • Initialize bloc once in initState; stop dispatching in build().
  • BlocBuilder now uses bloc: _editMealBloc (no locator() or .add() in build).
  • Removed the _baseQuantityTextController listener that called setState() on every keystroke.
  • Wrapped kcal/carbs/fat/protein fields in ValueListenableBuilder(_baseQuantityTextController) so only those labels rebuild when base quantity changes.
  • Replaced hardcoded " g/ml" with _unitSuffixForSelected(...).
  • Save-time conversion uses selectedUnit ?? _mealEntity.mealUnit.
  • Added dispose() for all TextEditingControllers.
  • Set keyboardType: TextInputType.numberWithOptions(decimal: true) for Base quantity.

Why

  • Dispatching InitializeEditMealEvent() inside build() caused full widget rebuilds on each keystroke → focus lost → keyboard dropped.
  • Scoping rebuilds to only the fields that need updates keeps the form stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant