Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter/Dart/firebase:: Error when trying to sign out

Not sure why I am not able to sign out.
When I click a button on the app bar, see ‘sign out’,
I click it,
system then asks me to confirm to sign out, I click it.

then I get an error and I am not signed out,

The expected result should be signing out without an error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

CODE SNIP::

class _NotesViewState extends State<NotesView> {
  void _popupMenuActionsPressed(value) async {
    devtools.log('App bar $value was pressed');
    switch (value) {
      case MenuAction.logout:
        final shouldLogout = await showLogOutDialog(context);
        devtools.log('User logout');

        if (shouldLogout) {
          devtools.log('inside if statement');
          await FirebaseAuth.instance.signOut();
          Navigator.of(context)
              .pushNamedAndRemoveUntil(homeRoute, (_) => false);
        }

        break;
      default:
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Main UI'),
        actions: [
          PopupMenuButton<MenuAction>(
            onSelected: (value) {
              _popupMenuActionsPressed(value);
            },
            itemBuilder: (context) {
              return [
                const PopupMenuItem<MenuAction>(
                  value: MenuAction.logout,
                  child: Text('Sign out'),
                )
              ];
            },
          )
        ],
      ),
      body: const Text('Hello world'),
    );
  }
}

ERROR SNIP

User logout
[log] inside if statement
E/flutter (10193): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
E/flutter (10193): #0      MethodChannelFirebase.app
package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:193
E/flutter (10193): #1      Firebase.app
package:firebase_core/src/firebase.dart:56
E/flutter (10193): #2      FirebaseAuth.instance
package:firebase_auth/src/firebase_auth.dart:44
E/flutter (10193): #3      _NotesViewState._popupMenuActionsPressed
package:ijob_clone_app/main.dart:81
E/flutter (10193): <asynchronous suspension>
E/flutter (10193):

>Solution :

The error is not from the code, it is because you are not initializing firebase in your main function.
Edit your main function as follows:

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(myApp());
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading