I am trying to create a SignIn page with Firebase authentication, but this error is happening in main.dart when I run the code:
This is the code: from main.dart:
import 'package:app_mypocket/services/auth_service.dart';
import 'package:app_mypocket/telas/home/homepage.dart';
import 'package:app_mypocket/telas/login/telalogin.dart';
[import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Pocket',
debugShowCheckedModeBanner: false,
theme: ThemeData(
),
home: HomePage(),
//routes: routes,
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) => Scaffold(
body: StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (snapshot.hasData){
return HomePage();
} else{
return TelaLogin();
}
})
);
}
My pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
intl:
provider: ^6.0.4
shared_preferences: ^2.0.6
hive: ^2.0.4
hive_flutter: ^1.1.0
path_provider: ^2.0.2
sqflite: ^2.0.0 3
fl_chart: ^0.55.2
firebase_core: ^2.1.1
firebase_auth: ^4.1.0
cloud_firestore: ^4.0.3
Also, I have created a user manually in my project on the firebase website, so I am trying to logIn.
CodePudding user response:
When logging into Firebase you normally provide options, like:
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// Initialize Firebase
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
These firebase_options are generated by running "flutterfire configure" (previously firebase configure iirc).
I think you forget this specific step. See the guide: https://firebase.google.com/docs/flutter/setup?platform=ios
The configuration file contains information about the apiKey, appId, projectId, bundle/app name and much more. Not providing it, will lead to a default/blank/unusable app.