flutter로 프로젝트를 만들 때, 거의 필수적으로 파이어베이스에 프로젝트를 만들어 플러터 프로젝트에 연동시키는 작업을 하게 됩니다. 이럴 때, 명령어 하나로 연동이 가능한데 이 방법에 대해 알아보겠습니다.
flutter 프로젝트를 생성한다.
안드로이드 스튜디오에서 메뉴에서 new flutter project를 선택해도 되고,
터미널에서 flutter create “your_project_name” –org “com.yourdomain” command 로 프로젝트를 생성해도 됩니. –org “com.yourdomain”은 미리 bundle id와 package name 앞부분에 쓰이고 your_project_name은 뒷부분에 쓰이기 때문에 중요합니다.
예를들어, flutter create bundleidtest –org “com.domain 로 지정하면 com.domain.bundleidtest 가 됩니다.
firebase_core 펍 추가
flutter pub add firebase_core
(flutterfire cli가 설치 되어 있는경우) 터미널에서 명령어 입력
아래 명령어를 터미널에 입력하고 가이드를 보고 선택하거나 엔터를 몇번 치면 파이버에이스와 플러터 프로젝트 연동이 끝납니다. flutterfire cli가 설치 되어 있지 않은 경우 맨 아래 링크에 있는 가이드 문서를 통해 설치할 수 있습니다.
flutterfire configure
main.dart 에 main을 아래와 같이 설정
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
flutterfire cli가 설치 방법
아래 링크를 통해 설치할 수 있습니다.
맥의 경우, 아래 명령어를 터미널에 치면 설치가 됩니다.
curl -sL https://firebase.tools | bash
그리고 아래의 명령어를 통해 활성화 시킵니다.
dart pub global activate flutterfire_cli
아래 문서를 참고하기 바랍니다.