Android 上的 Flutter TextFormField 中“粘贴”有时不可用

Tho*_*rge 8 keyboard android toolbar paste flutter

我们的一些 Android 用户抱怨他们无法将笔记应用中的文本粘贴到我们的应用中。

如果我做了一些奇怪的事情,比如打开我们的应用程序,从我们的文本字段复制一些内容,将其粘贴到另一个笔记应用程序中,然后粘贴功能突然起作用,我可以让它恢复工作一段时间。

我注意到键盘上的文本编辑功能也无法识别剪贴板中的内容,而它可以识别 Google Notes 中的内容。

[1]:https://i.stack.imgur.com/yVKoB.jpg [1]

[2]:https://i.stack.imgur.com/MNm5O.jpg [2]

TextFormField(
          textCapitalization: TextCapitalization.sentences,
          keyboardType: TextInputType.multiline,
          minLines: 3,
          maxLines: null,
          autofocus: true,
          onFieldSubmitted: (value) {
            mood.text = value;
          },
          onChanged: (value) {
            setState(() {
              mood.text = value;
            });
          },
          style: TextStyle(color: Colors.white70, fontSize: 18),
          cursorColor: Colors.white70,
          decoration: InputDecoration(
            border: InputBorder.none,
            focusColor: Colors.white70,
            filled: true,
            fillColor: Color(0xFF1F202A),
            hintMaxLines: 3,
            hintText: locator.get<Translation>().add_mood_screen_textfield,
            hintStyle: TextStyle(color: Colors.white70, fontSize: 18),
          ))
Run Code Online (Sandbox Code Playgroud)

小智 0

您在将文本“粘贴”到 Flutter 应用程序时遇到的问题可能与 TextFormField 的具体设置有关。确保您已启用粘贴属性并正确设置控制器属性。

TextEditingController moodController = TextEditingController();

TextFormField(
  controller: moodController,
  textCapitalization: TextCapitalization.sentences,
  keyboardType: TextInputType.multiline,
  minLines: 3,
  maxLines: null,
  autofocus: true,
  onFieldSubmitted: (value) {
    // Handle field submission if needed
  },
  onChanged: (value) {
    // Handle field changes if needed
  },
  style: TextStyle(color: Colors.white70, fontSize: 18),
  cursorColor: Colors.white70,
  decoration: InputDecoration(
    border: InputBorder.none,
    focusColor: Colors.white70,
    filled: true,
    fillColor: Color(0xFF1F202A),
    hintMaxLines: 3,
    hintText: locator.get<Translation>().add_mood_screen_textfield,
    hintStyle: TextStyle(color: Colors.white70, fontSize: 18),
  ),
  enableInteractiveSelection: true, // Ensure text is selectable
  enableSuggestions: true, // Enable text suggestions
  readOnly: false, // Allow editing
  onTap: () {
    // Handle tap if needed
  },
);
Run Code Online (Sandbox Code Playgroud)