'FLUTTER: When converting List<int> to List<String> error thrown: Unhandled Exception: type 'String' is not a subtype of type 'int' in type cast
This is bizarre, I'm trying to do a simple conversion of List to List sp I can save it to SharedPreferences (prefs) and it throws an exception.
Unhandled Exception: type 'String' is not a subtype of type 'int' in type cast
I've tried various other less familiar formalisations of the conversion as found on Stackoverflow here, but the exception persists
else if (value is List<int>) {
prefs.setStringList(
"itemsToLoanCats", [...value.map((int e) => e.toString())]);
}
I'm now wondering if the error isn't what it seems and something less obvious is going on.
Love some help.
Solution 1:[1]
As far as I understood, you should remove int (int e)=> to be (e)=>
else if (value is List<int>) {
prefs.setStringList(
"itemsToLoanCats", [...value.map((e) =>e.toString())]);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
