Flutter布局:如何将重点放在包裹在容器上的TextFormfield中

发布于 2025-01-24 09:48:19 字数 811 浏览 0 评论 0原文

因此,我有这个具有特定装饰边框的容器,小时候,我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺孤伤于心 2025-01-31 09:48:19

查看此软件包 @ 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;

夜还是长夜 2025-01-31 09:48:19

尝试此自动对焦:true, autococus是textformfield类中的属性

Try this autofocus: true, autofocus is a property in TextFormField class

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文