The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel<dynamic>' - flutter

After running the Flutter project, I get this error. What can I do to solve it?
Error: The method 'setMockMessageHandler'
isn't defined for the class 'BasicMessageChannel<dynamic>'.
FAILURE: Build failed with an exception.

I had the same problem after update plugin's in AndroidStudio on Mac
flutter pub upgrade
did nothing for me, but
flutter clean
flutter pub upgrade --major-versions
has solved the problem

Go to specified class 'BasicMessageChannel' by press and hold ctrl and click on it
than search for the 'setMockMessageHandler' by ctrl+F
than u will see something like this
// Looking for setMockMessageHandler?
// See this shim package: packages/flutter_test/lib/src/deprecated.dart
and paste this line below this comment
void setMockMessageHandler(dynamic message){
}
but this is just simple hack which is not recommended

I had the same problem today.
from what i could notice, this basically was a breaking change caused by transition of platform channel test interfaces to flutter_test package.
in my case, the problem was resolved just running the flutter pub upgrade on a global terminal session.
see more details about the mentioned transition on referred release notes

I have the same problem, I have tried all the above and did not help.
flutter pub upgrade and flutter pub upgrade --major-versions outputs this:
No dependencies changed.
1 package is discontinued.
76 packages have newer versions incompatible with dependency constraints.
Try flutter pub outdated for more information.
No changes to pubspec.yaml!
The plugins advance_pdf_viewer, flutter_absolute_path, geocoder, google_api_headers, onesignal_flutter use a deprecated version of the
Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise,
consider removing them since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding:
https://flutter.dev/go/android-plugin-migration.

Running across this problem after upgrading to Flutter 2.5.3 (from 2.2.3). The change outlined in the release notes broke several hundred tests since the mock method handlers were set in the global setUp() for most tests.
As shown in the release notes, I replaced code like
MethodChannel('channelName')
.setMockMethodCallHandler((MethodCall methodCall) {});
with code using the default instance of TestDefaultBinaryMessenger:
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(MethodChannel('channelName'), (MethodCall methodCall) {});
This change allowed me to keep all tests unchanged.

Related

The plugins `advance_pdf_viewer, flutter_webview_plugin` use a deprecated version of the Android embedding

The plugins advance_pdf_viewer, flutter_webview_plugin use a deprecated version of the Android embedding.
To avoid unexpected runtime failures or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of
Flutter will remove these deprecated APIs."
I follow some documentation but is still not working.
i upgrade and downgrade my version but still not working.
should I share my mainActivity.kt and manifest file?
if there is no newer version of advance_pdf_viewer, flutter_webview_plugin available with the new android V2 embedding, your can't do anything inside of your app. Keep watching for plugin updates of these 2 plugins... or go to it's github project and open an issue to fix it. Sometime the master branch has already fix it. In this case you could try to link direct to the master branch and not to a version in pub.dev
for advance_pdf_viewer i use $flutter pub add advance_pdf_viewer
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:
advance_pdf_viewer: ^2.0.1
Alternatively, your editor might support or flutter pub get. Check the docs for your editor to learn more.
Import it
Now in your Dart code, you can use:
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
and for webview I try dependencies:
flutter_webview_plugin:
git: https://github.com/nuc134r/flutter_webview_plugin.git
and it all works for me than you.

The plugin admob_flutter uses a deprecated version of the Android embedding

when i put admob_flutter: ^2.0.0-nullsafety.1 in pubspec, and type on cmd flutter pub get this error occurs!
The plugin admob_flutter uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of
Flutter will remove these deprecated APIs.
It's for latest flutter updates. so you can't do anything. Please use other package or wait till fix the problem by package developer because this error is produced after flutter version 2.5.
I have downgraded my flutter version by command flutter downgrade and it shows an option of a downgraded flutter version and it resolves my error.
Downgrading flutter worked for me.

Flutter | Error: Couldn't resolve the package

I created a package that is a collection of my own helper classes for faster developing...
The package also included firebase_analytics: which requires a native implementation for each platform i want it to run. Even if i dont wanted to use firebase at all, but still wanted to use my package i was forced to create firebase-config files for the app, because the app crashes if the firebase_analytics package does not find a valid file for the specific platform. To avoid those things i splitted my package in two packages.
The Core-Package: All helper classes that run native dart code
Optional extension: Only the classes that need the firebase implementation
So if i want to use the package without firebase i just have to depend on the core.
If i want to use the firebase variant i could simply depend the firebase package, because the extension package itself depends on the core-package in its own pubspec.yaml file.
PROBLEM: Since i restructured my package like i described, all my apps that depend on it are not building anymore. The console says that all packages that i depend on in my two packages can not be found. This error occures both ways: With firebase & without.
ERROR: (Scroll down for the complete console output)
MY ATTEMPTS:
"flutter clean" & "flutter pub get" in every package and app folder
"flutter pub cache repair"
CORE-PACKAGE Pubspec.yaml:
FIREBASE-Extension Pubspec.yaml:
Plain Console Output:
pastebin.com/m14cbqDV
Thanks for any help!!
I am facing the same issue while i was making a build in Xcode 13.So I had upgraded my flutter version 2.8.0 to 2.10.2 and also removed the version of all firebase dependencies, then the issue was finally solved.
I have faced similar issues and resolved them by removing package versions. Issues like this often arise due to mismatched versions of packages (eg firebase_core, firebase analytics). Please try to remove versions of the firebase packages or the whole packages. (like firebase_analytics :).
Sorry, my bad! As you can see i moved my dependencys to the dev section of my pubspec.yaml. They should be placed in the dependency section.

