flutter 自动聚焦在抖动文本域中不工作

ltskdhd1  于 2023-03-31  发布在  Flutter
关注(0)|答案(1)|浏览(123)

如果caneditfoldername==true我想显示一个文本字段,否则我想显示一个文本..但是文本字段中的焦点不工作..有人能修复吗?
code:appBar:AppBar(操作:[ IconButton(

onPressed: () {
                        setState(() {
                          caneditfoldername = true;
                          FocusScope.of(context)
                              .requestFocus(foldertitlefocus);
                        });
                      },
                      icon: Icon(
                        Icons.edit_rounded,
                        size: MediaQuery.of(context).size.height * .028,
                      )))
             
        ],
    
        title: widget.two == false
            ? Text(
                "Add",
               
              )
            :
            caneditfoldername == true ? Padding(
              padding:  EdgeInsets.only(right:  MediaQuery.of(context).size.width * .23,),
              child: TextFormField(
                
          
                  focusNode: foldertitlefocus,
                 
                 autofocus: true,
                 
                  controller: foldertitle,
                 
                 
            ):Text(
                 "My passwords..",
                  
            )
      ),
kupeojn6

kupeojn61#

看起来TextFormField小部件没有正确关闭,请尝试修改:

appBar: AppBar(
  actions: [
    IconButton(
      onPressed: () {
        setState(() {
          caneditfoldername = true;
          FocusScope.of(context).requestFocus(foldertitlefocus);
        });
      },
      icon: Icon(
        Icons.edit_rounded,
        size: MediaQuery.of(context).size.height * .028,
      ),
    ),
  ],
  title: widget.two == false
      ? Text(
          "Add",
        )
      : caneditfoldername == true
          ? Padding(
              padding: EdgeInsets.only(
                right: MediaQuery.of(context).size.width * .23,
              ),
              child: TextFormField(
                focusNode: foldertitlefocus,
                autofocus: true,
                controller: foldertitle,
              ),
            )
          : Text(
              "My passwords..",
            ),
),

相关问题