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

llycmphe  于 2022-12-24  发布在  Flutter
关注(0)|答案(3)|浏览(191)
body: SingleChildScrollView(
        child: InkWell(
          splashColor: Colors.black87,
          onTap: () {},
          child: Ink.image(
              image: Image.asset('images/logo.png'), // here
            height: 100,
            width: 400,
            fit: BoxFit.cover,
          ),
        ),
      ),

我想在文本按钮上应用资源图像

2w2cym1i

2w2cym1i1#

您可以使用AssetImage

image:AssetImage('images/logo.png'),
afdcj2ne

afdcj2ne2#

它需要ImageProvider类型的图像,您可以使用以下命令对其进行更改

body: SingleChildScrollView(
        child: InkWell(
          splashColor: Colors.black87,
          onTap: () {},
          child: Ink.image(
              image: AssetImage("images/logo.png"),
            height: 100,
            width: 400,
            fit: BoxFit.cover,
          ),
        ),
      ),
w8ntj3qf

w8ntj3qf3#

请尝试以下代码:

body: SingleChildScrollView(
  child: InkWell(
    splashColor: Colors.black87,
    onTap: () {},
    child: Ink.image(
      image: AssetImage('images/logo.png'),
      height: 100,
      width: 400,
      fit: BoxFit.cover,
    ),
  ),
),

相关问题