missingpluginexception(no implementation found for method distanceBetween on Channel flutter/baseflow.com/geolocator.methods

Asked

Viewed 316 times

-1

When trying to calculate a freight using the distance from the registered ZIP code to the user, I come across this error:

missingpluginexception(no implementation found for method distanceBetween on Channel flutter/baseflow.com/geolocator.methods

    Future<void> setAddress(Address address) async {
    loading = true;

    this.address = address;

    if (await calculateDelivery(address.lat, address.long)) {
      user.setAddress(address);
      loading = false;
    } else {
      loading = false;
      return Future.error('Endereço fora do raio de entrega :(');
    }
  }

  void removeAddress() {
    address = null;
    deliveryPrice = null;
    notifyListeners();
  }

  Future<bool> calculateDelivery(double lat, double long) async {
    final DocumentSnapshot doc = await firestore.document('aux/delivery').get();

    final latStore = doc.data['lat'] as double;
    final longStore = doc.data['long'] as double;

    final base = doc.data['base'] as num;
    final km = doc.data['km'] as num;
    final maxkm = doc.data['maxkm'] as num;

    double dis =
        await Geolocator().distanceBetween(latStore, longStore, lat, long);

    dis /= 1000.0;

    debugPrint('Distance $dis');

    if (dis > maxkm) {
      return false;
    }

    deliveryPrice = base + dis * km;
    return true;
  }
}

That’s the button that calls the code up

   if (cartManager.loading)
        LinearProgressIndicator(
          valueColor: AlwaysStoppedAnimation(Colors.white),
          backgroundColor: Colors.transparent,
        ),
      RaisedButton(
        color: Colors.blue,
        disabledColor: Colors.red.withAlpha(100),
        textColor: Colors.white,
        onPressed: !cartManager.loading
            ? () async {
                if (Form.of(context).validate()) {
                  Form.of(context).save();
                  try {
                    await context.read<CartManager>().setAddress(address);
                  } catch (e) {
                    Scaffold.of(context).showSnackBar(SnackBar(
                      content: Text('$e'),
                      backgroundColor: Colors.red,
                    ));
                  }
                }
              }
            : null,
        child: const Text('Calcular Frete'),
      ),
    ],
  );
else if (address.zipCode != null)
  return Padding(
    padding: const EdgeInsets.only(bottom: 16),
    child:
        Text('${address.street}, ${address.number}\n${address.district}\n'
            '${address.city} - ${address.state}'),`

My Pubspec.yaml

  name: Flutter2
    description: A new Flutter project.
    
    # The following line prevents the package from being accidentally published to
    # pub.dev using `pub publish`. This is preferred for private packages.
    publish_to: 'none' # Remove this line if you wish to publish to pub.dev
    
    # The following defines the version and build number for your application.
    # A version number is three numbers separated by dots, like 1.2.43
    # followed by an optional build number separated by a +.
    # Both the version and the builder number may be overridden in flutter
    # build by specifying --build-name and --build-number, respectively.
    # In Android, build-name is used as versionName while build-number used as versionCode.
    # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
    # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
    # Read more about iOS versioning at
    # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
    version: 1.0.0+1
    
    environment:
      sdk: ">=2.7.0 <3.0.0"
    
    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.3
      cloud_firestore: ^0.13.6
      firebase_auth: ^0.16.1
      firebase_storage: ^3.1.6
      provider: ^4.1.3
      carousel_pro: ^1.0.0
      flutter_staggered_grid_view: ^0.3.0
      transparent_image: ^1.0.0
      alphabet_list_scroll_view: ^1.0.6
      faker: ^1.2.1
      image_picker: ^0.6.7+1
      image_cropper: ^1.2.2
      uuid: ^2.0.4
      dio: ^3.0.9
      brasil_fields: ^0.2.0
      geolocator: ^5.3.2+2
      sliding_up_panel: ^1.0.2
      screenshot: ^0.1.1
      gallery_saver: ^2.0.1
      flutter_signin_button: ^1.0.0
      flutter_facebook_login: ^3.0.0
      url_launcher: ^5.4.11
      map_launcher: ^0.5.0
      flip_card: ^0.4.4
      mask_text_input_formatter: ^1.0.7
      credit_card_type_detector: ^1.1.0
      keyboard_actions: ^3.2.1+1
      cloud_functions: ^0.5.0
      cpf_cnpj_validator: ^1.0.5
      firebase_messaging: ^6.0.16
      flushbar: ^1.10.4
    
    
    
    
    
    
    
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    
    
        
    
    # For information on the generic Dart part of this file, see the
    # following page: https://dart.dev/tools/pub/pubspec
    
    # The following section is specific to Flutter.
    flutter:
      assets:
        - assets/
    
      # The following line ensures that the Material Icons font is
      # included with your application, so that you can use the icons in
      # the material Icons class.
      uses-material-design: true
    
      # To add assets to your application, add an assets section, like this:
      # assets:
      #   - images/a_dot_burr.jpeg
      #   - images/a_dot_ham.jpeg
    
      # An image asset can refer to one or more resolution-specific "variants", see
      # https://flutter.dev/assets-and-images/#resolution-aware.
    
      # For details regarding adding assets from package dependencies, see
      # https://flutter.dev/assets-and-images/#from-packages
    
      # To add custom fonts to your application, add a fonts section here,
      # in this "flutter" section. Each entry in this list should have a
      # "family" key with the font family name, and a "fonts" key with a
      # list giving the asset and other descriptors for the font. For
      # example:
      # fonts:
      #   - family: Schyler
      #     fonts:
      #       - asset: fonts/Schyler-Regular.ttf
      #       - asset: fonts/Schyler-Italic.ttf
      #         style: italic
      #   - family: Trajan Pro
      #     fonts:
      #       - asset: fonts/TrajanPro.ttf
      #       - asset: fonts/TrajanPro_Bold.ttf
      #         weight: 700
      #
      # For details regarding fonts from package dependencies,
      # see https://flutter.dev/custom-fonts/#from-packages

1 answer

1

This error message indicates that the method requested by you was not found. Like that method exists and is correctly used, you should check some points:

  • You need to run the package fetch command flutter pub get (Most Ide’s already contain a shortcut button for this).
  • You need close the app and rotate again (Press "play" on your IDE or rotate the flutter run again). If you’re using Hot Restart or Hot Reload, it won’t work because Flutter needs to inject these dependencies into specific parts of each platform. Hot Restart and Hot Reload are not enough to fire this type of injection.
  • Finally, rotate a flutter clean before the above step helps, but I believe it is not necessary.

For more information see this Issue (in English about a related problem that contains this information).

  • +1. Simply inform that the Issue is not related to the question problem, but that is something related and can help. Just not to confuse the crowd.

  • I restarted the App, quit running, gave the flutter clean, flutter pack get, flutter pub get, then opened the emulator and gave flutter run again, problem persists, keeps showing the same error, also reinitiated the PC and did the whole process again to ensure, but the error persists

  • 1

    @Matheus Edited response. @Giovanni, also, could you please enter the value of compileSdkVersion __, inside the archive android/app/build.gradle? This value needs to be at least 28. It is one of the initial steps described on the package page used.

  • this and android version { compileSdkVersion 28

Browser other questions tagged

You are not signed in. Login or sign up in order to post.