About use of http package in Chapter 12 Futures

In Chapter 12 Futures, is http a third party package developed by someone else. Therefore we need to add the line http: ^0.13.5 in the dependencies section in the pubspec.yaml file?

This syntax will specify Dart to load http package version 0.13.5 explicitly, am I correct? Is there any syntax that will tell Dart to load the whatever latest version of http possible?

1 Like

Because a ^ caret precedes the version number in ^0.13.5, the meaning is to use any version from 0.13.5 up to (but not including) 0.14.0. See this link for more info.

If you want to use the latest available version, leave the version blank or use the any key word. Like this:

dependencies
  http: 

Or this:

dependencies
  http: any

For example projects this is fine, but for production it can be dangerous. Say the developer makes a breaking change right before you are ready to publish your app. Then your app is broken and you have to fix it before publishing. Or worse yet, you don’t notice the breaking change and your broken app ships to the users.

Or take this book as an example. If I wrote any and then the next major version of http worked in a completely different way, all of my examples would be broken and readers would be frustrated. By specifying a non-breaking version range, I can be sure that the examples will work the same for a long time to come.

See also:

1 Like

Hi @suragch thank you. I somewhat remember book 1 has talked about this but don’t remember very clearly.

1 Like