Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

fix textfield cannot unfocus on mobile device

ErBW_s4a7b1287e73f
diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dart
index 237b7dbc..8f716668 100644
--- a/lib/pages/player/player_item_panel.dart
+++ b/lib/pages/player/player_item_panel.dart
@@ -64,6 +64,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
final InfoController infoController = Modular.get<InfoController>();
final PlayerController playerController = Modular.get<PlayerController>();
final TextEditingController textController = TextEditingController();
+ final FocusNode textFieldFocus = FocusNode();
Future<void> _handleScreenshot() async {
KazumiDialog.showToast(message: '截图中...');
@@ -91,13 +92,14 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
playerController.danmakuOn = !playerController.danmakuOn;
}
- Widget danmakuTextField() {
+ Widget get danmakuTextField {
return Container(
constraints: Utils.isDesktop()
? const BoxConstraints(maxWidth: 500, maxHeight: 33)
: const BoxConstraints(maxHeight: 33),
padding: const EdgeInsets.symmetric(horizontal: 8),
child: TextField(
+ focusNode: textFieldFocus,
style: TextStyle(
fontSize: Utils.isDesktop() ? 15 : 13, color: Colors.white),
controller: textController,
@@ -120,6 +122,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
),
suffixIcon: TextButton(
onPressed: () {
+ textFieldFocus.unfocus();
widget.sendDanmaku(textController.text);
textController.clear();
},
@@ -143,6 +146,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
playerController.canHidePlayerPanel = false;
},
onSubmitted: (msg) {
+ textFieldFocus.unfocus();
widget.sendDanmaku(msg);
widget.cancelHideTimer();
widget.startHideTimer();
@@ -153,6 +157,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
widget.cancelHideTimer();
widget.startHideTimer();
playerController.canHidePlayerPanel = true;
+ textFieldFocus.unfocus();
widget.keyboardFocus.requestFocus();
},
),
@@ -855,8 +860,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
icon: const Icon(
Icons.tune_rounded),
),
- if (isSpaceEnough)
- danmakuTextField(),
+ if (isSpaceEnough) danmakuTextField,
],
),
);
@@ -890,7 +894,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
color: Colors.white,
icon: const Icon(Icons.tune_rounded),
),
- Expanded(child: danmakuTextField()),
+ Expanded(child: danmakuTextField),
],
if (!playerController.danmakuOn) const Spacer(),
],