10 - Debugging Guide

Tools, techniques, and checklists for diagnosing issues in the Flutter frontend.

Flutter DevTools

DevTools is Flutter's built-in debugger / profiler / inspector. It launches automatically when you run flutter run.

BashLaunch DevTools
# Start the app
C:\flutter\bin\flutter run -d chrome --web-port 8080

# Look for this line in the console:
# A Dart VM Service ... is available at: http://127.0.0.1:xxxxx
# Flutter DevTools debugger and profiler is available at: http://127.0.0.1:9100

# Open the DevTools URL in your browser

What you get in DevTools

Breakpoints in VS Code

VS Code with the Flutter extension is the recommended IDE.

  1. Open the Flutter app folder in VS Code
  2. Click the left gutter next to a line number to set a breakpoint (red dot appears)
  3. Press F5 to start debugging (or click "Run and Debug")
  4. Select a device (Chrome, Android emulator, etc.)
  5. When the breakpoint is hit, use F10 (step over), F11 (step into), F5 (continue)
Recommended breakpoints

Set breakpoints in ApiService._post and ApiService._get to inspect every network call in one place. Set one in Stage0ArrivalScreen._initJourney to trace session startup.

debugPrint and print

Use debugPrint instead of print in Flutter code - it's rate-limited and works better on web.

DartLogging patterns
import 'package:flutter/foundation.dart';

debugPrint('Registration: mobile=$mobile, name=$name');
debugPrint('API response: success=${result.success}, data=${result.data}');

// For large objects, use debugPrint with JSON encoding
debugPrint('Full response: ${jsonEncode(result.data)}');

All debug logs show up in your terminal (flutter run) or VS Code Debug Console.

Network Inspection

Web (Chrome)

  1. Press F12 to open Chrome DevTools
  2. Go to the Network tab
  3. Filter by "XHR" or "Fetch" to see just API calls
  4. Click any request to inspect headers, payload, response, timing
CORS errors

If you see a CORS error in the Network tab, check backend/src/MO.Ekyc.Api/appsettings.jsonCors.AllowedOrigins. It must include your Flutter web origin (e.g., http://localhost:8080).

Android / iOS

Use Charles Proxy or Proxyman with a self-signed CA installed on the device/emulator. Flutter DevTools Network tab also shows HTTP traffic for mobile.

Inspecting Storage (SharedPreferences)

The StorageService wraps SharedPreferences. To see what's stored:

DartDump storage contents
final storage = await StorageService.getInstance();
debugPrint('leadId:       ${storage.leadId}');
debugPrint('sessionId:    ${storage.sessionId}');
debugPrint('token:        ${storage.token}');
debugPrint('currentStage: ${storage.currentStage}');
debugPrint('lastActivity: ${storage.lastActivity}');

To clear storage and start fresh (useful when testing resume logic):

DartClear all storage
await (await StorageService.getInstance()).clearAll();
// Now restart the app - it will go through Stage 0 fresh

Web - Application tab

In Chrome DevTools, go to Application → Storage → Local Storage. SharedPreferences on web maps to localStorage. You can see and delete keys directly.

Common Issues Checklists

"White screen on startup"

"Stuck at Stage 0 loading spinner"

"API always returns 401"

"OTP 1234 is rejected"

"Lottie animation doesn't play"

"Navigation back button takes me out of the app"

"Mock URL opens real WebView in dev"

"Session timed out immediately"

Backend-side debugging

When the backend is the problem, inspect it via Swagger and Hangfire.

URLPurpose
http://localhost:5000/swaggerInteractive API explorer. Test endpoints without the Flutter app.
http://localhost:5000/hangfireBackground job dashboard. See queued, running, completed, failed jobs (analytics events, downstream publishers).
Backend logs and config