|
|
@ -75,8 +75,8 @@ class AgentController extends GetxController { |
|
|
final isFullScreenEditMode = false.obs; // 是否处于全屏编辑模式 |
|
|
final isFullScreenEditMode = false.obs; // 是否处于全屏编辑模式 |
|
|
final shouldShowExpandButton = false.obs; // 是否显示展开按钮 |
|
|
final shouldShowExpandButton = false.obs; // 是否显示展开按钮 |
|
|
|
|
|
|
|
|
// 图片选择选项展开状态 |
|
|
// "+"号选项展开状态 |
|
|
final isImageOptionsExpanded = false.obs; // 是否展开图片选择选项 |
|
|
final isPlusOptionsExpanded = false.obs; // 是否展开"+"号选项 |
|
|
|
|
|
|
|
|
// 键盘状态 |
|
|
// 键盘状态 |
|
|
final isKeyboardVisible = false.obs; // 键盘是否可见 |
|
|
final isKeyboardVisible = false.obs; // 键盘是否可见 |
|
|
@ -904,39 +904,65 @@ class AgentController extends GetxController { |
|
|
isImageInputActive.value = false; |
|
|
isImageInputActive.value = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 切换图片选项展开状态 |
|
|
// 切换'+'选项展开状态 |
|
|
void toggleImageOptions() { |
|
|
void togglePlusOptions() { |
|
|
if (isImageOptionsExpanded.value) { |
|
|
if (isPlusOptionsExpanded.value) { |
|
|
// 如果当前已展开,则收缩 |
|
|
// 如果当前已展开,则收缩 |
|
|
collapseImageOptions(); |
|
|
collapsePlusOptions(); |
|
|
|
|
|
_pendingPlusOptionsExpansion = false; // 取消待展开状态 |
|
|
} else { |
|
|
} else { |
|
|
// 如果当前未展开,则展开并关闭键盘 |
|
|
// 如果当前未展开,则展开并关闭键盘 |
|
|
if (isKeyboardVisible.value) { |
|
|
if (isKeyboardVisible.value) { |
|
|
|
|
|
// 设置待展开标记 |
|
|
|
|
|
_pendingPlusOptionsExpansion = true; |
|
|
hideKeyboard(); |
|
|
hideKeyboard(); |
|
|
// 延迟展开选项,等待键盘完全关闭 |
|
|
// 使用双重机制:轮询检测 + 键盘状态监听 |
|
|
Future.delayed(const Duration(milliseconds: 200), () { |
|
|
_waitForKeyboardToClose(); |
|
|
// 再次检查键盘状态,确保键盘已关闭 |
|
|
|
|
|
if (!isKeyboardVisible.value) { |
|
|
|
|
|
isImageOptionsExpanded.value = true; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 如果键盘还没关闭,再等一会儿 |
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 100), () { |
|
|
|
|
|
if (!isKeyboardVisible.value) { |
|
|
|
|
|
isImageOptionsExpanded.value = true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// 键盘未显示,直接展开 |
|
|
// 键盘未显示,直接展开 |
|
|
isImageOptionsExpanded.value = true; |
|
|
isPlusOptionsExpanded.value = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 收缩图片选项 |
|
|
// 等待键盘关闭的轮询机制 |
|
|
void collapseImageOptions() { |
|
|
void _waitForKeyboardToClose() { |
|
|
isImageOptionsExpanded.value = false; |
|
|
int attempts = 0; |
|
|
|
|
|
const maxAttempts = 30; // 最多尝试30次,总计3秒 |
|
|
|
|
|
const checkInterval = Duration(milliseconds: 100); // 每100ms检查一次 |
|
|
|
|
|
|
|
|
|
|
|
Timer.periodic(checkInterval, (timer) { |
|
|
|
|
|
attempts++; |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否还需要展开(用户可能已经取消了) |
|
|
|
|
|
if (!_pendingPlusOptionsExpansion) { |
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!isKeyboardVisible.value) { |
|
|
|
|
|
// 键盘已关闭,展开选项 |
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
_pendingPlusOptionsExpansion = false; |
|
|
|
|
|
// 添加小延迟确保UI稳定 |
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 50), () { |
|
|
|
|
|
if (!isKeyboardVisible.value) { // 再次确认键盘状态 |
|
|
|
|
|
isPlusOptionsExpanded.value = true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else if (attempts >= maxAttempts) { |
|
|
|
|
|
// 超时,强制展开(可能键盘检测有问题) |
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
_pendingPlusOptionsExpansion = false; |
|
|
|
|
|
Logger.d('AgentController', '键盘关闭检测超时,强制展开选项'); |
|
|
|
|
|
isPlusOptionsExpanded.value = true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 收缩'+'选项 |
|
|
|
|
|
void collapsePlusOptions() { |
|
|
|
|
|
isPlusOptionsExpanded.value = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 更新键盘可见状态 |
|
|
// 更新键盘可见状态 |
|
|
@ -944,13 +970,26 @@ class AgentController extends GetxController { |
|
|
final wasVisible = isKeyboardVisible.value; |
|
|
final wasVisible = isKeyboardVisible.value; |
|
|
isKeyboardVisible.value = isVisible; |
|
|
isKeyboardVisible.value = isVisible; |
|
|
|
|
|
|
|
|
// 只有当键盘从隐藏变为显示时,才收缩图片选项 |
|
|
// 只有当键盘从隐藏变为显示时,才收缩'+'选项 |
|
|
// 避免键盘关闭时误触发收缩逻辑 |
|
|
// 避免键盘关闭时误触发收缩逻辑 |
|
|
if (!wasVisible && isVisible && isImageOptionsExpanded.value) { |
|
|
if (!wasVisible && isVisible && isPlusOptionsExpanded.value) { |
|
|
collapseImageOptions(); |
|
|
collapsePlusOptions(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果键盘关闭了,并且有待展开的选项,则展开 |
|
|
|
|
|
if (wasVisible && !isVisible && _pendingPlusOptionsExpansion) { |
|
|
|
|
|
_pendingPlusOptionsExpansion = false; |
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 100), () { |
|
|
|
|
|
if (!isKeyboardVisible.value) { |
|
|
|
|
|
isPlusOptionsExpanded.value = true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 标记是否有待展开的'+'选项 |
|
|
|
|
|
bool _pendingPlusOptionsExpansion = false; |
|
|
|
|
|
|
|
|
// 隐藏键盘 |
|
|
// 隐藏键盘 |
|
|
void hideKeyboard() { |
|
|
void hideKeyboard() { |
|
|
FocusManager.instance.primaryFocus?.unfocus(); |
|
|
FocusManager.instance.primaryFocus?.unfocus(); |
|
|
|