flutter 如何在www.example.com上显示图标Image.network?

sauutmhj  于 2022-12-19  发布在  Flutter
关注(0)|答案(1)|浏览(137)

如何在Image.network上显示图标?我使用了Stack小工具,它没有帮助,图标在图像下面,不可见。我希望我的IconButton显示在右上角的图像上,但Stack小工具对我不起作用。

SliverGrid(
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(),
            delegate: SliverChildBuilderDelegate(childCount: product.length,
                (BuildContext context, int index) {
              final media =
                  product[index].media?.map((e) => e.toJson()).toList();
              final photo = media?[0]['links']['local']['thumbnails']['350'];
              final productItem = product[index];
              return GestureDetector(
                onTap: () {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => ProductScreen(
                                name: productItem.name,
                                link: productItem.link,
                              )));
                },
                child: Container(
                  padding: REdgeInsets.only(left: 2, right: 2, top: 5),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8)),
                  child: Column(
                    children: <Widget>[
                      InkWell(
                        child: Container(
                          margin: REdgeInsets.only(top: 5),
                          child: Stack(
                            children: [
                              IconButton(onPressed: () {}, icon: Icon(Icons.favorite),),
                              Image.network(),
                            ]
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 10.h,
                      ),
                      Text(),
                      SizedBox(height: 8.h),
                      Text(),
                      SizedBox(height: 5.h),
                      buildButton(index, productItem.id),
                    ],
                  ),
                ),
              );
            }),
          ),
yzuktlbb

yzuktlbb1#

请尝试以下代码:

Stack(
  children: [
    Image.network(),
    Align(
      alignment: Alignment.topRight,
      child: IconButton(
        onPressed: () {},
        icon: Icon(Icons.favorite),
      ),
    ),
  ],
),

相关问题