Praveen Kumar
Praveen Kumar

Reputation: 299

The following FirebaseException was thrown building Builder: [core/no-app] No Firebase App '[DEFAULT]' has been created- call Firebase.initializeApp()

I tried all the solutions that are previously present on stackoverflow nothing is working , I am trying from some days but each time i stuck here. please give me a solution for this Thanks

This is my code in flutter .....

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
 import 'firstpage.dart';
 import 'package:firebase_core/firebase_core.dart';

  void main(){
  runApp(MaterialApp(
  home: Homepage(),
  routes: {
  '/home':(context){
    return Homepage();
   },
   '/first':(context){
    return First_Page();
   }
   },
     ));
     }
       class Homepage extends StatefulWidget {
      const Homepage({Key? key}) : super(key: key);

    @override
  _HomepageState createState() => _HomepageState();
   }

 class _HomepageState extends State<Homepage> {
 final _auth= FirebaseAuth.instance;
  final _user=TextEditingController();
   final _pass=TextEditingController();
   String email='';
   String password='';
  @override
  Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(
      backgroundColor: Colors.blue,
      title: Text(
         'Sign-Up',
      ),
      centerTitle: true,
       ),
      body: SingleChildScrollView(
       child: Column(
        children: [
          Padding(
           padding: EdgeInsets.only(top: 250),
          ),
           Container(
           child: TextFormField(
             controller: _user,
             decoration: InputDecoration(
               hintText: "Email-id",
               border: OutlineInputBorder(
                 borderRadius: BorderRadius.circular(10),
               )
             ),
           ),
         ),
        SizedBox(height: 10,),
        Container(
           child: TextFormField(
             controller: _pass,
             decoration: InputDecoration(
               hintText: "Password",
               border: OutlineInputBorder(
                 borderRadius: BorderRadius.circular(10),
               )
             ),
           ),
         ),
        FlatButton(

          color: Colors.blue,
          child: Text('Sign-up'),
          onPressed: () async {

            await Firebase.initializeApp();
            email=_user.toString();
            password=_pass.toString();
          try{
            final newuser= await _auth.createUserWithEmailAndPassword(email: email, password: 
            password);
            if(newuser!=null){
              Navigator.pushNamed(context, '/First_Page');
            }
          }
          catch(e){
            print('error');
          }
          },
        ),
       ],
      ),
      ),
      );
    }
  }

  These following are the dependencies in my pubsppec.yaml
   dependencies:
    flutter:
     sdk: flutter
     firebase_auth: ^3.2.0
      firebase_core :

======== Exception caught by widgets library ======================================================= The following FirebaseException was thrown building Builder: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

Upvotes: 1

Views: 1072

Answers (1)

Ashutosh Patole
Ashutosh Patole

Reputation: 980

1.initialize your firebase before the run app like this

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}
  1. You should not use home: if you are using routes:
void main(){
  runApp(MaterialApp(
  home: Homepage(),     // <== remove this line 
  routes: {
  '/':(context){        // <== change to this
    return Homepage();
   },
   '/first':(context){
    return First_Page();
   }
   },
     ));
     }

Upvotes: 2

Related Questions