fluttergitimportnfcrepo

Why can I not import nfc_manager repo as a dependency into my flutter app?


I am using flutter with nfcmanager as part of a project. I want to use the classes from the real world example of an nfcmanager app that I have tested on my machine and works very well inside my code, so I added a fork of the repo as a dependency.

I added it into pubspec.yaml:

nfc_manager_mine:
    git: 
      url: https://github.com/[My Github Username]/nfc-manager-mine.git
      ref: master

But then I got an error where suddenly flutter was unhappy that the name of the app in the repo I was referencing was 'app' and not 'nfc_manager_mine':

Error on line 1, column 7: "name" field doesn't match expected name

I then edited the name of the app, changed the import paths, and everything seemed to be fine. However inside the code it still thinks that it is called 'app'. When I run the package app itself there is no issue. However when I run the main app, I am met with this error:

Error: Couldn't resolve the package 'app' in 'package:app/utility/extensions.dart'.

Can someone please help me fix this, I think maybe a good starting place is the first error message but if you get nowhere then please at least help with the second one.

I then tried to get smart and removed the import statements for the package app inside the main app, ran the main app, then added the import statements back in and hot reloaded, and I was met with a huge error which I have cut down:

Error: Couldn't resolve the package 'app' in 'package:app/utility/extensions.dart'.
Error: Couldn't resolve the package 'app' in 'package:app/view/common/form_row.dart'.
Error: Couldn't resolve the package 'app' in 'package:app/view/common/nfc_session.dart'.
Error: Couldn't resolve the package 'app' in 'package:app/view/ndef_record.dart'.
../../../../.pub-cache/git/nfc-manager-mine-aa4c12d2172d55b346be2c1d4697fce508fe515b/lib/view/tag_read.dart:4:8: Error: Not found:
'package:app/utility/extensions.dart'
import 'package:app/utility/extensions.dart';
       ^
../../../../.pub-cache/git/nfc-manager-mine-aa4c12d2172d55b346be2c1d4697fce508fe515b/lib/view/tag_read.dart:5:8: Error: Not found:
'package:app/view/common/form_row.dart'
import 'package:app/view/common/form_row.dart';
       ^
../../../../.pub-cache/git/nfc-manager-mine-aa4c12d2172d55b346be2c1d4697fce508fe515b/lib/view/tag_read.dart:6:8: Error: Not found:
'package:app/view/common/nfc_session.dart'
import 'package:app/view/common/nfc_session.dart';
       ^
../../../../.pub-cache/git/nfc-manager-mine-aa4c12d2172d55b346be2c1d4697fce508fe515b/lib/view/tag_read.dart:7:8: Error: Not found:
'package:app/view/ndef_record.dart'
import 'package:app/view/ndef_record.dart';

You get the picture. It seems like the old package name is still cached somewhere but I can't find it.


Solution

  • To remove the cached packages just delete pubspec.lock file and run flutter pub get