flutter 模拟器上未显示扑动图像-例外:无效图像数据

2guxujil  于 2023-01-31  发布在  Flutter
关注(0)|答案(1)|浏览(128)

你好,我正尝试在我的应用程序上制作一个旋转木马,但图像没有显示。代码和错误如下,如果有人能帮助我解决这个问题,我将不胜感激。
我的终端上的错误:
图像资源服务捕获的异常解决图像编解码器时引发了以下_Exception:异常:无效图像数据
代码:

class CarouselBuild extends StatefulWidget {
  CarouselBuild({Key? key}) : super(key: key);

  @override
  State<CarouselBuild> createState() => _CarouselBuildState();
}

class _CarouselBuildState extends State<CarouselBuild> {
  final urlImages = [
    'https://unsplash.com/photos/VURwPtZqyF4',
    'https://unsplash.com/photos/oCZHIa1D4EU',
    'https://unsplash.com/photos/5-GNa303REg',
  ];
  @override
  Widget build(BuildContext context) {
    return CarouselSlider.builder(
      options: CarouselOptions(
        enlargeCenterPage: true,
        autoPlay: true,
        aspectRatio: 2.0,
      ),
      itemCount: urlImages.length,
      itemBuilder: (context, index, realIndex) {
        final urlImage = urlImages[index];
        return buildImage(urlImage, index);
      },
    );
  }

  Widget buildImage(String urlImage, int index) => Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height * 0.3,
        margin: EdgeInsets.symmetric(horizontal: 0),
        color: Colors.grey,
        child: Image.network(
          urlImage,
          fit: BoxFit.cover,
        ),
      );
}
f0brbegy

f0brbegy1#

问题不在于代码,而在于图像路径。
您已将图像路径定义为:

final urlImages = [
   'https://unsplash.com/photos/VURwPtZqyF4',
   'https://unsplash.com/photos/oCZHIa1D4EU',
   'https://unsplash.com/photos/5-GNa303REg',
];

然而,这些并不是实际的图片,而只是Unsplash页面。您提供的照片的现有路径将是:

final urlImages = [
   'https://images.unsplash.com/photo-1578632767115-351597cf2477',
   'https://images.unsplash.com/photo-1528360983277-13d401cdc186',
   'https://images.unsplash.com/photo-1534214526114-0ea4d47b04f2',
];

相关问题