Closed Storch72 closed 3 years ago
Okaay...
@Storch72 I'm also having the same problem for all my map functions in my classes. Did you manage to fix them?
No, never did and no one ever responded tp my question. This feels like nobody looks at this anymore. :-(
Ahh damn. I'm really excited to use this in my projects, but I have no idea how to fix the assignment issue. Maybe someone will respond with some tips.
@Storch72 I think I found a solution.
Just after your map function type cast the variable to whatever it needs to be using as. For example: bestTry: map['bestTry'] as double
Hope this helps! Don't know if this is the correct way of solving the issue though.
Changing the warning level, doesn't remove the warning, it only changes the level which has basically no effect in any tooling.
To ignore certain rules edit your pubpsec.yaml
include: package:lint/analysis_options.yaml
linter:
rules:
invalid_assignment: false
@passsy I've tried this, but it still shows up for all my map functions.
Can it be that my map functions are doing something wrong? For example:
`factory ChessStats.fromMap(Map<String, dynamic> map) { if (map == null) return null;
return ChessStats(
gamesPlayed: map['gamesPlayed'], //This is where I get the error
gamesWon: map['gamesWon'],
gamesDrawn: map['gamesDrawn'],
gamesLost: map['gamesLost'],
);
}`
map['gamesPlayed']
returns dynamic
. which is not bool
. You definitely have to add the cast to be correct.
The reason you see this error is because of implicit-cast: false
. Without lint
implicit-cast
is set to true
.
I really, really recommend disabling implicit-casts as they otherwise cause errors at runtime which could be caught at compile time. But you can enable them again:
include: package:lint/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: true
Thank you for clarifying this. I'd rather cast all my attributes to catch these errors on compile time.
Have a nice day/night.
Hello. I have tried several different ways to get the linter to ignore this error but am unsure what the correct answer is.
"A value of type ‘{0}’ can’t be assigned to a variable of type ‘{1}’" I have tried:
Nothing seems to prevent this from being a compile error in my project except removing [lint: ^1.0.0] completely What am I doing wrong? What do I need to do to use?