If you're seeing this error in the Flutter app:
Login error: ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 8000
This means the Flutter app cannot connect to the backend server. Here are the solutions:
Start the backend server:
cd /Users/modder/evmaster-workshop/backend
source venv/bin/activate
python main.pyVerify it's running:
curl http://localhost:8000/health
# Should return: {"status":"healthy"}The app now automatically detects your platform and uses the correct URL:
| Platform | URL Used |
|---|---|
| Android Emulator | http://10.0.2.2:8000 |
| iOS Simulator | http://localhost:8000 |
| Physical Device | Need your computer's IP |
If testing on a real phone/tablet, you need your computer's IP address:
Find your computer's IP:
# On macOS/Linux:
ifconfig | grep "inet " | grep -v 127.0.0.1
# On Windows:
ipconfig | findstr "IPv4"Update the config:
Edit /Users/modder/evmaster-workshop/client/lib/config/api_config.dart and replace YOUR_COMPUTER_IP with your actual IP address.
If the automatic detection doesn't work, manually set your computer's IP:
- Find your IP address (e.g.,
192.168.1.100) - Edit
lib/config/api_config.dart:
static String get baseUrl {
if (kDebugMode) {
return 'http://192.168.1.100:8000'; // Use your IP
} else {
return 'https://your-api-domain.com';
}
}Make sure your firewall allows connections on port 8000:
macOS:
sudo pfctl -f /etc/pf.confCheck if port is blocked:
netstat -an | grep 8000If port 8000 is blocked, use a different port:
Backend (main.py):
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080) # Use port 8080Flutter (api_config.dart):
return 'http://10.0.2.2:8080'; // Update portcurl http://localhost:8000/health
curl http://localhost:8000/docs # API documentationcurl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"client_code":"DEMO123"}'The login screen now shows debug info:
- Current API URL being used
- Platform (Android/iOS)
- Suggested demo codes
Make sure your device/emulator has internet access:
# From device/emulator, try:
ping google.comOption 1: Restart Everything
# Terminal 1: Backend
cd backend && source venv/bin/activate && python main.py
# Terminal 2: Flutter
cd client && flutter clean && flutter runOption 2: Use Different Device
# List available devices
flutter devices
# Run on specific device
flutter run -d <device-id>Option 3: Test API Manually
# Test backend is working
curl http://localhost:8000/health
# Test login endpoint
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"client_code":"TEST123"}'You'll know it's working when:
- ✅
curl http://localhost:8000/healthreturns{"status":"healthy"} - ✅ Login screen shows correct API URL in debug info
- ✅ No "Connection refused" errors in Flutter logs
- ✅ Login with "DEMO123" successfully enters the app
- ✅ Uses
http://10.0.2.2:8000automatically - ✅ Should work out of the box
- ✅ Uses
http://localhost:8000automatically - ✅ Should work out of the box
⚠️ Requires your computer's IP address⚠️ Device and computer must be on same WiFi network⚠️ Firewall must allow connections on port 8000
- Check the Flutter logs for specific error messages
- Verify backend logs show incoming requests
- Try different devices (emulator vs physical)
- Check network connectivity between device and computer
- Restart both backend and Flutter app
The connection should work seamlessly once the backend is running and the correct URL is configured! 🚗✨