Skip to content

Commit 68a0ebe

Browse files
mqtikclaude
andcommitted
Fix keyboard input on Flutter 3.32+ by passing viewId to TextInputConfiguration
Flutter 3.32 requires a valid viewId when creating TextInputConnection. Without it, keyboard input silently fails with PlatformException. Falls back to PlatformDispatcher.instance.implicitView.viewId. Based on PR TerminalStudio#210 by cnayan. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d35ba2c commit 68a0ebe

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/src/ui/custom_text_edit.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:ui';
2+
13
import 'package:flutter/foundation.dart';
24
import 'package:flutter/material.dart';
35
import 'package:flutter/services.dart';
@@ -15,11 +17,17 @@ class CustomTextEdit extends StatefulWidget {
1517
this.autofocus = false,
1618
this.readOnly = false,
1719
// this.initEditingState = TextEditingValue.empty,
20+
this.viewId,
1821
this.inputType = TextInputType.text,
1922
this.inputAction = TextInputAction.newline,
2023
this.keyboardAppearance = Brightness.light,
2124
this.deleteDetection = false,
22-
});
25+
}) {
26+
viewId = viewId ?? PlatformDispatcher.instance.implicitView?.viewId;
27+
if (viewId == null) {
28+
throw Exception('Cannot open input connection without a valid viewId.');
29+
}
30+
}
2331

2432
final Widget child;
2533

@@ -47,6 +55,8 @@ class CustomTextEdit extends StatefulWidget {
4755

4856
final bool deleteDetection;
4957

58+
late int? viewId;
59+
5060
@override
5161
CustomTextEditState createState() => CustomTextEditState();
5262
}
@@ -160,6 +170,7 @@ class CustomTextEditState extends State<CustomTextEdit> with TextInputClient {
160170
_connection!.show();
161171
} else {
162172
final config = TextInputConfiguration(
173+
viewId: widget.viewId,
163174
inputType: widget.inputType,
164175
inputAction: widget.inputAction,
165176
keyboardAppearance: widget.keyboardAppearance,

0 commit comments

Comments
 (0)