This guide covers deploying both the Flutter web app and Python API to Vercel.
┌─────────────────────────────────────────────────────────┐
│ Vercel Deployment │
├─────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Flutter Web App │ │ Python API │ │
│ │ (Static Build) │◄─────►│ (Serverless) │ │
│ │ │ │ │ │
│ │ / │ │ /api/analyze │ │
│ │ /index.html │ │ │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
└─────────────────────────────────────────────────────────┘
npm install -g vercelvercel.jsonOthernpm run build (from package.json)build/webhttps://your-project.vercel.app# Install Vercel CLI
npm install -g vercel
# Login to Vercel
vercel login
# Deploy to production
vercel --prod
# Navigate to project root
cd /Users/alizia/dev/uvsn_flutter/uvsn_image_analyzer
# Create Python virtual environment
python3 -m venv api/venv
source api/venv/bin/activate # On Windows: api\venv\Scripts\activate
# Install Python dependencies
pip install -r api/requirements.txt
# Run the API server
cd api
uvicorn analyze:app --reload --port 3000
# Test the API
python test_local.py
The API will be available at http://localhost:3000
# In a new terminal, navigate to project root
cd /Users/alizia/dev/uvsn_flutter/uvsn_image_analyzer
# Run Flutter web
flutter run -d chrome
# Or build for production
flutter build web
# Start the API server
cd api
uvicorn analyze:app --reload --port 3000
# In another terminal, run tests
python test_local.py path/to/test/image.jpg
# Build the Flutter web app
flutter build web
# Serve it locally
cd build/web
python3 -m http.server 8080
# Open http://localhost:8080 in your browser
vercel.json is properly configuredapi/requirements.txt includes all dependenciespackage.json has correct build scriptYour vercel.json should look like this:
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@vercel/static-build",
"config": {
"distDir": "build/web"
}
},
{
"src": "api/analyze.py",
"use": "@vercel/python"
}
],
"rewrites": [
{
"source": "/api/(.*)",
"destination": "/api/$1"
},
{
"source": "/(.*)",
"destination": "/index.html"
}
]
}
If you need to configure the API URL for different environments:
API_URL = /api (for production)The app automatically uses:
/api (relative path, same domain)http://localhost:3000/apivercel logs
api/requirements.txtcurl https://your-project.vercel.app/api/
lib/services/python_image_service.dart# Clear build cache
flutter clean
flutter pub get
flutter build web
api/requirements.txt for syntax errorsrawpy is installedEnable analytics in your Vercel dashboard to monitor:
# View real-time logs
vercel logs --follow
# View logs for specific deployment
vercel logs [deployment-url]
Currently, the app supports both Flutter and Python processing: