플러터:Firebase
둘러보기로 이동
검색으로 이동
개요[편집 | 원본 편집]
FireBase에서 데이터베이스와 스토리지 서비스를 시작한다.(스토리지는 요금제 내는 서비스로 바꾸어야 진행 가능)
중간에 서비스를 바꾸게 되면.. 얼마나 복잡할지.......
룰 설정[편집 | 원본 편집]
Strage를 처음 만들면 아무도 사용할 수 없는 상태이기에 룰 변경이 필요하다.
| 항목 | 설정 |
|---|---|
| 스토리지 룰 설정 | rules_version = '2';
// Craft rules based on data in your Firestore database
// allow write: if firestore.get(
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write:
if request.auth != null; // 로그인을 한 유저가 읽고 쓰기가 가능함을 지정.
}
}
}
|
| 데이터베이스 룰 설정 | rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write:
if request.auth != null;
}
}
}
|
플러터와 연결[편집 | 원본 편집]
| 항목 | 설정 | 비고 |
|---|---|---|
| Git은 있겠지. | ||
| Node.js |
|
|
| 환경변수 추가 | 터미널에서 $env:Path += ";$env:LOCALAPPDATA\Pub\Cache\bin" 로 간단히 추가할 수 있다.
|
환경변수를 적용하게끔 IDE를 재시작. |
| 연결 | IDE의 터미널에서
|
브라우저가 열리면 로그인. |
| 파이어베이스 설정 |
|
|
| 관련 패키지 설치 |
|
|
| 사용(플러터에서 연결) | import 'package:firebase_core/firebase_core.dart';
void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); } |