Calling Firebase.initializeApp() returns 'Unable to establish connection on channel' - Flutter + Firebase - flutter

I'm working with Firebase in flutter (latest versions as of 1st July 2022), and when I try to call Firebase.initializeApp() in my Main function, it returns an error of:
'[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)'
Here is my code:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp();
runApp(const MyApp());
}
Any help would be greatly appreciated

I was able to solve the problem by upgrading all my firebase dependencies to the latest version using flutter pub outdated and flutter pub upgrade firebase_....
I encountered this issue after adding the firebase_messaging plugin v11.4.4. Might be related to the change in firebase_core_platform_interface.

Also got it after a pub update. Fixed it by doing:
flutter clean
and removing the pubspec.lock

Do a flutter clean and upgrade firebase core with
flutter pub upgrade firebase_core
The run
dart pub global activate flutterfire_cli
flutterfire configure
to reinitialize firebase. I experienced this after adding app_check support

I have updated the below dependency:
dependency_overrides:
firebase_core_platform_interface: 4.4.1
Executed this command and updated firebase dependencies
flutter pub upgrade firebase_core
flutter pub upgrade firebase_messaging
it is working properly now.

Problem seems to be with the core platform interface.
Add firebase_core_platform_interface: 4.4.0 and adjust all other firebase deps to make them compatible with this library. I downgraded all versions to 36 day old release and it finally works.

I just built a new flutter app and I got this error when initializing Firebase App and running it in the browser and not the android emulator. I am using VS Code and you can change the target device in the bottom task bar on the right side.
Solution is to run it in the android emulator. I don't know if there are permissions to be set for web view but I do not plan on deploying to web.

Had the same problem and scaled back (thank you git) - getting flutter dependencies right - as in it compiles and work as advertised is no mean feat. Welcome :)

Related

Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)

