fix: 食物识别编辑框删除bug + VLM相关代码回滚

- 修复饮食识别结果编辑框一次只能删一个字的bug(控制器缓存)
- 回滚VLM图片压缩代码到原始状态
- 保持原有显示逻辑不变
This commit is contained in:
MingNian
2026-06-16 17:08:32 +08:00
parent c70d5d4be6
commit 9279b7e283
2 changed files with 52 additions and 42 deletions

View File

@@ -593,6 +593,7 @@ class _DietCapturePageState extends ConsumerState<DietCapturePage> {
(v) => ref
.read(dietProvider.notifier)
.updateFoodName(food.id, v),
fieldKey: '${food.id}_name',
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
@@ -608,6 +609,7 @@ class _DietCapturePageState extends ConsumerState<DietCapturePage> {
(v) => ref
.read(dietProvider.notifier)
.updateFoodPortion(food.id, v),
fieldKey: '${food.id}_portion',
hint: '份量',
style: const TextStyle(
fontSize: 14,
@@ -629,6 +631,7 @@ class _DietCapturePageState extends ConsumerState<DietCapturePage> {
food.id,
int.tryParse(v) ?? 0,
),
fieldKey: '${food.id}_cal',
hint: '0',
style: const TextStyle(
fontSize: 14,
@@ -664,16 +667,26 @@ class _DietCapturePageState extends ConsumerState<DietCapturePage> {
);
}
final Map<String, TextEditingController> _fieldCtrls = {};
TextEditingController _ctrlFor(String key, String value) {
if (_fieldCtrls.containsKey(key)) return _fieldCtrls[key]!;
final c = TextEditingController(text: value);
_fieldCtrls[key] = c;
return c;
}
Widget _compactField(
String value,
ValueChanged<String> cb, {
required String fieldKey,
String? hint,
TextStyle? style,
TextAlign align = TextAlign.start,
TextInputType? keyboardType,
}) {
return TextField(
controller: TextEditingController(text: value),
controller: _ctrlFor(fieldKey, value),
onChanged: cb,
keyboardType: keyboardType,
textAlign: align,

View File

@@ -1245,47 +1245,11 @@ class ChatMessagesView extends ConsumerWidget {
ChatMessage msg,
WidgetRef ref,
) {
return StatefulBuilder(
builder: (context, setState) {
final controller = TextEditingController(text: field.value);
return TextField(
controller: controller,
autofocus: true,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: AppColors.textPrimary,
),
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
filled: true,
fillColor: Colors.white,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: AppColors.primary.withAlpha(80)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(
color: AppColors.primary,
width: 1.5,
),
),
),
onSubmitted: (value) {
ref
.read(chatProvider.notifier)
.finishEditingField(msg.id, field.label, value);
},
onTapOutside: (_) {
ref
.read(chatProvider.notifier)
.finishEditingField(msg.id, field.label, controller.text);
},
);
return _EditFieldCell(
key: ValueKey('editing_${msg.id}_${field.label}'),
initialValue: field.value,
onDone: (value) {
ref.read(chatProvider.notifier).finishEditingField(msg.id, field.label, value);
},
);
}
@@ -2478,3 +2442,36 @@ class _ExpandableAdviceState extends State<_ExpandableAdvice> {
);
}
}
class _EditFieldCell extends StatefulWidget {
final String initialValue;
final ValueChanged<String> onDone;
const _EditFieldCell({super.key, required this.initialValue, required this.onDone});
@override State<_EditFieldCell> createState() => _EditFieldCellState();
}
class _EditFieldCellState extends State<_EditFieldCell> {
late final TextEditingController _ctrl;
@override void initState() {
super.initState();
_ctrl = TextEditingController(text: widget.initialValue);
}
@override void dispose() { _ctrl.dispose(); super.dispose(); }
@override Widget build(BuildContext context) => TextField(
controller: _ctrl,
autofocus: true,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1E293B)),
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
filled: true, fillColor: Colors.white,
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: BorderSide(color: const Color(0xFF6366F1).withAlpha(80))),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: const BorderSide(color: Color(0xFF6366F1), width: 1.5)),
),
onSubmitted: widget.onDone,
onTapOutside: (_) => widget.onDone(_ctrl.text),
);
}