flutterdart

Cannot find type 'PhoneNumberKit' and Extra argument 'phoneNumberKit' in call Error in Flutter iOS App


I'm encountering two issues in my Flutter app when building for iOS:

Cannot find type 'PhoneNumberKit' in scope: I'm getting this error when trying to use the PhoneNumberKit library in my Flutter iOS project. It seems like the compiler is unable to find the PhoneNumberKit type.

Extra argument 'phoneNumberKit' in call: This error occurs when I try to instantiate or pass PhoneNumberKit in a function call. The function signature doesn't seem to accept this argument, although I'm following the documentation.[enter image description here](https://i.sstatic.net/rEUwY9Bk.png)

I tried the following steps to resolve the issue:

Changing the CocoaPods version: I downgraded CocoaPods to an older version, but it didn't resolve the issue. Manually changing the package version: I downgraded the PhoneNumberKit package to a lower version manually, and surprisingly, the app worked. However, I don't consider this a logical or sustainable solution, as it might lead to compatibility issues in the future. I was expecting the app to build and run successfully using the latest versions of both CocoaPods and PhoneNumberKit without encountering these errors.


Solution

  • Remove Podfile.lock

    in Podfile

    target 'Runner' do
      use_frameworks!
      use_modular_headers!
    
        # Add This Line
        pod 'PhoneNumberKit', '~> 3.7.6'
    
        flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    end
    

    run:

       pod install --repo-update
       flutter clean
       flutter build iOS