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 showModalBottomSheet触发Futurebuilder_Flutter_Dart_Flutter Layout_Flutter Test - Fatal编程技术网

Flutter showModalBottomSheet触发Futurebuilder

Flutter showModalBottomSheet触发Futurebuilder,flutter,dart,flutter-layout,flutter-test,Flutter,Dart,Flutter Layout,Flutter Test,我在这件事上真的很沮丧 我有3个函数,在每个函数中调用showModalBottomSheet 2个模态是有状态的,1个是无状态的 我对另一个有状态模态有问题 它们都是使用InkWell的onTap函数调用的。而且两者都没有占据整个屏幕,因此显示主页 我的状态模式不会触发未来/不会刷新页面: void showCommentsModal(int id) { showModalBottomSheet( shape: RoundedRectangleBorder(

我在这件事上真的很沮丧

我有3个函数,在每个函数中调用
showModalBottomSheet

2个模态是有状态的,1个是无状态的

我对另一个有状态模态有问题

它们都是使用InkWell的
onTap
函数调用的。而且两者都没有占据整个屏幕,因此显示主页

我的状态模式不会触发未来/不会刷新页面:

void showCommentsModal(int id) {
    showModalBottomSheet(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0),
      ),
      backgroundColor: Color(colorBackground),
      isScrollControlled: true,
      context: context,
      builder: (BuildContext context) {
        return Container(
          padding: EdgeInsets.all(10),
          decoration: BoxDecoration(
              color: Color(colorBackground),
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(20), topRight: Radius.circular(20))),
          height: MediaQuery.of(context).size.height / 1.5,
          width: MediaQuery.of(context).size.width,
          child: ViewCommentModal(
            postID: id,
            userList: userList,
          ),
        );
      },
    );
  }
另一个触发未来/刷新列表的有状态模式:

 addCommentModal(int i) {
    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
触发了未来?请帮忙

编辑我抓到嫌疑犯了 这是我的
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();
  String defaultProfilePhoto = "";
  @override
  void initState() {
    defaultProfilePhoto = Constants.userFirstName[0].toUpperCase();
    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    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: TextFormField(
                controller: commentController,
                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),
                    ),
                    focusedBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.all(Radius.circular(20)),
                        borderSide:
                            BorderSide(width: 1, color: Color(0xFFff8b50)))),
                keyboardType: TextInputType.text,
                style: new TextStyle(fontFamily: "Poppins", fontSize: 15),
              ),
            ))
          ],
        ));
  }
}
class AddCommentModal扩展StatefulWidget{
最终价值在邮寄时更改;
AddCommentModal({@required this.onPost});
@凌驾
_AddCommentModalState createState()=>AddCommentModalState();
}
类_AddCommentModalState扩展状态{
final commentController=TextEditingController();
字符串defaultProfilePhoto=“”;
@凌驾
void initState(){
defaultProfilePhoto=Constants.userFirstName[0].toUpperCase();
super.initState();
}
@凌驾
无效处置(){
commentController.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回容器(
填充:边缘设置。全部(10),
孩子:排(
儿童:[
容器(
宽度:50,
身高:50,
孩子:ClipRRect(
边界半径:新边界半径。圆形(50),
子项:Constants.userProfilePhoto==null
?容器(
颜色:颜色(colorPrimary),
对齐:对齐.center,
子:文本(
照片,,
样式:TextStyle(
颜色:颜色(彩色文本),字体大小:20),
),
)
:Image.net(
APIServices.httpDomain+Constants.userProfilePhoto,
适合:BoxFit.cover,
)),
),
扩大(
子:容器(
页边距:仅限边距(
左:10,,
),
子项:TextFormField(
控制器:控制器,
装饰:新的输入装饰(
后缀:图标按钮(
onPressed:()=>widget.onPost(commentController.text),
图标:图标(
FontAwesomeIcons.paperPlane,
尺码:15,
颜色:主题。背景。原色,
)),
contentPadding:EdgeInsets.all(10),
hintText:“添加注释…”,
fillColor:Colors.white,
边框:新大纲输入边框(
边界半径:新边界半径。圆形(20.0),
),
聚焦顺序:大纲输入边框(
borderRadius:borderRadius.all(半径圆形(20)),
边界:
边框边(宽度:1,颜色:颜色(0xFFff8b50)),
键盘类型:TextInputType.text,
样式:新文本样式(fontFamily:“Poppins”,fontSize:15),
),
))
],
));
}
}
导致页面刷新的问题是由于每当聚焦
TextFormField
时弹出的软键盘


当我显示模态时,它运行平稳。但是当我开始点击
字段时,页面会刷新,就好像未来再次被调用一样。

您能编辑您的问题并添加AddCommentModal代码吗?我的初步猜测是,它可能通过APIServices与您的列表交互?嗨!我已经添加了AddCommentModal代码。谢谢您能编辑您的问题并添加AddCommentModal代码吗?我的初步猜测是,它可能通过APIServices与您的列表交互?嗨!我已经添加了AddCommentModal代码。谢谢