抖动图像转换

时间:2019-11-22 09:51:44

标签: flutter dart flutter-layout flutter-image

我正在尝试选择资产图片-> base64image字符串->显示它 但是它没有按预期工作。我的代码如下:

ImagePickPart:

ByteData bytes = await rootBundle.load(_images[_ran.nextInt(_images.length)]);
String asBase64 = base64Encode((bytes.buffer.asUint8List()).cast<int>());
Site site= Site();
site.image = asBase64;

ShowImage部分:

 @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(8.0),
        decoration: BoxDecoration(
          boxShadow: [BoxShadow(
            color: Colors.grey[500],
            offset:Offset(0.0,0.0),
            blurRadius: 5.0,
            spreadRadius: 0.0,
          )],
          borderRadius: BorderRadius.only(topLeft:Radius.circular(00.0),topRight:Radius.elliptical(75.0, 75.0)),
          image : DecorationImage(
            image: site.image!=null? Image.memory(base64Decode(site.image)):AssetImage('images/1024LowPoly.png'),
            fit: BoxFit.cover
          ),
        ),...........

我得到以下错误:

type 'Image' is not a subtype of type 'ImageProvider<dynamic>'

1 个答案:

答案 0 :(得分:0)

确定了答案。

我应该使用MemoryImage而不是Image.memory!