1

iam using flutter upgraded version and the app builds fine before writing the code to get data from firebase but after this when i run my app only white scree appears on my mobile here is my main.dart code

import 'package:flutter/material.dart';
import 'package:mints/home.dart';
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MaterialApp(
    home:Home(),
  ));
}

home.dart code

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:async';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:firebase_core/firebase_core.dart';



class Home extends StatefulWidget {
  @override
  _HomeState createState() => new _HomeState();
}

class _HomeState extends State<Home> {

  StreamSubscription<QuerySnapshot>subscription;

  List<DocumentSnapshot>snapshot;

  CollectionReference collectionReference = FirebaseFirestore.instance.collection("mints");

  @override
  void initState() {
    subscription = collectionReference.snapshots().listen((datasnap) { 
      setState(() {
        snapshot = datasnap.docs;
      });
    });
    super.initState();
     
  }
  Widget build (BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text("Mints"),
        backgroundColor: Colors.teal[200],
      ),

      drawer: Drawer(
        child:Container(
            color: Colors.teal[200],
            child: ListView(
            children:<Widget>[
              UserAccountsDrawerHeader(
                accountName: Text("CONTACT US AT"), 
                accountEmail: Text("mintslpu@gmail.com"),
                decoration: BoxDecoration(color: Colors.black),
                )
            ]
          ),
        ),
      ),

      body: Padding(
        padding: EdgeInsets.only(top: 30.0),
        child: Swiper(
          itemBuilder: (BuildContext context, int index) {
            return InkWell(
                child: Stack(
                  children: <Widget>[
                    Padding(
                      padding: EdgeInsets.all(10.0),
                      child: ClipRRect(
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(35.0),
                          topRight: Radius.circular(35.0),
                        ),
                        child: Image.network(
                          snapshot[index].data()['image'] ,
                          fit: BoxFit.cover,
                          height: 400.0,
                        ),
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.fromLTRB(0.0, 350.0, 0.0, 0.0),
                      child: Container(
                        height: 200.0,
                        width: 400.0,
                        child: Material(
                          borderRadius: BorderRadius.circular(35.0),
                          elevation: 10.0,
                          child: Column(
                            children:<Widget>[
                              Padding(
                                padding: EdgeInsets.fromLTRB(20.0, 20.0, 10.0, 20.0),
                                child: Text(
                                  snapshot[index].data()['title'] ,
                                  style: TextStyle(
                                    fontSize: 25.0,
                                    fontWeight: FontWeight.bold,
                                  ),
                                ),
                              )
                            ]
                          ),
                        ),
                      ),
                    )
                  ],
                ),
            );
          },
          itemCount: snapshot == null ? 0 : snapshot.length, autoplay: true,viewportFraction: 0.8,
                scale: 0.9,
        ),
      )
    );
  }
}

when i run the app and after it it is built this is being displayed in the vs code terminal

E/flutter (32259): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project?
E/flutter (32259):     
E/flutter (32259):     View the Android Installation documentation for more information: https://firebaseextended.github.io/flutterfire/docs/installation/android
E/flutter (32259):
E/flutter (32259): #0      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:86:9)
E/flutter (32259): <asynchronous suspension>
E/flutter (32259): #1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:25)
E/flutter (32259): #2      main (package:mints/main.dart:8:18)
E/flutter (32259): #3      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:231:25)
E/flutter (32259): #4      _rootRun (dart:async/zone.dart:1190:13)
E/flutter (32259): #5      _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (32259): #6      _runZoned (dart:async/zone.dart:1630:10)
E/flutter (32259): #7      runZonedGuarded (dart:async/zone.dart:1618:12)
E/flutter (32259): #8      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:223:5)
E/flutter (32259): #9      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
E/flutter (32259): #10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (32259):

Thanks in Advance

4 Answers4

2
E/flutter (32259): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project?

check this file is added in your project or not,

"google-services.json"

enter image description here

Shirsh Shukla
  • 5,491
  • 3
  • 31
  • 44
1

Did you put google-services.json generated by firebase in android's app level directory?

John Joe
  • 12,412
  • 16
  • 70
  • 135
Rohit Soni
  • 1,300
  • 6
  • 12
1

I had a white screen too because of Firebase.initializeApp(); and i did fix it by commands :

run

flutter pub upgrade firebase_core

then run

dart pub global activate flutterfire_cli

then run

flutterfire configure
Zakaria Ferzazi
  • 364
  • 3
  • 4
0

replace the main method with the following code:

Future<void> main() async {    
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,);
  runApp(const MyApp());
}