The argument type 'PointerEvent' can't be assigned to the parameter type 'PointerDownEvent'

Recently I've updated to flutter 2.5 and the newest androids studio, and tried to compile my flutter project to android device. Android studio throws me the error below. If I write flutter run in a terminal there is no problem compiling to android device.
Guess this must be related to android studio. I tried downgrade to an earlier android studio version, but the problem persists.
I'm not sure what plugin this is, it doesn't seem like any I use in my project.
Edit: If I downgrade flutter from 2.5 to 2.0 my project compiles again. So the problem is within flutter 2.5
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
../plugins/flutter/.pub-cache/hosted/pub.dartlang.org/photo_view-0.11.1/lib/src/core/photo_view_gesture_detector.dart:106:29: Error: The argument type 'PointerEvent' can't be assigned to the parameter type 'PointerDownEvent'.
- 'PointerEvent' is from 'package:flutter/src/gestures/events.dart' ('../plugins/flutter/packages/flutter/lib/src/gestures/events.dart').
- 'PointerDownEvent' is from 'package:flutter/src/gestures/events.dart' ('../plugins/flutter/packages/flutter/lib/src/gestures/events.dart').
super.addAllowedPointer(event);
There was an API change in version 2.5 of flutter and several packages must update accordingly.
Your logs show that the exact package which contains the error is photo_view.
Luckily enough the package has just been updated to fix this, so just update its version in your pubspec.yaml:
photo_view: ^0.12.0
UPDATE
If you don't have the package directly in your pubspec
You have two options
1 It's probably a transient dependency, you can run flutter pub deps
to list the installed packages and its dependencies and try to update the one that uses photo_view (if it does have an update)
2 Add a dependency override to your pubspec.yaml, this will effectively override the version of the package being used
dependency_overrides:
photo_view: ^0.12.0
Add this just before your dev_dependencies
from your debug code
('../plugins/flutter/packages/flutter/lib/src/gestures/events.dart').
you open the file or click if there are link clickable
Search for this:
void addAllowedPointer(PointerEvent event) {
and replace with this:
void addAllowedPointer(PointerDownEvent event) {
Here is the reference link
https://flutter.dev/docs/release/breaking-changes/gesture-recognizer-add-allowed-pointer
This problem arises due to the GestureRecognizer Cleanup -
Here is the documentation if you are intrested in the migration code
But in case you just want to build your flutter app without any migrations following are couple of solutions to that problem
You can update photo_view dependency in your pubspec.yaml file to
photo_view :^0.12.0
If you do not want to update your dependency due to any reason you can opt for this temporary fix . In the pubspec.yaml file add the following custom photo_view with better gesture recognition in dependency_overrides.
dependency_overrides:
photo_view:
git: git://github.com/robertodoering/photo_view.git

Flutter: build runner throws a precompile error

I am using analyser 1.7.1. The latest build_runner build command generates the following error.
flutter packages pub run build_runner build Failed to precompile
build_runner:build_runner:
../../../sdk/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.1/lib/src/error/best_practices_verifier.dart:1998:14:
Error: A non-null value must be returned since the return type
'String' doesn't allow null. String get displayString {
The usual flutter clean and pub cache repair commands don't seem to be fixing the problem, and displayString doesn't appear anywhere in my codebase.
There's an issue open 9 days ago. Here's the key part:
Right now, the current state of affairs is that:
package:analyzer 1.7.0 requires package:meta ^1.4.0
package:analyzer 1.7.1 has the same contents as 1.7.0, but requires package:meta ^1.3.0
Flutter stable pins package:meta to 1.3.0
I'm uncertain how we're running into the exceptions above - the two most recent versions of analyzer are pretty explicit about which version of meta they need.
#edlman do you have any dependency_overrides in your pubspec?
you're right, I'm using 3rd party pkgs which depend on meta 1.4.0 so I put it to dependency_overrides to solve the collision. It didn't come to my mind it cause such a problem.
I've changed the override to 1.3.0, it works fine, no problem yet
So I'd suggest checking whether or not there's a dependency_overrides in your pubspec, too.
It's a problem with analyser 1.7.1.
Add
dependency_overrides:
analyzer: 1.7.0
to pubspec.yaml.
There are more details available in raina77ow's answer.