Guide for debugging Flutter mobile app build and runtime issues. Use this when asked to fix Flutter build errors, run the app, or troubleshoot connection issues with backend.
CRITICAL: Always run from ecommerce-app/ directory:
cd ecommerce-app
# Ensure Flutter is in PATH
$env:Path += ";C:\src\flutter\bin"
# Get dependencies first
flutter pub get
# Analyze for issues
flutter analyze
# Run on Chrome (web)
flutter run -d chrome --web-port=3000
# Run on Windows desktop
flutter run -d windows
# Run on Android emulator (if set up)
flutter run -d emulator-5554
cd ecommerce-app
# 1. Verify Flutter SDK
flutter --version
# 2. Check available devices
flutter devices
# 3. Verify pubspec.yaml exists
Test-Path "pubspec.yaml"
# 4. Clean build cache (if issues)
flutter clean
flutter pub get
Solution: Add Flutter to PATH
$env:Path += ";C:\src\flutter\bin"
# Or permanently add C:\src\flutter\bin to system PATH
Solutions:
# List emulators
flutter emulators
# Launch emulator
flutter emulators --launch <emulator_id>
cd ecommerce-app
flutter clean
rm pubspec.lock # If exists
flutter pub get
flutter pub upgrade # If conflicts
cd ecommerce-app
flutter clean
flutter pub get
flutter run -d chrome
Check backend is running first:
# In separate terminal
cd ecommerce-backend
make run
Verify API endpoint in Flutter:
lib/core/constants/api_constants.darthttp://localhost:8080/api/v1http://localhost:8080 (not http://127.0.0.1)http://10.0.2.2:8080 (Android) or http://localhost:8080 (iOS)Test backend manually:
curl http://localhost:8080/health
Backend already has CORS configured. If still seeing errors:
internal/api/middleware/cors.go in backendlib/main.dartMultiProvider or ChangeNotifierProvider wraps MaterialAppcontext.read<T>() or context.watch<T>() usage is correctnotifyListeners() is called in Provider after state changescontext.watch<T>() for reactive updates (not context.read<T>())cd ecommerce-app
# Android APK
flutter build apk --release
# Android App Bundle (for Play Store)
flutter build appbundle --release
# iOS (requires macOS)
flutter build ios --release
# Windows desktop
flutter build windows --release
# Web
flutter build web --release
Output locations:
build/app/outputs/flutter-apk/build/windows/runner/Release/build/web/cd ecommerce-app
# Run analyzer
flutter analyze
# Format code
flutter format .
# Run tests
flutter test
# Test with coverage
flutter test --coverage
If hot reload (r) isn't working:
R in terminal)flutter cleanflutter run -d chrome --verbose
flutter pub global activate devtoolspackage:ecommerce_app/... formatname in pubspec.yaml matchesApp uses flutter_secure_storage for tokens.
On Windows: No special setup needed On Android: Handle keystore errors by clearing app data On iOS: Handle keychain access prompts
// Add temporarily to code
final storage = FlutterSecureStorage();
await storage.deleteAll();
If app is slow:
flutter run --releaseflutter run --profileconst widgets)