acoutts / flutter_libphonenumber

Leverages libphonenumber to allow for asynchronous and synchronous formatting of phone numbers in Flutter apps. Includes a TextInputFormatter to allow real-time AsYouType formatting.
MIT License
60 stars 73 forks source link

MissingPluginException in tests #35

Closed garrettlove8 closed 1 year ago

garrettlove8 commented 1 year ago

Error: MissingPluginException(No implementation found for method parse on channel flutter_libphonenumber)

Running into this issue which I see people have reported in the past, however I'm experiencing it while running tests and the app itself works fine.

Using VS Code if that changes anything.

Flutter Doctor Output [✓] Flutter (Channel stable, 3.7.0, on macOS 12.6 21G115 darwin-arm64, locale en-US) • Flutter version 3.7.0 on channel stable at /Users/garrettlove/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision b06b8b2710 (7 days ago), 2023-01-23 16:55:55 -0800 • Engine revision b24591ed32 • Dart version 2.19.0 • DevTools version 2.20.1 [✗] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions). If the Android SDK has been installed to a custom location, please use `flutter config --android-sdk` to update to that location. [✓] Xcode - develop for iOS and macOS (Xcode 14.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14B47b • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions). [✓] VS Code (version 1.74.3) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.58.0 [✓] Connected device (3 available) • iPhone 14 (mobile) • 9CD70026-7E08-4947-A071-601C41106272 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 2 categories.
acoutts commented 1 year ago

Most likely you need to mock the method channel stuff if you’re running it on a desktop or web since those platforms aren’t implemented.

garrettlove8 commented 1 year ago

@acoutts Thanks for the quick response. I will give that a shot later today and report back. Thanks! again

garrettlove8 commented 1 year ago

Not sure if I'm doing this in the best way but here is my solution that seems to be working.

const MethodChannel("flutter_libphonenumber").setMockMethodCallHandler((call) async {
      switch (call.method) {
        case "parse":
          return {
            "country_code": 1,
            "e164": "+18000985675",
            "national": "800 098 5675",
            "type": "mobile",
            "international": "+28000985675",
            "national_number": "18000985675",
          };
        default:
      }
    });