jimsimon / pub_client

A library for interacting with the REST API for Pub (pub.dartlang.org).
Apache License 2.0
9 stars 10 forks source link

Error on most getPackage(string) calls #2

Closed holyspidoo closed 6 years ago

holyspidoo commented 6 years ago

When I call var onlinePackage = await client.getPackage(packagename);

I get on most packages: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' in type cast

Example package that does it: dragable_flutter_list

Example package that works fine: cupertino_icons

jimsimon commented 6 years ago

What version of the package are you using? Since Flutter uses Dart 2.0, you'll need to use version 2.0.0 of pub_client if you're not already doing so.

holyspidoo commented 6 years ago

I'm using Dart VM version: 2.0.0 and pub_client: ^2.0.0

jimsimon commented 6 years ago

I'm at work at the moment, but I can dig into it when I get home tonight. You're also welcome to submit a PR if you want. I suspect it's primarily a type inference issue.

jimsimon commented 6 years ago

I've figured out the problem and it has to do with the format of the dependencies and dev_dependencies data.

This library currently only supports dependency and dev_dependency JSON properties that don't have any nesting. For example:

{
  ...
  "dependencies": {
    "http": "^0.11.3+17",
    "json_annotation": "^1.0.0"
  },
  ...
}

However, dependencies can also be specified like so:

{
  ...
  "dependencies": {
    "flutter": {
      "sdk": "flutter"
    }
  },
  ...
}

This library doesn't currently support this 2nd format (and several others). I'm trying out a few ideas for how to resolve this, so hang tight.

holyspidoo commented 6 years ago

Great news! Thanks for looking into this, pub_client is really useful!

jimsimon commented 6 years ago

I just published version 3.0.0 which has some backwards incompatible changes around how dependencies are handled. Instead of having the dependenices and devDependencies properties be simple Maps, they're now objects with multiple maps under them: simpleDependencies, complexDependencies, sdkDependencies, and gitDependencies. Unfortunately this was the only way I could handle the various dependency structures while still maintaining strong typing.

Take a look at this test for an example of the new structure.

I hope this helps!

holyspidoo commented 6 years ago

Great! It works!! A million thanks!