flutter는 다트 기반 모든 틀에 맞게 개발하고 배포할 수 있는 장점이 있는 프레임워크이다.

firebase는 쉽게 서버의 기능을 이용할 수 있게 해준다. 제한이 있고 넘어가면 과금

둘 다 구글에서 지원하고 있다.

firebase에서 다양한 기능을 flutter에서 사용하려면 flutterfire_core라는 플러그인이 필요하다.

firebase console에서 그 기능을 사용할 수도 있지만 코드와 연결 시키려면 cli를 통해 설치 및 설정이 필요하다.

https://firebase.google.com/docs/cli#install_the_firebase_cli 이 곳에서 운영체제에 맞게 설치를 할 수 있다.

mac 사용자이면서 node를 지금은 사용하지 않았기 때문에 curl로 아래와 같이 설치해 주었다.

curl -sL <https://firebase.tools> | bash

설치가 끝나면 permission과 프로젝트 선택 때문에 로그인이 필요하다.

firebase login

다른 앱에서 사용하려면 firebase init을 사용하면 되지만 flutter에서 사용할 것이기 때문에 다른 방법으로 init을 한다.

https://firebase.flutter.dev/docs/overview 이 사이트는 flutterfire를 다룬다.

위의 firebase 설치 과정이 없으면 flutterfire를 해도 계속 에러가 날 수 있다.

새로운 플러터 프로젝트를 만들고 (이미 있다면 migration해야하므로 https://firebase.flutter.dev/docs/migration 이 곳을 참고 하는 것이 좋다.) 터미널에 아래처럼 flutterfire및 파이어베이스 코어를 설치하고 설정한다.

flutter pub add firebase_core

dart pub global activate flutterfire_cli

flutterfire configure

오류 없이 설치가 되었다면 패키지를 불러오기 및 firebase를 앱에 init해 준다.

import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(MyApp());
}

flutter와 연결은 끝!

+ Recent posts