Flutter "argument type not assignable" Error with two identical types - flutter

Flutter shows me this error, but the two types are identical.
[CartItem it's just a simple model; there was a conflict since another widget had the same name but I resolved it using "as" in the import statement]
The argument type List<CartItems> (where CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart)' can't be assigned to the parameter type List<CartItems> (where CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart)'.dartargument_type_not_assignable
list.dart(56, 16): List is defined in /Users/marco/flutter/bin/cache/pkg/sky_engine/lib/core/list.dart
cart.dart(3, 7): CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart
list.dart(56, 16): List is defined in /Users/marco/flutter/bin/cache/pkg/sky_engine/lib/core/list.dart
cart.dart(3, 7): CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart
Peek Problem (⌥F8)
No quick fixes available

It was a double slash in the import statement that generated this strange error.

you should use the library prefix in the usage too so if your namespace is
import 'package:app/xxxx/shop_app/lib/providers/cart.dart as shop_cart;
you should specify it in the generic List as well such as;
List shopCarts = etc...;

Check your import statement at the top of file even if you mistyped a directory folder name as 'Caps or Small' you can get this error.

Related

Target of URI doesn't exist: 'package:flutter/material.dart'

I've just set up my Windows 11 for Flutter development,
So I updated flutter SDK, and placed it in my Documents. After, I got this:
Target of URI doesn't exist: 'package:flutter/material.dart'.
The function 'runApp' isn't defined.
Classes can only extend other classes.
The name 'WidgetBuilder' isn't a type so it can't be used as a type argument.
Undefined class 'Widget'.
Undefined class 'BuildContext'.
The method 'MaterialApp' isn't defined for the type 'MyApp'.
The method 'ThemeData' isn't defined for the type 'MyApp'.
Undefined name 'Colors'.
The method doesn't override an inherited method.
What is an error? It's difficult to me.
Try running the following command in terminal:
flutter pub get

What's the difference between List<Type/*1*/>> and List<Type/*2*/>>

Hi I was making a Todo App in flutter but got stuck thanks to an error in in my code:
`Error: The argument type 'List<Todo/1/>' can't be assigned to the parameter type 'List<Todo/2/>'.
'List' is from 'dart:core'.
'Todo/1/' is from 'package:Database/main.dart' ('lib/main.dart').
'Todo/2/' is from 'package:Database/model/Todo.dart' ('lib/model/Todo.dart').
? new TodoList(todo: todoList)`
All types are of List but it's telling me that values can't be assigned. I've tried casting but doesn't seem to fix the issue.
So my question is What's the difference between the List types. if I know I can find a fix myself(I'm trying to rely on my nkowledge of things to fix errors. it's a challenge for myself).
It seems like you have two different classes with the same name.
Even with the same class name, those classes are different. You can map your first List to the type List by using the map function:
list.map( (todo1) => Todo2() ).toList()
you can import Todo class like import 'package:Database/model/Todo.dart' as model and have your list like this: List<model.Todo>.

package:analyzer When the parameter type is Function type , type.element is getting 'null'

I am using package:analyzer to do custom static analysis.
when I have dart code like below :
class MyType{
final void Function(MyItemType) callback ;
}
When I try to access the element of the callback type : I am getting null
That is :
parameterElement.type.element evaluates to be null .
Therefore I cannot get the source file of the Types involved in the Function to import those source files.
This issue happens only when I use a Function type that is anything other than just Function().
parameterElement is of Type ParameterElement from analyser package.
My requirement is that I want to import all the files that contain the Types involved in the Function. In my example code shown above , I wish to import the file that contains the MyItemType class.
Also if the return type of the function was some other Type other than void , I want to import the corresponding source file.

Reference a java nested class in Spark Scala

I'm trying to read some data from hadoop into an RDD in Spark using the interactive Scala shell but I'm having trouble accessing some of the classes I need to deserialise the data.
I start by importing the necessary class
import com.example.ClassA
Which works fine. ClassA is located in a jar in the 'jars' path and has ClassB as a public static nested class
I'm then trying to use ClassB like so:
val rawData = sc.newAPIHadoopFile(dataPath, classOf[com.exmple.mapreduce.input.Format[com.example.ClassA$ClassB]], classOf[org.apache.hadoop.io.LongWritable], classOf[com.example.ClassA$ClassB])
This is slightly complicated by one of the other classes taking ClassB as a type, but I think that should be fine.
When I execute this line, I get the following error:
<console>:17: error: type ClassA$ClassB is not a member of package com.example
I have also tried using the import statement
import com.example.ClassA$ClassB
and it also seems fine with that.
Any advice as to how I could proceed to debug this would be appreciated
Thanks for reading.
update:
Changing the '$' to a '.' to reference the nested class seems to get past this problem, although I then got the following syntax error:
'<console>:17: error: inferred type arguments [org.apache.hadoop.io.LongWritable,com.example.ClassA.ClassB,com.example.mapredu‌​ce.input.Format[com.example.ClassA.ClassB]] do not conform to method newAPIHadoopFile's type parameter bounds [K,V,F <: org.apache.hadoop.mapreduce.InputFormat[K,V]]
Notice the types that the newAPIHadoopFile expects:
K,V,F <: org.apache.hadoop.mapreduce.InputFormat[K,V]
the important part here is that the generic type InputFormat expects the types K and V, i.e. the exact types of the first two parameters to the method.
In your case, the third parameter should be of type
F <: org.apache.hadoop.mapreduce.InputFormat[LongWritable, ClassA.ClassB]
does your class extend FileInputFormat<LongWritable, V>?

Scala - mixing of packages and variables?

A very strange thing indeed. I have the following project structure:
myproject/one/two
Inside package myproject I have a class:
abstract class A (two: Buffer[Int])
and then, inside package one I have:
object B extends A (Buffer[Int](1, 2, 3)) {
val с = two.map(_ + 1) // ERROR
}
However, the erros says:
object map is not a member of package
myproject/one/two
which is obviously erroneous because it should be perfectly clear that I don't refer to the packages here, but to the local variable... And two also is not shown in context-assist after this. in B, but is shown in A (Scala-IDE). Is this an intended behavior and I am doing something wrong or is it a bug?
UPDATE:
(simultaneously suggested by Nicolas :D ) Been able to resolve the name collision by specifying two as val (making it public). I did not notice at first, but it was private and unavailable in the successor class. Nevertheless I am still wondering, why and how did Scala pick up a package instead of saying that the variable does not exist or is not accessible?
It's not as clear as you might think. Without a modifier, two is private to abstract class A class A. Thus your declaration of a is equivalent to abstract class A (private[this] A). It means that field two can't be seen from object B. A direct consequence is that the compiler look into the only defiition of two visible from B: the package two.