Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

type 'int' is not a subtype of type 'List<int>' in type cast

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}]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
  }

>Solution :

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']]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading