微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

小部件中的颤振数据未显示,仅在单击后退按钮并返回小部件页面时才会显示

如何解决小部件中的颤振数据未显示,仅在单击后退按钮并返回小部件页面时才会显示

在课堂上,我有一个小部件,用于附加画廊或相机中的图像。它有效,我的意思是图像已成功选择,但是它没有显示在容器上。它仅在我返回上一页并再次返回小部件时显示。然后出现图像。我希望“附加图像”文本小部件在被选中后立即显示。请帮忙..

这是我的代码。这个小部件在一个类中。

File _imgHepa



Widget _showRegistrationForm2() {
showModalBottomSheet(
    isScrollControlled: true,context: context,builder: (BuildContext context) {
      return SingleChildScrollView(
          child: Container(
            child: Column(
              children: <Widget>[
                Container(
                  child: Image.asset(
                    'assets/docicon.png',),_hepaimageView(),Container(
                  child: FlatButton(
                    onpressed: () {
                      if (_imgHepa == null) {
                        Fluttertoast.showToast(
                            msg: 'please complete all the requirements',} else {
                        _formKey.currentState.save();
                      }
                    },child: Text(
                      "SUBMIT",style: TextStyle(
                        color: Colors.black,fontSize: 15,],));
    });
  }

在_hepaimageView()内部

Widget _hepaimageView() {
return Container(
  padding: EdgeInsets.only(
    left: 20,child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,children: <Widget>[
        _imgHepa == null
            ? AutoSizeText("Attach Image 1")
            : AutoSizeText("Image Attached")
        Container(
          child: InkWell(
            onTap: () {
              _showChoiceDialog(context,1);
            },child: ClipRRect(
              child: Image.asset(
                'assets/clip.png',height: 40,]),);

}

这是 _showChoiceDialog(),它表明图像是来自画廊还是相机。

Future<void> _showChoiceDialog(BuildContext context,int temp) {
return showDialog(
    context: context,builder: (BuildContext context) {
      return AlertDialog(
        title: Text('Choose one'),content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
              GestureDetector(
                child: Text("gallery"),onTap: () {
                  if (temp == 1) {
                    _openHepagallery(context);
                  } 
                },Padding(padding: EdgeInsets.all(8.0)),GestureDetector(
                child: Text("Camera"),onTap: () {
                  if (temp == 1) {
                    _openHepaCamera(context);
                  } 
                },);
    });

}

这是_openHepagallery(),选择图片的部分。

 _openHepagallery(BuildContext context) async {
var pic = await ImagePicker.pickImage(source: ImageSource.gallery);
this.setState(() {
  _imgHepa = pic;
});
Navigator.of(context).pop();

}

我刚刚删除了所有装饰以简要显示代码。我将感谢您的所有帮助和理解。非常感谢!!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。