Home > OS >  Flutter - Error: The argument type 'Image' can't be assigned to the parameter type --
Flutter - Error: The argument type 'Image' can't be assigned to the parameter type --

Time:08-30

I'm just starting to learn Flutter and when trying to add an image with a network image as the source, I encountered this error. I tried to search solution for this but still can't find it. So anyone could enlighten me on what the problem could be ?. Thank you.

Here is the source code

 Error: The argument type 'Image' can't be assigned to the parameter type 'ImageProvider<Object>'.
  • 'Image' is from 'package:flutter/src/widgets/image.dart' ('/C:/src/Flutter/flutter/packages/flutter/lib/src/widgets/image.dart').
  • 'ImageProvider' is from 'package:flutter/src/painting/image_provider.dart' ('/C:/src/Flutter/flutter/packages/flutter/lib/src/painting/image_provider.dart').
  • 'Object' is from 'dart:core'. image: Image.network(

CodePudding user response:

There are two way to show network image in flutter.

First use NetworkImage

Image(
  image: NetworkImage('https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/chihuahua-dog-running-across-grass-royalty-free-image-1580743445.jpg?crop=0.446xw:1.00xh;0.254xw,0&resize=480:*'),
)

or use:

Image.network('https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/chihuahua-dog-running-across-grass-royalty-free-image-1580743445.jpg?crop=0.446xw:1.00xh;0.254xw,0&resize=480:*')

CodePudding user response:

While NetworkImage is a image provider, Image or Image.network are Widgets so you need to use Image.network() or Image class

CodePudding user response:

this error mainly cause just because you are providing Image rather then ImageProvider.

solution:

              Container(
                decoration: const BoxDecoration(
                    image: DecorationImage(
                        image: NetworkImage(
                            "https://picsum.photos/250?image=9"),
                        ),
                    ),
              )
  • Related