Flutter App Troubleshooting
Running the Flutter App
CRITICAL: Always run from ecommerce-app/ directory:
powershell
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
Pre-flight Checks
powershell
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
Common Flutter Issues
"flutter: command not found" or "flutter not recognized"
Solution: Add Flutter to PATH
powershell
$env:Path += ";C:\src\flutter\bin" # Or permanently add C:\src\flutter\bin to system PATH
"No devices found"
Solutions:
- •For Web: Ensure Chrome is installed
- •For Windows: Enable Developer Mode in Windows Settings
- •For Android: Start an emulator first
powershell
# List emulators flutter emulators # Launch emulator flutter emulators --launch <emulator_id>
"pub get failed" or dependency errors
powershell
cd ecommerce-app flutter clean rm pubspec.lock # If exists flutter pub get flutter pub upgrade # If conflicts
Build errors after code changes
powershell
cd ecommerce-app flutter clean flutter pub get flutter run -d chrome
API Connection Issues
Cannot connect to backend (http://localhost:8080)
Check backend is running first:
powershell
# In separate terminal cd ecommerce-backend make run
Verify API endpoint in Flutter:
- •File:
lib/core/constants/api_constants.dart - •Should be:
http://localhost:8080/api/v1 - •For web: Use
http://localhost:8080(nothttp://127.0.0.1) - •For mobile emulator: Use
http://10.0.2.2:8080(Android) orhttp://localhost:8080(iOS)
Test backend manually:
powershell
curl http://localhost:8080/health
CORS errors in web browser
Backend already has CORS configured. If still seeing errors:
- •Check
internal/api/middleware/cors.goin backend - •Ensure backend is running
- •Clear browser cache
State Management Issues (Provider)
"Provider not found" errors
- •Ensure Provider is initialized in
lib/main.dart - •Check if
MultiProviderorChangeNotifierProviderwrapsMaterialApp - •Verify
context.read<T>()orcontext.watch<T>()usage is correct
State not updating
- •Check if
notifyListeners()is called in Provider after state changes - •Verify using
context.watch<T>()for reactive updates (notcontext.read<T>())
Build and Deployment
Building for production
powershell
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:
- •Android:
build/app/outputs/flutter-apk/ - •Windows:
build/windows/runner/Release/ - •Web:
build/web/
Analyzing Code Quality
powershell
cd ecommerce-app # Run analyzer flutter analyze # Format code flutter format . # Run tests flutter test # Test with coverage flutter test --coverage
Hot Reload Issues
If hot reload (r) isn't working:
- •Try hot restart (
Rin terminal) - •Stop app and run again
- •Clear build cache:
flutter clean
Debugging Tips
Enable verbose logging
powershell
flutter run -d chrome --verbose
Inspect widget tree
- •Use Flutter DevTools
- •Run app, then:
flutter pub global activate devtools - •Access at printed URL
Common import errors
- •Ensure all imports use
package:ecommerce_app/...format - •Check
nameinpubspec.yamlmatches - •Verify file paths are correct
Secure Storage Issues
App 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
Clear secure storage for testing
dart
// Add temporarily to code final storage = FlutterSecureStorage(); await storage.deleteAll();
Performance Optimization
If app is slow:
- •Run in release mode:
flutter run --release - •Profile mode:
flutter run --profile - •Check for unnecessary rebuilds (use
constwidgets) - •Optimize image sizes and assets