从警报对话框调用setstate时,父UI不会更新

时间:2019-07-22 09:42:55

标签: flutter

我正在尝试从设备中拾取图像,然后将其发送到后端并显示微调框。我现在的问题是,即使我的任务运行顺利,即使调用setstate之后,微调器仍无法启动。我在setState中放置了一条print语句,它清楚地表明该方法实际上在运行,但UI只是不反映状态的变化。我正在从alertdialog进行所有这些操作,甚至尝试使用statebuilder进行操作,但仍然一无所获。这是我的代码 请忽略任何遗漏的括号。

        class Edit extends StatefulWidget {


          @override
          _EditState createState() => _EditState();
        }


        class _EditState extends State<Edit> {

          File uploadedProfileImage;
          var shownProfilePhoto;


        void _showDialog() {
            // flutter defined function
            showDialog (
              context: context,
              builder: (BuildContext context) {
                // return object of type Dialog
                return AlertDialog(

                        content: Expanded(
                          child: IconButton(
                            icon: Icon(Icons.camera),
                            color: Colors.lightBlueAccent,
                            iconSize: 30.0,
                            onPressed: () async {
                              try {
                                var result = await imageHelper.getImageCamera();
                                Navigator.of(context).pop();
                                if (result != null) {
                                  setState(() {
                                    uploadedProfileImage = result;
                                    shownProfilePhoto = Center(
                                      child: SpinKitDoubleBounce(
                                        color: Colors.blueAccent,
                                        size: 50.0,
                                      ),\\ this is where i need the code to update the screen
                                    );
                                  });
                                }


                              } catch (e) {
                                print(e);

                        }
          )
        );
        }
        );
        }

        @override
          Widget build(BuildContext context) {
            return Scaffold(

              body:Stack(
                            children: <Widget>[
                              CircleAvatar(
                                  backgroundColor: Colors.grey,
                                  radius: 60.0,
                                  child: ClipOval(
                                    child: shownProfilePhoto = Image.network(
                                            'Someurl',
                                            fit: BoxFit.cover,
                                            width: 120.0,
                                            height: 120.0,
                                          ),
                                  )),
                           FloatingActionButton(
                                child: Icon(Icons.camera_alt),
                                onPressed: () {
                                   _showDialog();
                                }),


       ]
    )
            );
            }

0 个答案:

没有答案