Search code examples
gitflutterpackagepubspec

How to reference packages from repository in Flutter?


I'm trying to modify an existing package on pub.dev. I need to update one of the dependencies in the package. I've seen how to do this from here

dependencies:
  flutter:
    sdk: flutter
  graphql_flutter:
    git:
      url: https://github.com/username/graphql-flutter.git

When I run flutter pub get
I get pub get failed (1; Could not find a file named "pubspec.yaml"

Looking at the repository

There is no pubspec.yaml in the root

I presume I need to reference the pubspec.yaml in the packages folder? There is 2 of them there... Not sure how to do this?

The package is graphql_flutter


Solution

  • That's because that's a repo with multiple packages. You need to reference the path and branch directly, just like so, for example for the master branch:

    graphql_flutter:
        git:
          url: https://github.com/zino-app/graphql-flutter.git
          ref: master
          path: packages/graphql_flutter
    

    If you want both packages:

    graphql_flutter:
        git:
          url: https://github.com/zino-app/graphql-flutter.git
          ref: master
          path: packages/graphql_flutter
    
    graphql:
        git:
          url: https://github.com/zino-app/graphql-flutter.git
          ref: master
          path: packages/graphql