首页 > 解决方案 > Flutter - 如何重启或重绘当前屏幕小部件

问题描述

我正在使用导航抽屉,在其中我设计了一个屏幕名称作为 PostProperty 屏幕,其中实现了多个文本表单字段,图像上传,我想要的是当用户单击提交/添加按钮时,当前屏幕小部件应该是重绘或所有表单字段应该清楚,以便用户可以提交/添加另一个,请指导我,如何实现这一点。

小部件构建代码

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      key: scaffoldKey,
      resizeToAvoidBottomPadding: false,
      backgroundColor: Colors.white,
      appBar: showAppbar
          ? AppBar(
              title: new Text(
                setAppBarTitle(val_property_type),
                style:
                    TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
              ),
              centerTitle: true,
              backgroundColor: ColorConstant.bg_color,
            )
          : null,
      body: ModalProgressHUD(
        inAsyncCall: _isInAsyncCall,
        child: buildPropertyForm(context),
        opacity: 0.5,
        progressIndicator: CircularProgressIndicator(),
      ),
    );
  }

buildPropertyForm是我包含所有文本表单字段和其他内容的表单。

请看下面的截图

在此处输入图像描述

在此处输入图像描述

标签: dartflutterflutter-layout

解决方案


提交后,您可以动态更改每个 TextFormField 的键,并将 TextEditingControllers 的值更改为 null。


推荐阅读