Can't build after upgrading to Flutter 2.5.1 - flutter

Once i upgraded to Flutter 2.5.1 my project stops build and run, giving this error:
/Users/admin/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_android-2.0.0/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java:29: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
^
symbol: variable S
location: class VERSION_CODES
/Users/admin/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_android-2.0.0/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java:30: error: cannot find symbol
position.put("is_mocked", location.isMock());
^
symbol: method isMock()
location: variable location of type Location
2 errors
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':geolocator_android:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Any idea?

You must have upgraded Geolocator to version 7.7.0, which means you will also need to update your android/app/build.gradle file and set the compileSdkVersion to 31 (it's mentioned in the CHANGELOG).
If you don't want to upgrade the Android compileSdkVersion you should downgrade the geolocator to version 7.6.2 in your pubspec.yaml.

The error is because the compileSdkVersion needs to be changed to 31 for Geolocator 7.7.0 and higher.
You could either do that in android/app/build.gradle file. But I wouldn't recommend it as it will cause more errors with other packages.
Instead, you could downgrade the Geolocator to 7.6.2 in the pubspec.yaml
Or use these commands to downgrade:
dart pub downgrade geolocator

Maybe your version is not upgraded with your packages
The following command will help you for that:
flutter pub get

I just Upgraded my project and got this issue:
Maybe this will work for you:
Run These commands in your terminal:
dart pub downgrade geolocator_android
dart pub downgrade geolocator
Another way is to set Compile and Target Android version to 31.
But I will not recommend it for now coz this will lead you to many other issues.

Related

Fluttertoast problem: Member not found: 'Overlay.maybeOf'

/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/fluttertoast-8.1.3/lib/fluttertoast.dart:165:28: Error: Member not found: 'Overlay.maybeOf'.
var _overlay = Overlay.maybeOf(context!);
^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/fluttertoast-8.1.3/lib/fluttertoast.dart:154:18: Error: The getter 'mounted' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
framework.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named 'mounted'.
if (context?.mounted != true) {
^^^^^^^
3
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1159
After adding fluttertoast in my project it shows this problem while I run project on my device.
Now, what does it mean?
I was trying to show toast when an error or success occurred. But without snackbar fluttertoast is the only option to do.
But after adding dependency this problem showed.
Update: Found the actual issue:
Flutter toast v8.1.3 cannot work with a Flutter version older than 3.7.0 because of a breaking change in Flutter v3.7.0. You have to either use fluttertoast v8.1.2 or you have to upgrade your flutter version to v3.7.0+.
Old Answer
I faced a similar issue after running the flutter pub upgrade but even after rolling back the changes in the pubspec.yaml file, I got the same error. But this issue was fixed after rolling back the changes in the pubspec.lock file. Make sure to do flutter clean after reverting changes in pubspec.lock file.
I also came across the same problem,
Due to some limitations I was not able to change the flutter version, and Changing the version of fluttertoast has not led to any success. so what I do is try some other alternatives
toast: ^0.3.0
https://pub.dev/packages/toast
I removed fluttertoast completely from the project and install a new dependency by running the command in the terminal
flutter pub add toast
usage:
Toast.show("Toast plugin app", duration: Toast.lengthShort, gravity: Toast.bottom);
try to use this:
if (!mounted) return;
snackBar(yourText, context);//or use your fluttertoast
if you had any problem or question i'm here to answer.
happy coding.
Unfortunately, this error is caused by a version incompatibility between the fluttertoast package and your version of Flutter. The Overlay.maybeOf method was removed in Flutter 2.0 and replaced with Overlay.of, which is likely what the fluttertoast package is using.
In order to fix this error, you can try upgrading to the latest version of fluttertoast, or if that doesn't work, downgrade your version of Flutter to a version compatible with the version of fluttertoast you are using.

Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?'

how can I fix this error in flutter with android studio
/C:/src/flutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_navigation/src/snackbar/snackbar.dart:452:31: Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null.
'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('/C:/src/flutterSDK/flutter/packages/flutter/lib/src/scheduler/binding.dart').
Try calling using ?. instead.
SchedulerBinding.instance.addPostFrameCallback(
^^^^^^^^^^^^^^^^^^^^
This error happens because the package get 4.6.2 or 4.6.3 is for new flutter sdk version 3.0. So you got this error. you have to use get 4.6.1 for fluter SDK version 2.xx
I had the same problem.. on "dart.get" package. Then I did this..
First go to pubspec.yaml file then edit the get version not more than
(get: ^4.6.1).. if you are using fluter sdk v2.xx.
if the version won't get lower then try this method
go to pubspec.lock file. edit the version not more than (4.6.1).. if you are using fluter sdk v2.xx.
you will find in pubspec.lock file
and last you have to do this
then "pub get" .. error will be gone.
This is because of recent flutter updates. All flutter SDKs >= V2.10.3 have this issue. There's no proper solution for this error yet.
Temporary Solution:
You can simply downgrade your flutter SDK to V2.10.2 or lower to get rid of this issue.
Note:
After downgrading, make sure you also change the dart version in pubspec.yaml of your flutter project according to the Flutter SDK.
This error is due to some changes happened in null-safety properties in Flutter 3.0.0. In your case you can try to import:
get: 4.6.1 instead of get: ^4.6.3.
Source: https://github.com/jonataslaw/getx/issues/2356
try this
flutter doctor --android-licenses

Why is riverpod failing even to initialize in project? Method not found: 'Error.throwWithStackTrace'

So i am trying to get started with riverpod and creating a new flutter project with the "click and counter" default sample.
As soon as I add on the pubspec
flutter_hooks: ^0.18.0
hooks_riverpod: ^2.0.0
And
import 'package:hooks_riverpod/hooks_riverpod.dart';
I get this error on the debug console and can't figure it out what is the problem
: Error: Method not found: 'Error.throwWithStackTrace'.
../…/framework/provider_base.dart:904
Error.throwWithStackTrace(error, chain);
^^^^^^^^^^^^^^^^^^^
: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
../…/framework/provider_base.dart:898
Never _rethrowProviderError(Object error, StackTrace stackTrace) {
^
Error.throwWithStackTrace was added in Dart 2.16 (Flutter version 2.10 from Feb 8, 2022).
https://api.flutter.dev/flutter/dart-core/Error/throwWithStackTrace.html
(Check the #Since annotation.)
If your Flutter/Dart version is below that, you'll get the error you saw.
Two options that may help are:
Specify an exact version of dependencies (don't use ^ ahead of version)
upgrade Flutter/Dart to at least 2.10/2.16
flutter upgrade
If your problematic package (hooks_riverpod: ^2.0.0 in your case) is listed with ^, it'll use the latest version that doesn't break dependencies.
I'm guessing that when you created a new project and used that same dependency version, upon initial pub get it downloaded a newer version of the package (or a newer version of a dependency that that package uses) into "pub cache" which is relying on the new Error API method.
Your project will store this information in:
<your_project_dir>/dart_tool/package_config.json
The min Dart SDK version listed for the package should normally have changed from 2.12 to 2.16. (update: it's been updated now) This would give us a hint that we need to update our Flutter/Dart if we see our build failing.
In an earlier version of this answer, I noted that the ^ prefix on package dependency versions is supposed to prevent these types of issues, but I'm no longer certain it was meant to cover this situation where the underlying platform needs to be updated (as opposed to a breaking change in the API of the package itself).
Anyways, at first glance, it might make sense to go from 2.0.0 to 3.0.0 for a package version # when it depends on a new core Dart API method that did not exist when 2.0.0 was published.
Notes
The author of riverpod also wrote the new API for Error.throwWithStackTrace so likely the latest version of hooks_riverpod is using the latest API changes. (The version you're listing 2.0.0 is pre-release currently). You could try earlier versions of riverpod in your pubspec.yaml (such as 1.0.3)
for anyone facing " Method not found: 'Error.throwWithStackTrace' " with firebase.
try to add this to your pubspec.yaml
dependency_overrides:
firebase_messaging_platform_interface: 3.1.6
I saw this.
How about trying flutter pub upgrade?
If it is not resolved, then check analyzer version and check which dependency locks that.
As noted in Baker's answer, Error.throwWithStackTrace was recently added in Dart 2.16.
If you're getting an error about Error.throwWithStackTrace not being found for some package, the package author neglected to update their package's minimum Dart SDK version. You should report that to the package maintainer. In the meantime, you should use an earlier version of the problematic package or use a newer version of the Dart SDK.
Try running flutter upgrade
By this it will upgrade your flutter and dart SDK version and hope it resolves your issue
if you are still facing the issues after "flutter upgrade" or you use this line of code in pubspec.yaml
dependency_overrides:
firebase_messaging_platform_interface: 3.1.6
you receive this type of errors
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
at com.sun.tools.javac.util.Assert.error(Assert.java:133)
at com.sun.tools.javac.code.TypeAnnotations.annotationType(TypeAnnotations.java:231)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:294)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitMethodDef(TypeAnnotations.java:1066)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
so Try to upgrade your gradle version, this line in your build.gradle
classpath 'com.android.tools.build:gradle:4.1.0'
after doing that it may be possible it ask you to change your
gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip
to
distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip
also upgarde this packages
firebase_core: ^1.10.0
firebase_messaging: ^11.1.0

Error when update facebook_audience_network to 0.9.0

Whan update my facebook_audience_network to 0.9.0 then I got this error message
[com.facebook.android:audience-network-sdk:6.4.0] C:\Users\007\.gradle\caches\transforms-2\files-2.1\25a494723d7018266df203e7ea11ccc5\audience-network-sdk-6.4.0\AndroidManifest.xml:12:9-55 Error:
Missing 'package' key attribute on element package at [com.facebook.android:audience-network-sdk:6.4.0] AndroidManifest.xml:12:9-55
[com.facebook.android:audience-network-sdk:6.4.0] C:\Users\007\.gradle\caches\transforms-2\files-2.1\25a494723d7018266df203e7ea11ccc5\audience-network-sdk-6.4.0\AndroidManifest.xml Error:
Validation failed, exiting
AndroidManifest of audience-network-sdk-6.4.0 includes 'queries' element, it requires fixed Gradle plugin.
I've solved the problem by rising Gradle plugin version to 3.6.4.
Here there are more info -
https://android-developers.googleblog.com/2020/07/preparing-your-build-for-package-visibility-in-android-11.html
Probably it's just a package mismatch, try to delete pubspec.lock and run
flutter clean
flutter pub get

DualTransitionBuilder is imported from both 'package:flutter/src/widgets/dual_transition_builder.dart' and

After upgrading to version of Flutter 1.20.x I'm getting the following error when building for both iOS and Android.
../../.pub-cache/hosted/pub.dartlang.org/animations-1.1.0/lib/src/shared_axis_transition.dart:241:12: Error: 'DualTransitionBuilder' is imported from both 'package:flutter/src/widgets/dual_transition_builder.dart' and 'package:animations/src/dual_transition_builder.dart'.
return DualTransitionBuilder(
^^^^^^^^^^^^^^^^^^^^^
Command PhaseScriptExecution failed with a nonzero exit code
I have done a Flutter clean several times, deleted and regenerated the iOS Podfile and manually deleted the flutter_build directory. Every time it regenerates the build with this error.
It's known issue, fixed now. Increase the version to at least 1.1.1 in pubspec.yaml
dependencies:
...
animations: ^1.1.1
and run
flutter pub get