Flutter布局:如何将重点放在包裹在容器上的TextFormfield中
因此,我有这个具有特定装饰边框的容器,小时候,我使用parameter enabledborder
的TextFormField带有另一个样式的边框。
我的问题是:我必须进行双击以显示光标并能够在我的TextFormField上写入,因为焦点只能获得容器的装饰,并且不会从我的TextFormfield的内部获得焦点。
这是我的代码:
onFocusChange: (focus) {
print(focus);
},
child: Focus(
child: Container(
decoration: _focusNode.hasFocus && widget.errorText == null
? BambamShadows.dropShadowSelected()
: null,
child: TextFormField(
cursorColor: BambamColors.brandBlack,
focusNode: _focusNode,
inputFormatters: widget.inputFormatters,
enabled: widget.enabled,
onChanged: widget.onChanged,
如何在容器和TextFormField中既将重点放在?
So I have this Container with a specific decoration border, and as a child I have the TextFormField with another styled border using the parameter enabledBorder
.
My problem is: I have to make a double click to show the cursor and be able to write on my textformfield, because the focus only gets the container decoration and do not gets the focus from the inside of my TextFormField.
Here is my code:
onFocusChange: (focus) {
print(focus);
},
child: Focus(
child: Container(
decoration: _focusNode.hasFocus && widget.errorText == null
? BambamShadows.dropShadowSelected()
: null,
child: TextFormField(
cursorColor: BambamColors.brandBlack,
focusNode: _focusNode,
inputFormatters: widget.inputFormatters,
enabled: widget.enabled,
onChanged: widget.onChanged,
How can I get both Focus inside Container and TextFormField?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看此软件包 @ https://pub.dev/packages/packages/indexed 它将授予您的授予您Z索引在CSS中具有相同的等效属性,该属性将使您可以根据索引将元素定位在堆栈中;因此,基于您的问题,如果您的TxTFormField具有较高的索引,则不会“低于”容器(如果有道理);
另外,您始终可以考虑修改UI以专注于使用堆栈(在此处进行的非常好的文档: https://medium.flutterdevs.com/stack-and-posited-widget-widget-in-flutter-3d1a7b30b09a )
我会尝试索引实现堆栈UI结构并测试不同的变体,直到钉住它为止;
Check out this package @ https://pub.dev/packages/indexed it'll grant you the same equivalent property that Z-index has in CSS which will allow you to position elements in a stack based on the index; so based on your question if your txtformField has a higher index it wouldn't be "below" the container (if that makes sense);
Also you can always consider modifying your UI to focus on using Stack (very good documentation about it here: https://medium.flutterdevs.com/stack-and-positioned-widget-in-flutter-3d1a7b30b09a)
I'd try indexed, else I'd clone your current java to implement a stack UI structure and test different variants till you nail it;
尝试此
自动对焦:true,
autococus是textformfield类中的属性Try this
autofocus: true,
autofocus is a property in TextFormField class