解码BASE64后抖动显示图像

时间:2017-11-20 18:13:55

标签: flutter

所以我已成功将图像编码为Base64并在JSON字段中存储为JSON字符串。好吧,我相信我有,当我检索字段,然后尝试解码它,如果它在那里,我试图显示。我一直收到错误,没有图片出现。我已经尝试了几件事,但是从Image_provider或Framework继续得到断言错误。我在调试过程中确认我只有1条记录进入图像数据并且它被解码并且断言看起来正确。有什么想法或想法吗?

    @override
  Widget build(BuildContext context) {
    _key = new PageStorageKey('${widget.datediv.toString()}');
    return new Column(
      children: <Widget>[
        new Container(
          child: new Text(
            mydate,
            textAlign: TextAlign.left,
            style: new TextStyle( color: Colors.grey, fontWeight: FontWeight.bold,),

          ),
          alignment: Alignment.centerLeft,
          padding: new EdgeInsets.only(left: 10.0),
        ),
        new Container(
          child: new Divider(
            height: 5.0,
            color: Colors.grey,
          ),
          padding: new EdgeInsets.only(left: 10.0, right: 10.0),
        ),
        /**/
        new FutureBuilder(
          future: _responseFuture,
          builder:
              (BuildContext context, AsyncSnapshot<http.Response> response) {
            if (!response.hasData) {
              return const Center(
                child: const Text('Loading Messages...'),
              );
            } else if (response.data.statusCode != 200) {
              return const Center(
                child: const Text('Error loading data'),
              );
            } else {
              List<dynamic> json = JSON.decode(response.data.body);
              messagelist = [];
              json.forEach((element) {
                DateTime submitdate =
                DateTime.parse(element['submitdate']).toLocal();
                if (element['image'] != null) {
                  imgStr = element['image'];
                  Uint8List mybytes = BASE64.decode(imgStr);

                }
                _addImage() {
                  assert(imgStr != null);

                  new Container(
                    width: 150.0,
                    child: new Image.memory(mybytes),
                  );
                }
                _addNoImage() {
                  assert(imgStr == null);
                  new Text('');
                }
                messagelist.add(new Container(
                  //width: 300.0,
                  padding: new EdgeInsets.all(10.0),
                  child: new Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      new Container(
                        padding: new EdgeInsets.only(bottom: 5.0),
                        child: new Row(
                          mainAxisSize: MainAxisSize.min,
                          children: <Widget>[
                            new CircleAvatar(
                              child: new Text(element['sendname'][0], style: new TextStyle(fontSize: 15.0),),
                              radius: 12.0,
                            ),
                            new Text('    '),
                            new Text(
                              element['sendname'],
                              style: new TextStyle(
                                  fontSize: 15.0, fontWeight: FontWeight.bold),
                            ),
                            new Text('    '),
                            new Text(new DateFormat.Hm().format(submitdate), style: new TextStyle(color: Colors.grey, fontSize: 12.0),),

                          ],
                        ),
                      ),


                      new Row(
                        children: <Widget>[
                          new Text('          '),
                          new Flexible(
                              child: new Text('${element['message']}'),
                          )
                        ],
                      ),
                      imgStr != null ? _addImage(): _addNoImage(),

                    ],
                  ),
                ),
                );
              });
              return new Column(children: messagelist);
            }
          },
        ),
      ],
    );
  }

0 个答案:

没有答案