# ๐Ÿ“ฑ Mobile App Integration - Setup Guide Panduan lengkap mengintegrasikan API Classification ke aplikasi Flutter Anda. --- ## โœ… File yang Dibuat/Diupdate ### File Baru: 1. **lib/services/classification_service.dart** - Service untuk komunikasi dengan API 2. **MOBILE_SETUP.md** - Guide ini ### File yang Diupdate: 1. **lib/dashboard_klasifikasi.dart** - Integrasi API + error handling 2. **lib/screen/result_screen.dart** - Display hasil API termasuk disease info 3. **pubspec.yaml** - Tambah permission_handler --- ## ๐Ÿ”ง Konfigurasi Server URL **PENTING:** Update URL server sesuai environment Anda! ### File: `lib/services/classification_service.dart` Edit line 7: ```dart static const String _baseUrl = 'http://10.0.2.2:8000/api/classification'; ``` Pilih satu sesuai kebutuhan: | Environment | URL | Keterangan | |---|---|---| | **Emulator Android** | `http://10.0.2.2:8000/api/classification` | Default (Android emulator akses host via 10.0.2.2) | | **Emulator iOS** | `http://127.0.0.1:8000/api/classification` | iOS emulator akses localhost langsung | | **Device Fisik (WiFi)** | `http://192.168.x.x:8000/api/classification` | Ganti x.x dengan IP komputer Anda | | **Testing Lokal** | `http://127.0.0.1:8000/api/classification` | Jika Flutter di desktop | ### Cara Cari IP Komputer Anda: **Windows:** ```bash ipconfig # Cari "IPv4 Address" misalnya: 192.168.1.100 ``` **Mac/Linux:** ```bash ifconfig # Cari "inet" misalnya: 192.168.1.100 ``` --- ## ๐Ÿ“ฆ Install Dependencies Buka terminal di folder `mobile_TA/padi_app/`: ```bash flutter pub get ``` Atau jika menggunakan Android Studio: ``` Tools โ†’ Flutter โ†’ Flutter Pub Get ``` --- ## ๐Ÿš€ Menjalankan Aplikasi ### Terminal 1: Python API Server ```bash cd "d:\PROJECT TA\rice leaf diseases dataset" python api_server.py ``` ### Terminal 2: Laravel Web Server ```bash cd "d:\PROJECT TA\web_TA" php artisan serve ``` ### Terminal 3: Flutter App **Emulator Android:** ```bash cd "d:\PROJECT TA\mobile_TA\padi_app" flutter run ``` **Device Fisik:** ```bash flutter run -d # Dapatkan device_id dengan: flutter devices ``` --- ## ๐ŸŽฏ Fitur yang Sudah Terintegrasi โœ… **Image Picker** - Upload dari galeri - Upload dari kamera - Preview gambar sebelum klasifikasi โœ… **API Integration** - Kirim gambar ke server Laravel - Dapatkan hasil prediksi dengan confidence score - Dapatkan informasi disease (gejala, penanganan, severity) โœ… **Error Handling** - Network error messages - Timeout handling - Validation feedback โœ… **Result Display** - Confidence score dengan progress bar - Severity badge dengan warna - Analisis semua kelas - Detail gejala dan penanganan โœ… **Loading Indicator** - Menunjukkan proses klasifikasi sedang berlangsung --- ## ๐Ÿ“ฑ Screen Flow ``` Home Screen โ†“ [Pilih/ambil foto] โ†“ Dashboard Klasifikasi โ†“ [Klasifikasi Sekarang] โ†“ [Loading...] โ†“ Result Screen โ”œโ”€ Disease Info โ”œโ”€ Confidence Score โ”œโ”€ Severity Level โ”œโ”€ Symptoms โ”œโ”€ Treatment โ”œโ”€ All Predictions โ””โ”€ Product Recommendations ``` --- ## ๐Ÿ”Œ API Endpoints Used Aplikasi menggunakan 2 endpoint: ### 1. Test Connection (Opsional) ``` GET /api/classification/test ``` ### 2. Classify & Save Image ``` POST /api/classification/classify-and-save Body: - image: File - notes: String (optional) Response: { "success": true, "data": { "predicted_class": "Bacterialblight", "confidence": "95.23%", "disease_info": { "name": "...", "symptoms": [...], "treatment": [...] } } } ``` --- ## ๐Ÿงช Testing ### Test dengan Gambar Manual: 1. Buka app 2. Tap tombol upload 3. Pilih/ambil foto daun padi 4. Tap "Klasifikasi Sekarang" 5. Tunggu hasil ### Expected Behavior: - Loading spinner muncul - Setelah 1-2 detik, hasil ditampilkan - Detail penyakit terlihat lengkap - Confidence score di atas 80% untuk prediksi yang baik --- ## โš ๏ธ Troubleshooting ### Error: "Network error - Check your connection" **Solusi:** 1. Pastikan tanto Python API server maupun Laravel server berjalan 2. Update URL di `classification_service.dart` sesuai environment 3. Pastikan device/emulator bisa akses server: ```bash curl http://10.0.2.2:8000/api/classification/test ``` ### Error: "Request timeout" **Solusi:** 1. Cek kecepatan koneksi 2. Model CNN memang butuh 1-2 detik untuk prediksi 3. Pastikan model file (.keras/.h5) ada di server ### Error: "Model API is not loaded" **Solusi:** 1. Lihat output Python API server 2. Pastikan file model ada: `rice_leaf_disease_model.keras` 3. Restart Python API server ### Image tidak bisa dipilih **Solusi:** 1. Check permissions di `AndroidManifest.xml` atau `Info.plist` 2. Pastikan `permission_handler` package installed 3. Grant camera & storage permissions di app --- ## ๐Ÿ“‚ Struktur File ``` lib/ โ”œโ”€โ”€ main.dart # Main app โ”œโ”€โ”€ dashboard_klasifikasi.dart # ๐Ÿ”ฅ Updated - Image picker + API call โ”œโ”€โ”€ screen/ โ”‚ โ”œโ”€โ”€ result_screen.dart # ๐Ÿ”ฅ Updated - Display API results โ”‚ โ”œโ”€โ”€ login.dart โ”‚ โ”œโ”€โ”€ home_screen.dart โ”‚ โ””โ”€โ”€ ... (screens lainnya) โ”œโ”€โ”€ services/ โ”‚ โ””โ”€โ”€ classification_service.dart # โœจ NEW - API service โ””โ”€โ”€ ... (files lainnya) ``` --- ## ๐ŸŽ“ Customization ### 1. Ubah UI Warna Edit di `dashboard_klasifikasi.dart` dan `result_screen.dart`: ```dart backgroundColor: const Color(0xFF0F703A), // Warna hijau ``` ### 2. Ubah Max Upload Size Di server Laravel, edit `ClassificationController.php`: ```php 'image' => 'image|mimes:jpeg,png,jpg|max:10240' // 10MB ``` ### 3. Tambah Loading Spinner Custom Di `dashboard_klasifikasi.dart`, replace: ```dart CircularProgressIndicator(...) ``` dengan spinner pilihan Anda ### 4. Persist Classification History Tambah SharedPreferences untuk menyimpan history: ```dart // Di classification_service.dart final prefs = await SharedPreferences.getInstance(); await prefs.setString('last_classification', jsonEncode(result.toJson())); ``` --- ## ๐Ÿ” Security Notes 1. **API URL jangan hardcode untuk production** - Gunakan env files 2. **Validate image size** sebelum upload - Sudah ada di service 3. **Handle sensitive data** - Jangan log classification results 4. **Use HTTPS** di production - Ubah `http://` ke `https://` --- ## ๐Ÿ“ž Quick Reference ### Common Commands ```bash # Get dependencies flutter pub get # Run app flutter run # Run di device tertentu flutter run -d # List devices flutter devices # Clean build flutter clean flutter pub get ``` ### API Call Example ```dart final service = ClassificationService(); final result = await service.classifyAndSave(imageFile); print(result.diseaseInfo.name); ``` --- ## โœจ Features Added | Feature | Location | Status | |---------|----------|--------| | Image Picker | dashboard_klasifikasi.dart | โœ… | | API Classification | services/classification_service.dart | โœ… | | Error Handling | dashboard_klasifikasi.dart | โœ… | | Loading State | dashboard_klasifikasi.dart | โœ… | | Disease Display | result_screen.dart | โœ… | | Confidence Score | result_screen.dart | โœ… | | Symptoms/Treatment | result_screen.dart | โœ… | | All Predictions | result_screen.dart | โœ… | | History Tracking | Not implemented | โณ | | Offline Mode | Not implemented | โณ | --- ## ๐Ÿš€ Next Steps 1. โœ… Setup Flutter project 2. โœ… Install dependencies 3. โœ… Create ClassificationService 4. โœ… Integrate with HomeScreen 5. **โ†’ Configure server URL for your environment** 6. **โ†’ Run Python API + Laravel servers** 7. **โ†’ Test with real images** 8. **โ†’ Deploy to Play Store / App Store** (future) --- **Status:** โœ… Ready to Use **Last Updated:** March 9, 2026 **Version:** 1.0