Stack Overflow em Português Asked on December 11, 2021
Ao tentar calcular um frete usando a distancia do CEP cadastrado ao do usuário, me deparo com esse erro:
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;
}
}
Esse é o botão que chama o codigo a cima
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}'),`
Meu 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
Essa mensagem de erro indica que não foi achado o método requisitado por você. Como esse método existe e está corretamente utilizado, você deve verificar alguns pontos:
flutter pub get
(A maioria das IDE's já contém um botão de atalho para isso).flutter run
novamente). Se você está usando Hot Restart ou Hot Reload, isso não irá funcionar pois o Flutter precisa injetar essas dependências em partes específicas de cada plataforma. Hot Restart e Hot Reload não são o suficiente para disparar esse tipo de injeção.flutter clean
antes do passo acima ajuda, mas acredito não ser necessário.Para maiores informações consulte esta issue (em inglês sobre um problema relacionado que contém essas informações).
Answered by Naslausky on December 11, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP