7
votes

I'm using VS Code on a flutter project. I just edited pubspec.yaml to point to a later version of a package, and it automatically ran 'flutter packages get'. In my '/development//flutter/.pub-cache/hosted/pub.dartlang.org' directory, I can see both versions. But when I compile, it looks like it's still using the old version. I tried various things like 'flutter packages upgrade', 'flutter clean', etc., but to no avail. Looking at the 2 package versions' source code, I can see the change I want in the newer version. How do I point to the new package? Thanks.

Update:

It's the 'ethereum' package that's not updating. I had used the 3.0.0 version (method expects 2 args), and then switched to the 3.1.0 version (method expects 3 args). But compiling with a 3 arg call balks with incorrect argument count:

client.admin.personalSendTransaction(BigInt.parse(currentAddress), currentPassword,{});

[dart] Too many positional arguments: 2 expected, but 3 found. [extra_positional_arguments_could_be_named]

Yet hovering over the method call does show it expects 3 args:

personalSendTransaction(BigInt address, String passphrase, {BigInt to, BigInt data, int gas, int gasPrice, int value, int nonce, int condition, bool conditionIsTimestamp: false}) → Future<BigInt>

pubspec.yaml:

    dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

  # Get package(s) for talking to ethereum node
  # web3dart: '>=0.3.0'
  ethereum: ^3.1.0

  # read barcodes and QR codes
  barcode_scan: ^0.0.3

  # Generate a QR code
  qr: ^1.0.1

  # Display as actual symbol
  qr_flutter: ^1.1.5

dev_dependencies:
  flutter_test:
    sdk: flutter

In pubspec.lock:

  ethereum:
    dependency: "direct main"
    description:
      name: ethereum
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.0"

Version 3.1.0 is what I want to be used.

Running 'flutter packages upgrade resolved' yields:

[Gregorys-iMac]:(gkd) ~/Programs/wine_track $ flutter packages upgrade resolved
Running "flutter packages upgrade" in ....                   2.7s

In the package cache, I have both:

/Users/gkd/development//flutter/.pub-cache/hosted/pub.dartlang.org/ethereum-3.0.0/lib/src/api/ethereum_api_admin.dart

/Users/gkd/development//flutter/.pub-cache/hosted/pub.dartlang.org/ethereum-3.1.0/lib/src/api/ethereum_api_admin.dart
5
Could you add your pubspec file in your question? what package is not updating?diegoveloper
Check the pubspec.lock file what version flutter packages upgrade resolved. What exactly does the dependency looks like that you added to pubspec.yaml`?Günter Zöchbauer

5 Answers

11
votes

you can simply run flutter packages upgrade in your project to upgrade all the packages. this feature is available from flutter version 1.17

1
votes

i have created a python3 script for this, you can use. this script only produce latest packages names and versions, you must to copy and paste into pubspec.yaml file.

import yaml
import requests
from lxml import etree
from io import StringIO


def getNewVersion(pkg_name):
    url = f'https://pub.dev/packages/{pkg_name}'
    with requests.get(url) as req:
        doc = etree.parse(StringIO(req.text), etree.HTMLParser()).getroot()
        title = doc.xpath('//h2[@class="title"]')[0].text.strip()
        return '^' + (title.split(' ')[1])


if __name__ == "__main__":
    filename = 'pubspec.yaml'
    new_map = None
    with open(filename, 'r') as _f:
        docs = yaml.load(_f, Loader=yaml.FullLoader)
        deps = docs['dependencies']
        for package_name, old_version in deps.items():
            if package_name == 'flutter':
                continue
            last_version = getNewVersion(package_name)
            print(f'{package_name}: {last_version}')
0
votes

OK, never mind. This was my mistake. I interpreted the declaration's "{ type:variablename, . . .}" as a map/hash. In reality, they're Dart's optional named parameters. Just using any of them without the wrapping braces compiles clean.

0
votes

Go to https://pub.dartlang.org/packages and find the latest package from there. In there you can see an install tab. click that. Now you can add the dependencies into your pubspec.ymal file in your flutter project. Then you can just press ctrl+s in VS Code or type flutter packages get in your terminal. Now you can import into any page.

0
votes

flutter pub upgrade --major-versions