Flutter textfield焦点触发UI的重建

Flutter textfield焦点触发UI的重建,flutter,dart,flutter-layout,flutter-test,Flutter,Dart,Flutter Layout,Flutter Test,当我设置Textfieldautofocus:false时,它不会刷新页面,但当我点击Textfield时,键盘会显示主页重建,这会导致延迟 这已经是一个近一周的问题了。我可以找到与textfields重建UI相关的问题,但解决方案无法应用于我的 单击按钮时,主页面包含此功能 void addCommentModal() { showModalBottomSheet( context: context, builder: (BuildContext context

当我设置
Textfield
autofocus:false
时,它不会刷新页面,但当我点击Textfield时,键盘会显示主页重建,这会导致延迟

这已经是一个近一周的问题了。我可以找到与textfields重建UI相关的问题,但解决方案无法应用于我的

单击按钮时,主页面包含此功能

void addCommentModal() {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return Container(
          padding:
              EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
          child: AddCommentModal(
            onPost: (String text) {
              // APIServices.commentPost(context, i.toString(), text);
              Navigator.pop(context);
            },
          ),
        );
      },
    );
  }
AddCommentModal

class AddCommentModal extends StatefulWidget {
  final ValueChanged<String> onPost;

  AddCommentModal({@required this.onPost});

  @override
  _AddCommentModalState createState() => _AddCommentModalState();
}

class _AddCommentModalState extends State<AddCommentModal> {

  final commentController = TextEditingController();
  bool _canPost = false;
  String defaultProfilePhoto = "";
  @override
  void initState() {
    defaultProfilePhoto = Constants.userFirstName[0].toUpperCase();
    super.initState();
  }

  @override
  void dispose() {
    commentController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print("PHOTO: ${Constants.userProfilePhoto}");
    return Container(
        padding: EdgeInsets.all(10),
        child: Row(
          children: <Widget>[
            Container(
              width: 50,
              height: 50,
              child: ClipRRect(
                  borderRadius: new BorderRadius.circular(50),
                  child: Constants.userProfilePhoto == null
                      ? Container(
                          color: Color(colorPrimary),
                          alignment: Alignment.center,
                          child: Text(
                            defaultProfilePhoto,
                            style: TextStyle(
                                color: Color(colorText), fontSize: 20),
                          ),
                        )
                      : Image.network(
                          APIServices.httpDomain + Constants.userProfilePhoto,
                          fit: BoxFit.cover,
                        )),
            ),
            Expanded(
                child: Container(
              margin: EdgeInsets.only(
                left: 10,
              ),
              child: TextField(
                controller: commentController,
                autofocus: true,
                decoration: new InputDecoration(
                  suffixIcon: IconButton(
                      onPressed: () => widget.onPost(commentController.text),
                      icon: Icon(
                        FontAwesomeIcons.paperPlane,
                        size: 15,
                        color: Theme.of(context).primaryColor,
                      )),
                  contentPadding: EdgeInsets.all(10),
                  hintText: "Add a comment ...",
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(20.0),
                  ),
                ),
                keyboardType: TextInputType.text,
                style: new TextStyle(fontFamily: "Poppins", fontSize: 15),
              ),
            ))
          ],
        ));
  }
}
class AddCommentModal扩展StatefulWidget{
最终价值在邮寄时更改;
AddCommentModal({@required this.onPost});
@凌驾
_AddCommentModalState createState()=>AddCommentModalState();
}
类_AddCommentModalState扩展状态{
final commentController=TextEditingController();
bool\u canPost=假;
字符串defaultProfilePhoto=“”;
@凌驾
void initState(){
defaultProfilePhoto=Constants.userFirstName[0].toUpperCase();
super.initState();
}
@凌驾
无效处置(){
commentController.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
打印(“照片:${Constants.userProfilePhoto}”);
返回容器(
填充:边缘设置。全部(10),
孩子:排(
儿童:[
容器(
宽度:50,
身高:50,
孩子:ClipRRect(
边界半径:新边界半径。圆形(50),
子项:Constants.userProfilePhoto==null
?容器(
颜色:颜色(colorPrimary),
对齐:对齐.center,
子:文本(
照片,,
样式:TextStyle(
颜色:颜色(彩色文本),字体大小:20),
),
)
:Image.net(
APIServices.httpDomain+Constants.userProfilePhoto,
适合:BoxFit.cover,
)),
),
扩大(
子:容器(
页边距:仅限边距(
左:10,,
),
孩子:TextField(
控制器:控制器,
自动对焦:对,
装饰:新的输入装饰(
后缀:图标按钮(
onPressed:()=>widget.onPost(commentController.text),
图标:图标(
FontAwesomeIcons.paperPlane,
尺码:15,
颜色:主题。背景。原色,
)),
contentPadding:EdgeInsets.all(10),
hintText:“添加注释…”,
fillColor:Colors.white,
边框:新大纲输入边框(
边界半径:新边界半径。圆形(20.0),
),
),
键盘类型:TextInputType.text,
样式:新文本样式(fontFamily:“Poppins”,fontSize:15),
),
))
],
));
}
}

这是由Flatter SDK上的未优化代码引起的:

修复程序最近被合并,并在“主”频道上


考虑使用
flatterchannelmaster

切换到该频道,它是否也会更改我的flatter版本?我目前正在使用稳定版本v1.9.1+修补程序。4:通道uknown:源uknown。它将更改您的颤振版本,是的。在
flatter channel master
尝试调试时,我的应用程序无法运行后,您将切换到1.10+。在调试之前,我也做了
flatterclean
。我想我必须自己解决这个问题。回到马厩,你找到解决办法了吗?我也面临同样的问题。就像我单击文本字段时,键盘会出现,并且需要一些时间来聚焦文本字段。同样,当我关闭键盘时,我可以看到脚手架背景颜色超过1分钟,并且看起来很滞后。