dart 参数类型“Image”不能分配给参数类型“ImageProvider< Object>”

unguejic  于 2023-01-15  发布在  其他
关注(0)|答案(2)|浏览(180)

我试了容器我把image.net的工作在孩子它的工作,但我需要自定义图像的边界。我应该如何修复它?

Expanded(child: Align(alignment:Alignment.center,
        child: Container(
          height: 45, //height, //155,
          width: 45, //width, //155,
          decoration: BoxDecoration(
            color: const Color(0xff7c94b6),
            image: DecorationImage(
            image: Image.network(state
              .offerConfirm
              .ownImage[index]),
         fit: BoxFit.cover,
        ),
        borderRadius: BorderRadius.circular(12),
         ),
        ),
      ),
     flex: 3,
  ),

wh6knrhe

wh6knrhe1#

将图像装饰更改为:

decoration: BoxDecoration(
      image: DecorationImage(image: NetworkImage("urlImage"),
      fit: BoxFit.cover)
    ),

完整代码:

Expanded(
                                            child: Align(
                                              alignment: Alignment.center,
                                              child: Container(
                                                height: 45, //height, //155,
                                                width: 45, //width, //155,
                                                decoration: BoxDecoration(
                                                  color:
                                                      const Color(0xff7c94b6),
                                                  image: DecorationImage(
                                                    image: NetworkImage(state
                                                        .offerConfirm
                                                        .ownImage[index])
                                                    fit: BoxFit.cover,
                                                  ),
                                                  borderRadius:
                                                      BorderRadius.circular(12),
                                                ),
                                              ),
                                            ),
                                            flex: 3,
                                          ),
pcrecxhr

pcrecxhr2#

flutter中有三种类型的图像小部件,
1.网络图像
因此使用NetworkImage("http://imageURL"),代替Image.network("http://imageURL"),
1.资产图像
1.列表项
因此使用AssetImage("assets/book_icon.png"),代替Image.asset('assets/skip-book_icon.png'),
1.内存图像,
因此使用MemoryImage(uint8listBytes),代替Image.memory(uint8listBytes),

相关问题