使用导航器根据Flutter上一个屏幕返回的数据更新变量 [英] Update the variable depending on what data was returned from the previous screen in Flutter using the Navigator

查看:32
本文介绍了使用导航器根据Flutter上一个屏幕返回的数据更新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量_PhotoName,该变量为null,但是当我拍照并在另一个屏幕上重复术语base64时,如果base64不为null,我希望变量_PhotoName为timestamp.img.这是显示此变量的代码部分,还有返回base 64的代码:

I have a variable _PhotoName, this variable is null, but when I take a photo and repeat the term base64 from another screen, I would like the variable _PhotoNameto be a timestamp.img , if base64 is not null. here is the part of the code that displays this variable, and there is also code where base 64 is returned:

              Container(
              padding: EdgeInsets.only(left: 15, right: 15, top: 5),
              color: Colors.white,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Expanded(
                    child: Text(
                        "$_PhotoName",
                        style: TextStyle(color: Colors.black, fontSize: 15)

                    ),

                  ),
                  Expanded(
                    child: ButtonTheme(
                        alignedDropdown: true,
                        child: new RaisedButton.icon(
                          label: Text('Add Image'),//Добавити фото
                          onPressed: () async{
                            _imageB64 = await  Navigator.push(
                                context,
                                MaterialPageRoute(
                                builder: (context) => image.PicturePreview(camera)),
                             );

                          },

                          icon : Icon(Icons.camera_alt),
                        )
                    ),
                  ),

                ],

              ),
            ),

推荐答案

我可能不明白这个问题,但是您可以检查 base64 是否为 null ,如果是,请更新国家

I might have not understood the question but you could check if base64 is null and if so update the state

if (_imageB64 != null) {
    setState ((){
        _PhotoName = WHAT_IT_NEEDS_TO_BE_EQUAL_TO;
    });
}

这篇关于使用导航器根据Flutter上一个屏幕返回的数据更新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