[英]how can I change TextField Focus with iOS keyboard upper button on Flutter
textfield focus change image文本字段焦点更改图像
Hi Everyone I'm trying to change focus on textfiealds by clicking the buttons that appear in the picture.大家好,我正在尝试通过单击图片中出现的按钮来改变对 textfields 的关注。
I tried FocusScope.of(context).nextFocus();
我试过
FocusScope.of(context).nextFocus();
this method.这种方法。 When I run this method, the keyboard closes and the focus on the currently active textfield is lost also the next textfield is not active.
当我运行此方法时,键盘关闭,当前活动文本字段的焦点丢失,下一个文本字段也未激活。
Can anyone help me.谁能帮我。
My Flutter version is: 3.0.5我的Flutter版本是:3.0.5
flutter doctor outputs: flutter 博士输出:
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79
darwin-arm, locale en-US)
• Flutter version 3.0.5 at
/Users/seniorturkmen/fvm/versions/stable
• Upstream repository
https://github.com/flutter/flutter.git
• Framework revision f1875d570e (5 weeks ago),
2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[!] Android toolchain - develop for Android devices
(Android SDK version 33.0.0)
• Android SDK at
/Users/seniorturkmen/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android
Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
11.0.12+0-b1504.28-7817840)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept
the SDK licenses.
See
https://flutter.dev/docs/get-started/install/maco
s#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
• Xcode at
/Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google
Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android
Studio.app/Contents
• Flutter plugin can be installed from:
🔨
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build
11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.70.1)
• VS Code at /Applications/Visual Studio
Code.app/Contents
• Flutter extension version 3.46.0
[✓] Connected device (3 available)
• iPhone 12 (mobile) •
AC295A39-16D5-4B2C-8A9F-567492AD9E01 • ios
• com.apple.CoreSimulator.SimRuntime.iOS-15-5
(simulator)
• macOS (desktop) • macos
• darwin-arm64 • macOS 12.4 21F79 darwin-arm
• Chrome (web) • chrome
• web-javascript • Google Chrome 104.0.5112.79
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
Edit编辑
Keyboard Actions Widget code's below键盘操作小部件代码如下
void showOverlay(
BuildContext context,
) {
if (overlayEntry != null) return;
OverlayState? overlayState = Overlay.of(context);
overlayEntry = OverlayEntry(
builder: (context) {
return Positioned(
bottom: MediaQuery.of(context).viewInsets.bottom,
right: 0.0,
left: 0.0,
child: KeyboardInputWidget(
previous: FocusScope.of(context).previousFocus,
next: FocusScope.of(context).nextFocus,
),
);
},
);
overlayState?.insert(overlayEntry!);
}
you must check the context
i think your FocusScope using the `overlay's context你必须检查
context
我认为你的 FocusScope 使用`覆盖的上下文
void showOverlay(
BuildContext context,
) {
if (overlayEntry != null) return;
OverlayState? overlayState = Overlay.of(context);
overlayEntry = OverlayEntry(
builder: (ctx) {
return Positioned(
bottom: MediaQuery.of(context).viewInsets.bottom,
right: 0.0,
left: 0.0,
child: KeyboardInputWidget(
previous: FocusScope.of(context).previousFocus,
next: FocusScope.of(context).nextFocus,
),
);
},
);
overlayState?.insert(overlayEntry!);
}
Add TextInputAction
parameter in TextField
.在
TextField
中添加TextInputAction
参数。
TextFormField(
textInputAction: TextInputAction.next,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.