This is my flutter code
import 'package:flutter/material.dart';
import 'firebase_options.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'login.dart';
import 'home.dart';
Future main() async{
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
const MainApp({Key? key}) : super(key: key);
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
String ime='';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot){
if (snapshot.hasData){
return const HomePage();
} else{
return const LoginPage();
}
},
)
),
);
}
}
the error from the code usually appears if you don’t have Firebase.initializeApp(), but i have it
i have also have firebase_core in my pubspec yaml
i have tried making the code only check if the user has an account after initializing using FutureBuilder
i have used this type of code a thousand times and only now does it show this bug
i have even watched begginer tutorials to see if i missed something, but everything seems in orded
bulga is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.