Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getProducts(), type 'List<dynamic>' is not a subtype of type 'FutureOr<List<Product>>' #163

Closed
marchacio opened this issue Mar 8, 2021 · 8 comments · Fixed by #164
Closed
Labels
bug Something isn't working

Comments

@marchacio
Copy link

Hi everyone.
In my app, i have added the method "Purchases.getProducts(...)" but this throws a TypeError Exception.
VScode shows me that the corrupted file is "purchases_flutter.dart".

Today I upgraded the package to 3.0.0; before today, i used 2.0.2

My code:

Future<List<Product>> caricaDonazioni() async {
    List<Product> prodotti = await Purchases.getProducts([
      'XXXXX',
      'XXXXX',
      'XXXXX',
      'XXXXX',
      'XXXXX',
    ], type: PurchaseType.inapp);

    prodotti.sort((prod1, prod2) => prod1.price.compareTo(prod2.price));

    return prodotti;
  }
@marchacio marchacio added the bug Something isn't working label Mar 8, 2021
@vegaro
Copy link
Contributor

vegaro commented Mar 8, 2021

Can you share the exception? I would like to look at the stacktrace. Thanks!

@vegaro
Copy link
Contributor

vegaro commented Mar 8, 2021

Actually, I just managed to reproduce it. I will look into it

@davidmartos96
Copy link
Contributor

davidmartos96 commented Mar 8, 2021

@vegaro I think the problem is that the typing of invokeMethod has been removed, so that turns into dynamic.

Dynamic doesn't statically check the .map, and fails to infer the output type as List<Product>.

Probably bringing the List<dynamic> back would fix it. Maybe it could help to deactivate the implicit dynamic lint to better spot/avoid these kind lf issues.
dynamic is too magical 😄

Screenshot_20210309-001524783.jpg

@vegaro
Copy link
Contributor

vegaro commented Mar 9, 2021

As you say, bringing back List<dynamic> as the type fixes it, but also adding map<Product> and keeping the final result. What you are saying makes sense. For future reference, what's basically happening is:

  1. Replacing List<dynamic> with final is making the result to be of type dynamic.
  2. The static analyzer doesn't check the type of map because result is dynamic. We can specifically tell that map should be map<Product>, or just make sure that result is not dynamic

I was actually just looking at how to disable the implicit-dynamic lint because these issues look insanely hard to spot unless you have a ton of experience with the language, which I don't.

@vegaro
Copy link
Contributor

vegaro commented Mar 9, 2021

I am preparing a release 3.0.1 that should include the fix. Thanks for reporting and sorry about the trouble

@nohli
Copy link

nohli commented Mar 9, 2021

As you say, bringing back List<dynamic> as the type fixes it, but also adding map<Product> and keeping the final result. What you are saying makes sense. For future reference, what's basically happening is:

  1. Replacing List<dynamic> with final is making the result to be of type dynamic.
  2. The static analyzer doesn't check the type of map because result is dynamic. We can specifically tell that map should be map<Product>, or just make sure that result is not dynamic

I was actually just looking at how to disable the implicit-dynamic lint because these issues look insanely hard to spot unless you have a ton of experience with the language, which I don't.

@vegaro this is how to disable that lint:

analyzer:
  strong-mode:
    implicit-dynamic: false

Would you like a PR?

@vegaro
Copy link
Contributor

vegaro commented Mar 9, 2021

Thanks @nohli ! I actually have a branch and have started fixing a bunch of errors. There are so many though 🤦

@github-actions
Copy link

This issue has been automatically locked due to no recent activity after it was closed. Please open a new issue for related reports.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants