3.9 KiB
🔧 FIX: "Koneksi Gagal" di Mobile App
🎯 Masalah
Aplikasi Flutter menampilkan error: "Koneksi gagal, periksa internet Anda"
✅ Solusi Sudah Diterapkan
File app_config.dart sudah diupdate dengan IP komputer Anda: 10.130.244.240
📱 LANGKAH-LANGKAH FIX
1️⃣ Pastikan Device & Komputer di WiFi yang Sama
PENTING! HP dan komputer harus terhubung ke WiFi yang sama.
Cek WiFi:
- Komputer: Lihat icon WiFi di taskbar
- HP: Settings → WiFi → lihat nama network
2️⃣ Test Koneksi dari HP
A. Buka Browser di HP, akses:
http://10.130.244.240/TugasAkhir/test_mobile_api.html
B. Klik tombol:
- "Test Koneksi Server" → harus muncul ✅ KONEKSI BERHASIL
- "Test Login API" → harus muncul ✅ LOGIN BERHASIL
Jika halaman tidak bisa dibuka: → Lanjut ke Step 3 (Windows Firewall)
3️⃣ Fix Windows Firewall
Windows Firewall mungkin memblokir koneksi dari HP.
Cara 1: Izinkan Apache (Recommended)
- Buka Command Prompt as Administrator
- Jalankan:
netsh advfirewall firewall add rule name="Apache HTTP" dir=in action=allow protocol=TCP localport=80
netsh advfirewall firewall add rule name="Apache HTTPS" dir=in action=allow protocol=TCP localport=443
Cara 2: Matikan Firewall Sementara (untuk testing)
- Windows Settings → Update & Security → Windows Security
- Firewall & network protection
- Private network → Turn off (HANYA untuk testing!)
- Setelah berhasil, nyalakan lagi dan gunakan Cara 1
4️⃣ Restart Flutter App
Setelah test koneksi berhasil:
cd c:\xampp\htdocs\TugasAkhir\sim_mobile
flutter clean
flutter run
PENTING: Harus Hot Restart (bukan hot reload!)
- VS Code: Klik icon 🔄
- Android Studio: Klik lightning bolt hijau
5️⃣ Test Login
Gunakan credentials:
- Username:
Aydin Fauzan - Password:
s002
🐛 Troubleshooting
Error: "Halaman test_mobile_api.html tidak bisa dibuka"
Penyebab: Firewall atau WiFi berbeda
Solusi:
-
Ping dari HP ke komputer:
- Install app "Network Utilities" atau "Fing"
- Ping ke: 10.130.244.240
- Jika timeout → WiFi berbeda atau Firewall
-
Cek XAMPP Apache:
- Buka XAMPP Control Panel
- Pastikan Apache running (hijau)
Error: "Test koneksi berhasil, tapi login gagal"
Penyebab: API atau database bermasalah
Solusi: Test dari komputer dulu:
$body = '{"id_santri":"Aydin Fauzan","password":"s002"}'
Invoke-RestMethod -Uri "http://localhost/TugasAkhir/sim-pkpps/public/api/v1/login" -Method POST -ContentType "application/json" -Body $body
Jika ini gagal:
- Cek routes:
php artisan route:list --name=login - Cek database connection
- Cek Laravel log:
sim-pkpps/storage/logs/laravel.log
Error: "Flutter masih error 'koneksi gagal'"
Penyebab: Config tidak ter-reload
Solusi:
- Stop Flutter app (Shift+F5)
- Jalankan:
flutter clean flutter pub get flutter run - Atau uninstall app dari HP, install ulang
🔍 Cek IP Komputer Berubah
Jika IP komputer berubah (setelah restart/ganti WiFi):
-
Cek IP baru:
ipconfig | findstr IPv4 -
Update
app_config.dart:static const String baseUrl = 'http://[IP_BARU]/TugasAkhir/sim-pkpps/public/api/v1'; -
Hot restart Flutter
✅ Checklist Final
- HP dan komputer di WiFi yang sama
- XAMPP Apache running
- Firewall rule untuk Apache sudah dibuat
- Test koneksi dari HP berhasil (test_mobile_api.html)
- Flutter app sudah hot restart
- Login dengan username & password yang benar
📞 Masih Error?
Kirim screenshot:
- Error di Flutter (terminal log)
- Hasil test dari test_mobile_api.html
- XAMPP Control Panel (Apache status)
- WiFi settings (HP dan komputer)
IP Komputer Anda: 10.130.244.240 Test Page: http://10.130.244.240/TugasAkhir/test_mobile_api.html