219 lines
6.2 KiB
Markdown
219 lines
6.2 KiB
Markdown
# Firebase Setup Guide for Debartis Fire Detection
|
|
|
|
## Langkah-langkah Setup Firebase
|
|
|
|
### 1. Buat Project Firebase
|
|
1. Buka [Firebase Console](https://console.firebase.google.com/)
|
|
2. Klik "Add project" atau "Tambah project"
|
|
3. Masukkan nama project: `debartis-fire-detection`
|
|
4. Ikuti langkah-langkah setup hingga selesai
|
|
|
|
### 2. Enable Authentication
|
|
1. Di Firebase Console, pilih project `debartis-fire-detection`
|
|
2. Pilih "Authentication" di sidebar
|
|
3. Pilih tab "Sign-in method"
|
|
4. Enable "Email/Password" authentication
|
|
5. Klik "Save"
|
|
|
|
### 3. Setup Firestore Database
|
|
1. Pilih "Firestore Database" di sidebar
|
|
2. Klik "Create database"
|
|
3. Pilih "Start in test mode" (untuk development)
|
|
4. Pilih lokasi server (pilih yang paling dekat dengan lokasi Anda)
|
|
5. Klik "Done"
|
|
|
|
### 4. Setup Storage
|
|
1. Pilih "Storage" di sidebar
|
|
2. Klik "Get started"
|
|
3. Gunakan default rules untuk sekarang
|
|
4. Pilih lokasi yang sama dengan Firestore
|
|
5. Klik "Done"
|
|
|
|
### 5. Add Flutter App ke Firebase Project
|
|
1. Di Firebase Console, klik ikon Flutter (atau Add app > Flutter)
|
|
2. Masukkan informasi berikut:
|
|
- **Apple bundle ID**: `com.example.debartis`
|
|
- **Android package name**: `com.example.debartis`
|
|
- **App nickname**: `Debartis Fire Detection`
|
|
|
|
### 6. Download Configuration Files
|
|
1. Download `google-services.json` untuk Android
|
|
2. Download `GoogleService-Info.plist` untuk iOS
|
|
3. Tempatkan file tersebut di lokasi yang sesuai:
|
|
- Android: `android/app/google-services.json`
|
|
- iOS: `ios/Runner/GoogleService-Info.plist`
|
|
|
|
### 7. Update firebase_options.dart
|
|
1. Buka file `lib/firebase_options.dart`
|
|
2. Ganti semua placeholder dengan konfigurasi yang benar dari Firebase Console
|
|
3. Untuk mendapatkan konfigurasi:
|
|
- Buka Project Settings di Firebase Console
|
|
- Scroll ke bawah ke "Your apps"
|
|
- Pilih platform yang ingin dikonfigurasi
|
|
- Copy konfigurasi yang diperlukan
|
|
|
|
### 8. Konfigurasi Android (android/app/build.gradle)
|
|
Tambahkan di bagian bawah file:
|
|
```gradle
|
|
apply plugin: 'com.google.gms.google-services'
|
|
```
|
|
|
|
### 9. Konfigurasi Android (android/build.gradle)
|
|
Tambahkan di dependencies:
|
|
```gradle
|
|
dependencies {
|
|
classpath 'com.google.gms:google-services:4.3.15'
|
|
}
|
|
```
|
|
|
|
### 10. Konfigurasi iOS (ios/Runner/Info.plist)
|
|
Tambahkan konfigurasi URL scheme jika diperlukan.
|
|
|
|
### 11. Test Setup
|
|
1. Jalankan `flutter clean`
|
|
2. Jalankan `flutter pub get`
|
|
3. Jalankan `flutter run`
|
|
4. Coba register user baru
|
|
5. Cek Firebase Console untuk memastikan user terdaftar
|
|
|
|
## Database Structure
|
|
|
|
### Collections yang digunakan:
|
|
|
|
#### 1. users
|
|
- uid (document ID)
|
|
- email: string
|
|
- displayName: string
|
|
- photoURL: string
|
|
- role: string (default: "user")
|
|
- isActive: boolean
|
|
- createdAt: timestamp
|
|
- updatedAt: timestamp
|
|
|
|
#### 2. detections
|
|
- userId: string
|
|
- timestamp: timestamp
|
|
- location: string
|
|
- confidence: number (0.0 - 1.0)
|
|
- imageUrl: string
|
|
- status: string (detected, confirmed, false_alarm, resolved)
|
|
- severity: string (low, medium, high, critical)
|
|
- description: string
|
|
- resolved: boolean
|
|
- createdAt: timestamp
|
|
|
|
#### 3. alerts
|
|
- userId: string
|
|
- detectionId: string
|
|
- title: string
|
|
- message: string
|
|
- severity: string
|
|
- location: string
|
|
- timestamp: timestamp
|
|
- isRead: boolean
|
|
- isResolved: boolean
|
|
- createdAt: timestamp
|
|
|
|
#### 4. devices
|
|
- userId: string
|
|
- deviceName: string
|
|
- deviceType: string
|
|
- location: string
|
|
- status: string
|
|
- lastSeen: timestamp
|
|
- createdAt: timestamp
|
|
|
|
## Security Rules
|
|
|
|
### Firestore Rules
|
|
```javascript
|
|
rules_version = '2';
|
|
service cloud.firestore {
|
|
match /databases/{database}/documents {
|
|
// Users can only access their own data
|
|
match /users/{userId} {
|
|
allow read, write: if request.auth != null && request.auth.uid == userId;
|
|
}
|
|
|
|
// Detections - users can only access their own detections
|
|
match /detections/{detectionId} {
|
|
allow read, write: if request.auth != null && request.auth.uid == resource.data.userId;
|
|
}
|
|
|
|
// Alerts - users can only access their own alerts
|
|
match /alerts/{alertId} {
|
|
allow read, write: if request.auth != null && request.auth.uid == resource.data.userId;
|
|
}
|
|
|
|
// Devices - users can only access their own devices
|
|
match /devices/{deviceId} {
|
|
allow read, write: if request.auth != null && request.auth.uid == resource.data.userId;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Storage Rules
|
|
```javascript
|
|
rules_version = '2';
|
|
service firebase.storage {
|
|
match /b/{bucket}/o {
|
|
match /users/{userId}/{allPaths=**} {
|
|
allow read, write: if request.auth != null && request.auth.uid == userId;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Environment Variables (Opsional)
|
|
Untuk keamanan tambahan, Anda bisa menggunakan environment variables untuk API keys.
|
|
|
|
## Troubleshooting
|
|
- Jika error "Firebase project not found", pastikan project ID benar
|
|
- Jika error authentication, cek apakah Email/Password sudah dienable
|
|
- Jika error Firestore, cek rules dan pastikan database sudah dibuat
|
|
- Jika error di build, pastikan google-services.json sudah di tempatkan dengan benar
|
|
|
|
### Windows Build Issues
|
|
Firebase SDK untuk Windows masih dalam tahap pengembangan dan sering mengalami masalah:
|
|
|
|
1. **Disk Space Error**:
|
|
- Pastikan ada space disk yang cukup (minimal 5GB free)
|
|
- Hapus folder `build` dan jalankan `flutter clean`
|
|
|
|
2. **Linking Errors** (LNK2019, LNK1120):
|
|
- Firebase Windows SDK memiliki compatibility issues
|
|
- **Solusi**: Gunakan platform lain untuk development:
|
|
```bash
|
|
# Untuk Android
|
|
flutter run -d android
|
|
|
|
# Untuk Web
|
|
flutter run -d chrome
|
|
|
|
# Untuk testing di emulator
|
|
flutter emulators --launch <emulator_name>
|
|
```
|
|
|
|
3. **CMake Deprecation Warnings**:
|
|
- Ini hanya warning dan tidak mempengaruhi functionality
|
|
- Akan diperbaiki di versi Firebase SDK selanjutnya
|
|
|
|
4. **Alternative untuk Windows Development**:
|
|
- Gunakan Firebase Web SDK melalui browser
|
|
- Develop dan test di Android emulator
|
|
- Deploy ke Android device untuk testing
|
|
|
|
### Recommended Development Flow:
|
|
1. **Primary Development**: Android (emulator atau device)
|
|
2. **Testing**: Web browser (Chrome)
|
|
3. **Production**: Android APK build
|
|
4. **Windows**: Tunggu Firebase SDK update atau gunakan alternatif
|
|
|
|
## Next Steps
|
|
1. Buat halaman register
|
|
2. Buat halaman home/dashboard
|
|
3. Implementasi real-time fire detection
|
|
4. Implementasi push notifications
|
|
5. Implementasi file upload untuk images
|