title: flutter web: No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in FlutterFire
body: <p>After searching tons of SO answers also I wasn't able to solve this.</p>
  <p>I tried all 4 methods of <a href="https://stackoverflow.com/questions/63492211/no-firebase-app-default-has-been-created-call-firebase-initializeapp-in?noredirect=1&amp;lq=1">No Firebase App &#39;[DEFAULT]&#39; has been created - call Firebase.initializeApp() in Flutter and Firebase</a>
  but, couldn't solve the bug.</p>
  <p>I tried adding Firebase.initializeApp() on initState() but, it also didn't work.</p>
  <p><strong>main.dart</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:firebase_core/firebase_core.dart';
  import 'package:dashboard/app.dart';
  import 'package:url_strategy/url_strategy.dart';
  
  void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    setPathUrlStrategy();
    runApp(App());
  }
  
  </code></pre>
  <p><strong>app.dart</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  
  import 'package:dashboard/routes/help_and_support.dart';
  import 'package:dashboard/routes/homepage.dart';
  import 'package:dashboard/routes/items.dart';
  
  class App extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'vipatra',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        initialRoute: '/',
        routes: {
          '/': (context) =&gt; HomePage(),
          '/items': (context) =&gt; ShowItems(),
          '/help-and-support': (context) =&gt; HelpAndSupport(),
        },
      );
    }
  }
  
  </code></pre>
  <p><strong>homepage.dart</strong></p>
  <pre><code>import 'package:firebase_core/firebase_core.dart';
  import 'package:flutter/material.dart';
  
  import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  
  import 'package:dashboard/style.dart';
  
  class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() =&gt; _HomePageState();
  }
  
  class _HomePageState extends State&lt;HomePage&gt; {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('vipatra'),
        ),
        drawer: Drawer(
          child: ListView(
            padding: EdgeInsets.zero,
            children: &lt;Widget&gt;[
              DrawerHeader(
                child: Text(
                  '',
                ),
                decoration: BoxDecoration(
                  color: Colors.blue,
                ),
              ),
              ListTile(
                leading: Icon(
                  Icons.inventory,
                ),
                title: Text('Items'),
                onTap: () {
                  Navigator.pushNamed(context, '/items');
                },
              ),
              ListTile(
                leading: Icon(
                  Icons.reorder,
                ),
                title: Text('All Transactions'),
                onTap: () {
                  // Update the state of the app.
                  // ...
                },
              ),
              ListTile(
                leading: Icon(
                  Icons.help_outline,
                ),
                title: Text(
                  'Help &amp; Support',
                ),
                onTap: () {
                  Navigator.pushNamed(context, '/help-and-support');
                },
              )
            ],
          ),
        ),
        body: SingleChildScrollView(
          child: Container(
            alignment: Alignment.center,
            child: ConstrainedBox(
              constraints: BoxConstraints(
                maxWidth: 800,
              ),
              child: Column(
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.symmetric(
                      horizontal: 15,
                      vertical: 10,
                    ),
                    child: Text(
                      'Items',
                      style: headerTextStyle,
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(
                      bottom: 25,
                    ),
                    child: Items(),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
    }
  
    String? uid;
    late List&lt;Map&lt;String, String&gt;&gt; items;
  
    Future&lt;String?&gt; getUserId() async {
      FirebaseAuth auth = FirebaseAuth.instance;
  
      if (auth.currentUser != null) {
        String uid = auth.currentUser!.uid;
        print(uid);
        return uid;
      } else {
        return null;
      }
    }
  
    void getItems() async {
      FirebaseFirestore db = FirebaseFirestore.instance;
  
      db
          .collection('biz')
          .doc('demo')
          .collection('items')
          .get()
          .then((QuerySnapshot&lt;Map&lt;String, dynamic&gt;&gt; querySnapshot) {
        querySnapshot.docs.forEach((doc) {
          items.add({
            'name': doc.data()['item']['name'],
            'price': doc.data()['item']['price'],
          });
        });
      });
    }
  }
  
  class Items extends StatefulWidget {
    @override
    _ItemsState createState() =&gt; _ItemsState();
  }
  
  class _ItemsState extends State&lt;Items&gt; {
    @override
    Widget build(BuildContext context) {
      CollectionReference&lt;Map&lt;String, dynamic&gt;&gt; items = FirebaseFirestore.instance
          .collection('biz')
          .doc('biz-id')
          .collection('items');
  
      return StreamBuilder&lt;QuerySnapshot&lt;Map&lt;String, dynamic&gt;&gt;&gt;(
        stream: items.snapshots(),
        builder: (BuildContext context,
            AsyncSnapshot&lt;QuerySnapshot&lt;Map&lt;String, dynamic&gt;&gt;&gt; snapshot) {
          if (snapshot.hasError) {
            return Text('Something went wrong');
          }
  
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Text(&quot;Loading&quot;);
          }
  
          return ListView.builder(
            shrinkWrap: true,
            itemCount: snapshot.data!.docs.length,
            itemBuilder: (context, index) {
              DocumentSnapshot&lt;Map&lt;String, dynamic&gt;&gt; document =
                  snapshot.data!.docs[index];
              return Card(
                child: ListTile(
                  onTap: () {},
                  leading: Text(
                    document.data()!['item']['name'],
                  ),
                  title: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Container(
                        child: Text(
                          '₹ ${document.data()!['item']['price'].toString()}',
                          style: TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              );
            },
          );
        },
      );
    }
  }
  
  </code></pre>
  <p><strong>pubspec.yaml</strong></p>
  <pre><code>name: dashboard
  description: A new Flutter project.
  
  publish_to: &quot;none&quot;
  
  # 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: &quot;&gt;=2.12.0 &lt;3.0.0&quot;
  
  dependencies:
    flutter:
      sdk: flutter
    url_launcher: ^6.0.4
    url_strategy: ^0.2.0
    firebase_core: ^1.2.0
    cloud_firestore: ^2.2.0
    firebase_auth: ^1.2.0
  
  dev_dependencies:
    flutter_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:
    uses-material-design: true
    # To add assets to your application, add an assets section, like this:
    # assets:
    #   - images/a_dot_burr.jpeg
    #   - images/a_dot_ham.jpeg
    # An image asset can refer to one or more resolution-specific &quot;variants&quot;, 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 &quot;flutter&quot; section. Each entry in this list should have a
    # &quot;family&quot; key with the font family name, and a &quot;fonts&quot; 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
  
  </code></pre>
  <p>Error I am getting:</p>
  <pre><code>The following FirebaseException was thrown building Items(dirty, state: _ItemsState#ce219):
  [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
  
  The relevant error-causing widget was:
    Items file:///C:/Users/vignesh/vipatra/dashboard/lib/routes/homepage.dart:90:26      
  
  When the exception was thrown, this was the stack:
  #0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:122:5)
  #1      Firebase.app (package:firebase_core/src/firebase.dart:54:41)
  #2      FirebaseFirestore.instance (package:cloud_firestore/src/firestore.dart:27:21)  
  #3      _ItemsState.build (package:dashboard/routes/homepage.dart:142:73)
  #4      StatefulElement.build (package:flutter/src/widgets/framework.dart:4691:27)     
  #5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)
  #6      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4746:11)
  #7      Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)
  #8      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4553:5)
  #9      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4737:11)
  #10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4548:5)     
  ...     Normal element mounting (10 frames)
  #20     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)     
  #21     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6221:36)
  #22     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6232:32)
  ...     Normal element mounting (109 frames)
  #131    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)     
  #132    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6221:36)
  #133    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6232:32)
  ...     Normal element mounting (238 frames)
  #371    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)     
  #372    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6221:36)
  #373    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6232:32)
  ...     Normal element mounting (360 frames)
  #733    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)     
  #734    Element.updateChild (package:flutter/src/widgets/framework.dart:3360:20)       
  #735    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1189:16)
  #736    RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1167:5)
  #737    RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1181:7)
  #738    Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)
  #739    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2582:33)     
  #740    AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1106:19)
  #741    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:328:5)
  #742    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
  #743    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
  #744    AutomatedTestWidgetsFlutterBinding.pump.&lt;anonymous closure&gt; (package:flutter_test/src/binding.dart:973:9)
  #747    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)    
  #748    AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:960:27)
  #749    WidgetTester.pumpWidget.&lt;anonymous closure&gt; (package:flutter_test/src/widget_tester.dart:534:22)
  #752    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)    
  #753    WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:531:27)   
  #754    main.&lt;anonymous closure&gt; (file:///C:/Users/vignesh/vipatra/dashboard/test/widget_test.dart:6:18)
  #755    main.&lt;anonymous closure&gt; (file:///C:/Users/vignesh/vipatra/dashboard/test/widget_test.dart:5:28)
  #756    testWidgets.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:flutter_test/src/widget_tester.dart:156:29)
  &lt;asynchronous suspension&gt;
  &lt;asynchronous suspension&gt;
  (elided 5 frames from dart:async and package:stack_trace)
  
  ════════════════════════════════════════════════════════════════════════════════════════════════════
  00:04 +0 -1: Demo test [E]
    Test failed. See exception logs above.
    The test description was: Demo test
  
  00:05 +0 -1: Some tests failed.
  
  </code></pre>