how to solve this issue: type 'int' is not a subtype of type 'List<int>' in type cast
? Now I am trying to do somethin like that:
ElevatedButton(
onPressed: () {
BasesService().SelectBaseAsync(
basesNames?[index]['id]);
},
Also I was trying to cast to needed type like this - basesNames?[index]['id'] as List<int>
, but it also returned me the same error: type 'int' is not a subtype of type 'List<int>' in type cast
the print of basesNames - [{name: MyDb, id: 4}]
Future<bool> SelectBaseAsync(List<int> integers) async {
final hubConnection = HubConnectionBuilder()
.withUrl(
'http:mysecurelink'
)
.build();
await hubConnection.start();
bool select = false;
List<int>? saveInts;
if (hubConnection.state == HubConnectionState.Connected) {
await hubConnection
.invoke('SelectBaseAsync', args: [integers]).then((value) {
saveInts = integers;
select = value as bool;
});
}
hubConnection.onclose(({error}) {
throw Exception(error);
});
print(saveInts);
print(select);
return select;
}
CodePudding user response:
As you can see in print(basesNames)
result, basesNames[index]['id'] return an int
value not list of int
, so what you can do are either change your SelectBaseAsync
constructer to accept an int instead of List<int>
or pass value like this:
BasesService().SelectBaseAsync([basesNames?[index]['id']]);