flutter pub add flutterfire_ui
flutter pub add firebase_core
flutter pub add firebase_auth
flutter pub add go_router
minSDK버전은 21로 맞춘다.
Flutter 프로젝트 디렉터리에서 다음 명령을 실행하여 앱 구성 워크플로를 시작합니다.
flutterfire configure
Firebase에서 사용할 프로젝트를 선택하고, 안드로이드인지 ios인지 선택한다. 다 되면 아래와 같은 화면이 나온다.
class AuthGate extends StatelessWidget {
const AuthGate({Key? key}) : super(key: key);
Widget build(BuildContext context) {
return StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SignInScreen(
providerConfigs: [
EmailProviderConfiguration(),
]
);
}
// Render your application if authenticated
return const MainScreen();
},
);
}
}
Firebase console에 들어가서 보면 아래와 같이 들어가 있음을 알 수 있다.