Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Firebase App has been created - call Firebase.initializeApp [duplicate]

[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

I kinda understand the error but whereever I put it, it doesn't work... I am trying to return only a string and a number value from firebase. And I also did all the requirements. build.graddle in android folder, and build.gradle in android/app folder. Everything. In addition to that I also did: cloud_firestore:

to the dependencies on the pubspec.yaml. Now my main.dart looks like this, but gives so much errors I can't paste here. It's very long. I was using this video as a base but it doesn't work..

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  Widget _buildListItem(BuildContext context, DocumentSnapshot document) {
    return ListTile(
      title: Row(
        children: [
          Expanded(
            child: Text(
              document.data()['adSoyad'],
            ),
          ),
          Container(
            decoration: const BoxDecoration(
              color: Color(0xffddddff),
            ),
            padding: const EdgeInsets.all(10.0),
            child: Text(
              document.data()['yas'].toString(),
              style: Theme.of(context).textTheme.headline4,
            ),
          ),
        ],
      ),
      onTap: () {
        print("bisey");
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: StreamBuilder(
          stream: FirebaseFirestore.instance.collection('tablolar').snapshots(),
          builder: (context, snapshot) {
            if (!snapshot.hasData) return const Text('Loading...');
            return ListView.builder(
              itemExtent: 80.0,
              itemCount: snapshot.data.documents.length,
              itemBuilder: (context, index) =>
                  _buildListItem(context, snapshot.data.documents[index]),
            );
          }),
    );
  }
}
like image 281
Stayheuh Avatar asked Sep 12 '26 09:09

Stayheuh


1 Answers

inside main function add this two lines and make your function asynchronous. like this

 void main() async {
 WidgetsFlutterBinding.ensureInitialized();
 await Firebase.initializeApp();
 runApp(MyApp());
 } 

and one more thing, you also need to add firebase_core to your project. otherwise firebase will throw and error

In your pubsec.yaml file add firebase core

  firebase_core: ^0.5.3

and then import it into your main.dart

import 'package:firebase_core/firebase_core.dart';
like image 80
GloatingCoder Avatar answered Sep 14 '26 23:09

GloatingCoder