fluttercommunity / flutter_google_places

Google Places - Google places autocomplete widgets for flutter. No wrapper, use https://pub.dev/packages/google_maps_webservice. Maintainer: @juliansteenbakker
https://pub.dev/packages/flutter_google_places
Other
303 stars 415 forks source link

Flutter master branch issue - The method 'ancestorStateOfType' isn't defined for the class 'BuildContext'. #140

Closed Theunodb closed 3 years ago

Theunodb commented 3 years ago

For future release:

If you are in the latest master branch of flutter the ios build fails with this error:

./../../../.pub-cache/hosted/pub.dartlang.org/flutter_google_places-0.2.6/lib/src/flutter_google_places.dart:74:15: Error: The method 'ancestorStateOfType' isn't defined for the class 'BuildContext'.
     - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../../flutter/packages/flutter/lib/src/widgets/framework.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'ancestorStateOfType'.
          context.ancestorStateOfType(const TypeMatcher<PlacesAutocompleteState>());
                  ^^^^^^^^^^^^^^^^^^^
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.26.0-2.0.pre.402, on macOS 11.1 20C69 darwin-x64, locale en-ZA)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.1)
[✓] Connected device (2 available)
josh-burton commented 3 years ago

This change is now in Flutter beta so really needing a fix.

hoc081098 commented 3 years ago

Please, trying use my fork: https://github.com/hoc081098/flutter_google_places

flutter_google_places:
  git:
    url: https://github.com/hoc081098/flutter_google_places.git
    ref: feature/restricted-api-keys
talatkuyuk commented 3 years ago

I am using beta channel. I receive similar error:

./../../.pub-cache/hosted/pub.dartlang.org/flutter_google_places-0.2.6/lib/src/flutter_google_places.dart:74:15: Error: The method 'ancestorStateOfType' isn't defined for the class 'BuildContext'.

in pubspec.yaml: flutter_google_places: ^0.2.6

amadorta commented 3 years ago

I made this change:

static PlacesAutocompleteState of(BuildContext context) =>
      // context.ancestorStateOfType(const TypeMatcher<PlacesAutocompleteState>());
      context.findAncestorStateOfType<PlacesAutocompleteState>();

in c:\src\flutter.pub-cache\hosted\pub.dartlang.org\flutter_google_places-0.2.6\lib\src\flutter_google_places.dart

and it works

DaniEzzeddine commented 3 years ago

I'm still seeing this error, when could I install a fix?

zhelon commented 3 years ago

I upgraded flutter_google_places to ^0.2.8 and rxdart to ^0.25.0 and it worked :D