Suddenly this error appears in the debug console. I do not know what I did wrong.
You've upgraded Flutter but not the packages. In the terminal enter
flutter pub outdated
Then upgrade the outdated packages one by one like this:
flutter pub upgrade outdated_package
After you're finished:
flutter clean
and
flutter pub get
Your problem should now be solved.
I had the same issue and stumped on this post.
In my case I was able to detect which plugin was in fact giving the error and it turned out to be firebase_core. So, I decided to upgrade the package to the latest version which happened to be 1.21.1 in my case.
So, to solve the issue I will suggest you try changing the version of the firebase_core package you're using to the latest in the pubspec.yaml file of your project like so:
firebase_core: ^1.21.1 (replace with latest verison)
Or you can just run:
flutter pub upgrade firebase_core
This will upgrade firebase_core to the latest version.
Or you can as well put any as the version code in the pubspec.yaml file of your project like so:
firebase_core: any (upgrades firebase_core to the latest verison)
Please also check the compileSdkVersion in android/app/build.gradle and update it to 33
You are good to go with these three steps,
Flutter clean
Flutter pub get
Flutter run
If you are using these dependecies then replace it with a latest version:
firebase_messaging
firebase_core
flutter_local_notifications
Then in android/app/build.gradle update compileSdkVersion flutter.compileSdkVersion to 33
I spent a long time looking into this and eventually traced it to the plugin registrar being nil when setting up the plugin.
This was caused by setting my iOS app root view controller to anything other than FlutterViewController (i.e. in my case, I had a UINavigationController as the root). This will result in a failure to register all your plugins.
The app delegate assumes that the root view controller is a FlutterViewController, so if it isn't then you will need to re-direct all plugin-related function calls to your FlutterViewController from your app delegate by overriding these functions as follows:
override func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar? {
flutterViewController.registrar(forPlugin: pluginKey)
}
override func hasPlugin(_ pluginKey: String) -> Bool {
flutterViewController.hasPlugin(pluginKey)
}
override func valuePublished(byPlugin pluginKey: String) -> NSObject? {
flutterViewController.valuePublished(byPlugin: pluginKey)
}
I was have this problem.
after downgrade awesome_notifications package to 0.6.21, resolved this.
I also effected from that issue for few hours, finally I found issue that was I ran my emulator as windows (:, yeah please run with Android emulator you selected vm.
for me my dependencies were up to date but I was using windows as an emulator so I switched to android emulator issue was resolved.

MissingPluginException(No implementation found in flutter using geolocator

i am using geolocator in flutter project to get current location but this error come on it.
i added all dependencies in both ios and android files still get this error i dont know why
flutter channel stable, 2.12,
here is my code:
Position position = await Geolocato.getCurrentPosition( desiredAccuracy: LocationAccuracy.high);
here is my error coming which i tested android 10, 8 also, but answer same
Unhandled Exception: MissingPluginException(No implementation found for method getCurrentPosition on channel flutter.baseflow.com/geolocator)
i am using geolocator plugin here is plugin link :https://pub.dev/packages/geolocator
Maybe someone will need my solution. This happens because GeolocatorPlatform.instance is not initialized. Call _registerPlatformInstance() where you need.
import 'package:geolocator_android/geolocator_android.dart';
import 'package:geolocator_apple/geolocator_apple.dart';
void _registerPlatformInstance() {
if (Platform.isAndroid) {
GeolocatorAndroid.registerWith();
} else if (Platform.isIOS) {
GeolocatorApple.registerWith();
}
}
Running flutter clean and flutter pub get fixed the issue for me. I uninstalled the application, cleared the cache of my device and rebuilt the app. This time there was a popup asking to give location permission to the app.
I gave the access and got the current position of the device (latitude and longitude).
Also make sure you upgrade flutter to 3.0.0 by running flutter upgrade
If you just installed the package (geolocator), just restart the app or even better the phone.
Stop running the app completely and restart the app.
make sure that the app is killed before restart
click stop button, refer below,
Upgrade your flutter
Run on terminal flutter upgrade
or flutter upgrade —-force
Then =>flutter pub outdated
Then =>flutter pub upgrade
After that =>flutter pub upgrade —-major-versions
Finally go to
yourProjectName/android/app/build.gradle
Change:
android {
compileSdkVersion ##
…
…
}
To:
android {
compileSdkVersion 33
…
…
}

shared preference macos lib missing from Dart

I have this error with my Flutter app that caused by Dart SDK
I use Flutter 1.22.6 with Dart SDK 2.10.5 (stable) & intellij 2020.3 ...
when click on fix only remove shows, after remove the error goes, but then the error starts popup ...as I'm doing Android app so it's not affecting , but later for the iOS version I guess it will affect .
any idea how to solve ?
It looks like a cache problem.
Try to run the following commands:
flutter pub cache repair
flutter packages get

StaggeredGridView not scrolling after updating Flutter

I updated my flutter and dart package last night and now StaggeredGridView which was scrolling perfectly before is giving me an error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'SliverHitTestResult' is not a subtype of type 'BoxHitTestResult'
i had the same problem , and i solved upgrading the version in pubspeck.yaml to flutter_staggered_grid_view 0.3.0
The BoxHitTestResult exception was fixed in new version of flutter_staggered_grid_view 0.3.0
You can check changelog here
If you have same issue after the upgrade,
run flutter clean in terminal and then run again.
#Yamim comment: "switch your channel to stable" worked.
Here is the command you can use:
flutter channel stable
Other Channels:
$ flutter channel
Flutter channels:
* stable
beta
dev
master
For more information about channels you can refer:
https://github.com/flutter/flutter/wiki/Flutter-build-release-channels
This issue is resolved in the upgraded package No need to modify the code just upgrade the package.
Add the following dependencies to your pubspec.yaml and restart the application. It works well.
flutter_staggered_grid_view: 0.3.0

Usage of Websocket, STOMP in flutter application

While trying to work with STOMP, websockets, facing issue for "packages get" after updating pubspec with required stomp/websocket details. I have tried for stomp, stompdart, websocket none of them worked.
Error observed while running "packages get" is
"The current Dart SDK version is 2.1.0-dev.4.0.flutter-4eb879133a.
Because project_name depends on stompdart >=0.0.2 which requires SDK version >=1.5.0 <2.0.0, version solving failed.
pub upgrade failed (1)"
If I try to downgrade flutter version then it has thrown exception informing 'current project needs SDK version > 2.0.0
Please help to clear the issue or suggest some other way as I am using STOMP at server end.
had the same issue, it can be solved in two ways:
solved it by adding this to my yaml file :
dependency_overrides:
stomp: ^0.7.3
dependencies:
stomp: ^0.7.3
flutter:
sdk: flutter
using the dependency_overrides works.
Secondly by running "pub upgrade" in your project directory
https://github.com/rikulo/stomp/issues/18#issuecomment-435748215
Well, this is not a definitive answer, but it may help you.
I forked a chinese library that seems to work named JStomp and did some translations. Let me know if it work since I am also interested to be able to work with STOMP on Flutter.
Here's my fork: https://github.com/raedcran/flutter_jstomp