FilledStacks / flutter-tutorials

The repo contains the source code for all the tutorials on the FilledStacks Youtube channel.
MIT License
4.75k stars 1.76k forks source link

038-firebase-authentication doesn't work since new Firebase versions #113

Closed woohelps closed 3 years ago

woohelps commented 4 years ago

Hi There,

I am new to flutter, your tutorial is very good and helps me a lot. when I follow the 038-firebase-authentication tutorial, I got the below error:

I/flutter (32447): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (32447): The following FirebaseException was thrown building SignUpView: I/flutter (32447): [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

Then I found the answer:https://stackoverflow.com/a/63492262/4339371

I have no idea how to add Firebase.initializeApp() in the get it locator, could you let me know how to update the code for the new version of firebase?

I tried to add Firebase.initializeApp() in my code but doesn't work. Here is my git repo: https://github.com/woohelps/firebase_app/blob/firebase_new_version/README.md

Divyansh1011 commented 4 years ago

hyy dude i also ran into same problem then added this additional code in main.dart file

class MyApp extends StatelessWidget {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _initialization,
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          return MaterialApp(
            title: 'Compound',
            builder: (context, child) => Navigator(
              key: locator<DialogService>().dialogNavigationKey,
              onGenerateRoute: (settings) => MaterialPageRoute(
                  builder: (context) => DialogManager(child: child)),
            ),
            navigatorKey: locator<NavigationService>().navigationKey,
            theme: ThemeData(
              primaryColor: Color.fromARGB(255, 9, 202, 172),
              backgroundColor: Color.fromARGB(255, 26, 27, 30),
              textTheme: Theme.of(context).textTheme.apply(
                    fontFamily: 'Open Sans',
                  ),
            ),
            home: StartUpView(),
            onGenerateRoute: generateRoute,
          );
        }

      },
    );
  }
}
mtruong1999 commented 3 years ago

Another solution (as mentioned in this StackOverflow post) is to only change main in main.dart to the following:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  setupLocator();
  runApp(new myApp());
}

That way, MyApp can be left untouched.

FilledStacks commented 3 years ago

Did the suggestions above solve the problem?

elrapo commented 3 years ago

Did the suggestions above solve the problem?

Yes, it works!