Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The argument type 'Object' can't be assigned to the parameter type 'ImageProvider<Object>'

I just updated to Dart2 and Flutter sdk: '>=2.12.0 <3.0.0' and now this if statement breaks:

 decoration: new BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.blueAccent,
              border: Border.all(
                  color: Colors.blueAccent,
                  width: 20.0,
                  style: BorderStyle.solid),
              image: new DecorationImage(
                fit: BoxFit.cover,
                image: myMarkerThumb != 'noImage'
                    ? NetworkImage(myMarkerThumb)
                    : AssetImage('assets/images/noImageAvailable.png'),
              ),
            ),

The argument type 'Object' can't be assigned to the parameter type 'ImageProvider'. ),

enter image description here

I'm just starting with flutter and have no idea where to look else.

like image 582
JoergP Avatar asked Mar 10 '21 08:03

JoergP


People also ask

Is it possible to assign argument type'object'to imageprovider?

The argument type 'Object' can't be assigned to the parameter type 'ImageProvider'. ), I'm just starting with flutter and have no idea where to look else. Show activity on this post. Hey this is currently an issue I opened in the flutter repo with dart 2.12.

Is it possible to assign jsobject as a parameter type?

The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'. · Issue #66800 · flutter/flutter · GitHub Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

What happens if you use a parameter type other than dynamic?

This meant it was valid to assign, for example, a function with a parameter of type String to a place that expected a function type with a parameter of dynamic. However, in Dart 2 using a parameter type other than dynamic (or another top type, such as Object?) results in a compile-time error.


1 Answers

Hey this is currently an issue I opened in the flutter repo with dart 2.12.

A simple workaround you could make in the meantime is just to cast the object.


 decoration:  BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.blueAccent,
              border: Border.all(
                  color: Colors.blueAccent,
                  width: 20.0,
                  style: BorderStyle.solid),
              image:  DecorationImage(
                fit: BoxFit.cover,
                image: myMarkerThumb != 'noImage'
                    ? NetworkImage(myMarkerThumb)
                    : AssetImage('assets/images/noImageAvailable.png') as ImageProvider,
              ),
            ),

like image 57
croxx5f Avatar answered Sep 19 '22 19:09

croxx5f