Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 键盘出现时颤振状态重建_Flutter - Fatal编程技术网

Flutter 键盘出现时颤振状态重建

Flutter 键盘出现时颤振状态重建,flutter,Flutter,大家好 我使用模态底部表单查看评论。当我点击TextField(评论页面)时,所有的小部件也都是父母!为什么所有的小部件都要重新构建。为什么父母也会这么做?我知道键盘何时出现或旋转发生变化,例如重建了StatefulWidget和无状态Widget。但在这种情况下我无能为力。请帮帮我 这里是第页 class CommentPage extends StatelessWidget {final String activityname; final String postid; final Stri

大家好 我使用模态底部表单查看评论。当我点击TextField(评论页面)时,所有的小部件也都是父母!为什么所有的小部件都要重新构建。为什么父母也会这么做?我知道键盘何时出现或旋转发生变化,例如重建了StatefulWidget和无状态Widget。但在这种情况下我无能为力。请帮帮我

这里是第页

class CommentPage extends StatelessWidget {final String activityname;
final String postid;
final String usernameuid;
const CommentPage(
  {Key key,
  @required this.activityname,
  @required this.postid,
  @required this.usernameuid,
  }): super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
  child: Container(
    height: MediaQuery.of(context).size.height * 0.8,
    child: Scaffold(
        resizeToAvoidBottomInset: false,
        resizeToAvoidBottomPadding: false,
        appBar: AppBar(
          title: Text('Coments'),
          centerTitle: true,
        ),
        body: Container(
          height:MediaQuery.of(context).size.height * 0.8,
          width: MediaQuery.of(context).size.width,
          child: ChangeNotifierProvider(
              create: (context) => CommentLikeController(),
              builder: (context, child) => FutureBuilder<List<Comment>>(
                  future: Provider.of<CommentLikeController>(context,
                          listen: false)
                      .initial(),
                  builder: (context, snapshot) {
                    if (snapshot.hasData)
                      return Stack(children: [
                        Positioned(
                          bottom: 50,
                          child: Container(
                            height:
                                MediaQuery.of(context).size.height * 0.8 -
                                    105,
                            width: MediaQuery.of(context).size.width,
                            child: AnimatedList(
                              shrinkWrap: true,
                              reverse: true,
                              key: Provider.of<CommentLikeController>(
                                      context)
                                  .listkey,
                              initialItemCount: snapshot.data.length,

                              itemBuilder: (context, index, animation) {
                                return ListItem(
                                  index: index,
                                  postid: postid,
                                  activityname: activityname,
                                  usernameuid: usernameuid,
                                );
                              },
                            ),
                          ),
                        ),
                        Positioned(
                            bottom: 0,
                            right: 0,
                            child: IconButton(
                                icon: Icon(Icons.add),
                                onPressed: () {
                                  Provider.of<CommentLikeController>(
                                          context,
                                          listen: false)
                                      .add();
                                })),
                        Positioned(
                            bottom: 0,
                            left: 0,
                            child: Container(
                                height: 50,
                                width:
                                    MediaQuery.of(context).size.width - 50,
                                child: TextField()))
                      ]);
                    else
                      return LinearProgressIndicator();
                  })),
        )),
  ),
);
}
}    

注意我还有PageviewItem家长课程。当单击文本字段(键盘出现时)

时,每个字段都会重新生成,从而改变可用屏幕的大小。这会导致
MediaQuery
发生更改。这反过来激发依赖于
MediaQuery
属性的any
build
方法。@jaredbaszler感谢您的回答。我删除了所有MediaQuery代码。并解决了父窗口小部件(PageviewItem)的重建问题。但评论页面仍在重建中。你能帮我吗?当键盘出现时,屏幕的大小就会改变。这会导致
MediaQuery
发生更改。这反过来激发依赖于
MediaQuery
属性的any
build
方法。@jaredbaszler感谢您的回答。我删除了所有MediaQuery代码。并解决了父窗口小部件(PageviewItem)的重建问题。但评论页面仍在重建中。你能帮助我吗?
class PageviewItem extends StatelessWidget {
final DBcontroller value;
final int index;
final String activityname;
final String username;
const PageviewItem(
  {Key key,
  @required this.value,
  @required this.index,
  @required this.activityname,
  @required this.username})
  : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
  child: Stack(
    children: [
      Container(
        child: value.posts[index].urln.contains('.mp4')
            ? VideoItem(value: value, index: index)
            : PhotoItem(value: value, index: index),
      ),
      UserInfo(value: value, index: index),
      Positioned(
          bottom: 5,
          left: 5,
          child: GestureDetector(
            onTap: () {
              showpopup(context);
            }, //show pop up
            child: Container(
              decoration: BoxDecoration(
                  color: Colors.blue[400].withOpacity(0.3),
                  borderRadius: BorderRadius.all(Radius.circular(5))),
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: RichText(text: TextSpan(text: 'Comment')),
              ),
            ),
          )),
      Header(activityname: activityname),
    ],
  ),
);
}
showpopup(context) {
return showModalBottomSheet(
  shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.only(
          topLeft: Radius.circular(10), topRight: Radius.circular(10))),
  isScrollControlled: true,
  context: context,
  builder: (context1) {
    return CommentPage(
      activityname: activityname,
      postid: value.posts[index].from_uid,
      usernameuid: username,
    );
  },
);
}
}