4

Error Description I am running my flutter app on windows desktop I am using master channel in android studio in order to run it on desktop. I have integrated firebase to my app, and login signup is working fine, but when I try to add or get data from my cloud firestore, the error appears to be is " No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase" , which was solved by adding

void main()
async
{
   WidgetsFlutterBinding.ensureInitialized();
   await Firebase.initializeApp();
   // if (USE_FIRESTORE_EMULATOR) {
   //   FirebaseFirestore.instance.settings = Settings(
   //       host: 'localhost:8080', sslEnabled: false, persistenceEnabled: false);
   // }
  runApp(MyApp());
}

to my app. but after adding this I got this error:

Launching lib\main.dart on Windows in debug mode...
Building Windows application...
Debug service listening on ws://127.0.0.1:14281/b7FohxM2yN4=/ws
Syncing files to device Windows...
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
<asynchronous suspension>
#1      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:344:35)
<asynchronous suspension>
#2      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30:22)
<asynchronous suspension>
#3      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75:7)
<asynchronous suspension>
#4      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:9)
<asynchronous suspension>
#5      main (package:res_ds/main.dart:17:4)
<asynchronous suspension>

and that's the error I am unable to solve. My app GUI does not show after this error. I have tried multiple solutions which were available on internet, but none of them worked for me. I have provided below flutter doctor and pubspec, kindly have look and help me solving this issue. Thanks in advance Flutter Doctor

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 1.27.0-2.0.pre.67, on Microsoft Windows [Version 10.0.19041.804], locale 
en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.4)
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.52.1)
[√] Connected device (1 available)

! Doctor found issues in 1 category.

Pubspec.yaml

name: res_ds
description: A new Flutter application.

# 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: ^1.0.2
  provider: ^4.3.2+2
  http: ^0.12.2
  cloud_firestore: ^0.14.2
  firebase_core: ^0.5.0
  image_picker: ^0.6.7+22


dev_dependencies:
  flutter_test:
    sdk: flutter
  integration_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:

  # 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:
     - assets/images/
  #   - 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
Rabbiya
  • 41
  • 2

2 Answers2

3

The Flutter Firebase plugins do not currently support Windows, which is why there's no plugin implementation when you run on Windows.

smorgan
  • 20,228
  • 3
  • 47
  • 55
  • 1
    I'm not sure why people are down-voting this answer. The cause of the error in this question is that the plugin implementation *does not exist* for Windows. The reason trying various solutions for that error message that they found online didn't work is that the source of the error in this particular case is not a configuration error, it's that there *is* no implementation. I've linked to the authoritative source for the plugin, which lists the platforms it supports, and that doesn't include Windows. – smorgan May 02 '21 at 12:41
  • I am currently writing a desktop flutter app that shares much code with an Android/IOS app, and get the same error. My app uses several packages where windows was not listed, but no problem. The package firedart states explicitly that it is "dart native". So I guess firebase is not "dart native". It would help my understanding if someone explained what these "channels" mean. A bridge from dart to code written in another language? And lastly I wonder why Google says Flutter 2.2 supports Windows, but an important package like Firebase is not supported yet. – Michael Uhlenberg May 23 '21 at 15:34
  • @MichaelUhlenberg Most packages work on all platforms; plugins are packages that have native, platform-specific code. For an explanation of channels, see https://flutter.dev/docs/development/platform-integration/platform-channels. As for supporting Windows, Firebase itself has no Windows desktop support. There's no Windows Firebase SDK, as there is for iOS and Android. Flutter isn't Firebase, just as it isn't any of the many other plugins, and supporting a platform doesn't mean every possible plugin is going to support that platform. – smorgan May 23 '21 at 23:25
0

because firebase does not support Windows, I did this and wherever I used firebase classes, I set this condition and the problem was solved...

void main() async {
  Bloc.observer = PishBlocObserver(); //log Bloc/cubit
  WidgetsFlutterBinding.ensureInitialized();
  
  (!Platform.isWindows) ? await Firebase.initializeApp() : null;
  FirebaseMessaging.onBackgroundMessage(resiveNotiInBackGround);

  runApp(....

and

 gettokan() async {
      await FirebaseMessaging.instance.getToken().then((value) {
        print(value);
      });
    }

   (!Platform.isWindows) ? gettokan() : null;

and ...