title: Flutter -- No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
body: <p>I'm learning Flutter by following the relatively recent tutorial (made in February - <a href="https://youtu.be/VPvVD8t02U8?t=36573" rel="nofollow noreferrer">LINK</a>) and while I wrote the same code as author I'm getting the following exception:</p>
  <pre><code>======== Exception caught by widgets library =======================================================
  The following FirebaseException was thrown building FutureBuilder&lt;FirebaseApp&gt;(dirty, state: _FutureBuilderState&lt;FirebaseApp&gt;#881ee):
  [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
  
  The relevant error-causing widget was: 
    FutureBuilder&lt;FirebaseApp&gt; FutureBuilder:file:///C:/Users/Mrky/Desktop/Sve/Faks/10_semestar/mynotes/lib/main.dart:30:13
  When the exception was thrown, this was the stack: 
  #0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:173:5)
  #1      Firebase.app (package:firebase_core/src/firebase.dart:53:41)
  #2      FirebaseAuth.instance (package:firebase_auth/src/firebase_auth.dart:38:47)
  #3      HomePage.build.&lt;anonymous closure&gt; (package:mynotes/main.dart:37:34)
  #4      _FutureBuilderState.build (package:flutter/src/widgets/async.dart:615:55)
  #5      StatefulElement.build (package:flutter/src/widgets/framework.dart:4919:27)
  #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4806:15)
  #7      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4977:11)
  #8      Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
  #9      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2659:19)
  #10     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:891:21)
  #11     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:370:5)
  #12     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146:15)
  #13     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1083:9)
  #14     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:997:5)
  #18     _invoke (dart:ui/hooks.dart:151:10)
  #19     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
  #20     _drawFrame (dart:ui/hooks.dart:115:31)
  (elided 3 frames from dart:async)
  ==========================================================================================
  </code></pre>
  <p>The code that I have currently written is:</p>
  <pre><code>import 'package:firebase_core/firebase_core.dart';
  import 'package:flutter/material.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:mynotes/firebase_options.dart';
  import 'package:mynotes/views/login_view.dart';
  
  
  void main() {
    WidgetsFlutterBinding.ensureInitialized();
    runApp(
      MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.green,
        ),
        home: const HomePage(),
      ),
    );
  }
  
  class HomePage extends StatelessWidget {
    const HomePage({Key? key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: const Text('Home'),
        ),
        body: FutureBuilder(
          future: Firebase.initializeApp(
            options: DefaultFirebaseOptions.currentPlatform,
          ),
          builder: (context, snapshot) {
            switch (snapshot.connectionState) {
              case ConnectionState.done:
                print(FirebaseAuth.instance.currentUser);
                return const Text('Done');
              default:
                return const Text('Loading...');
            }
          },
        ),
      );
    }
  }
  </code></pre>
  <p>As it is visible I have Firebase.initializeApp inside future of FutureBuilder. Also If I comment out the line <code>print(FirebaseAuth.instance.currentUser);</code> the app will show text <em>Done</em> without any problem.</p>