Files
deflock-app/V1.8.2_SHEET_POSITIONING_FIX.md

7.1 KiB

v1.8.2 Sheet Positioning Fix

Problem Identified

The node tags sheet and suspected location sheet were not properly adjusting the map positioning to keep the visual center in the middle of the viewable area above the sheet, unlike the working add/edit node sheets.

Root Cause Analysis

Upon investigation, the infrastructure was already in place and should have been working:

  1. Both sheets use MeasuredSheet wrapper to track height
  2. Both sheets call SheetCoordinator.updateTagSheetHeight()
  3. SheetCoordinator.activeSheetHeight includes tag sheet height as the lowest priority
  4. SheetAwareMap receives this height and positions the map accordingly

However, a race condition was discovered in the sheet transition logic when moving from tag sheet to edit sheet:

The Race Condition

  1. User taps "Edit" in NodeTagSheet
  2. appState.startEditSession(node) is called
  3. Auto-show logic calls _openEditNodeSheet()
  4. _openEditNodeSheet() calls Navigator.of(context).pop() to close the tag sheet
  5. The tag sheet's .closed.then(...) callback runs and calls resetTagSheetHeight because _transitioningToEdit is still false
  6. Only THEN does _openEditNodeSheet() call _sheetCoordinator.openEditNodeSheet() which sets _transitioningToEdit = true

This caused the map to bounce during edit sheet transitions, and potentially interfered with proper height coordination.

Solution Implemented

1. Fixed Race Condition in Sheet Transitions

File: lib/screens/home_screen.dart

  • Set _transitioningToEdit = true BEFORE closing the tag sheet
  • This prevents the tag sheet's close callback from resetting the height prematurely
  • Ensures smooth transitions without map bounce
void _openEditNodeSheet() {
  // Set transition flag BEFORE closing tag sheet to prevent map bounce
  _sheetCoordinator.setTransitioningToEdit(true);
  
  // Close any existing tag sheet first...

2. Enhanced Debugging and Monitoring

Files:

  • lib/widgets/measured_sheet.dart - Added optional debug labels and height change logging
  • lib/screens/coordinators/sheet_coordinator.dart - Added debug logging for height updates and active height calculation
  • lib/screens/home_screen.dart - Added debug labels to all MeasuredSheet instances

Debug Labels Added:

  • NodeTag - For node tag sheets
  • SuspectedLocation - For suspected location sheets
  • AddNode - For add node sheets
  • EditNode - For edit node sheets
  • Navigation - For navigation sheets

3. Improved Fallback Robustness

Files:

  • lib/widgets/map/node_markers.dart
  • lib/widgets/map/suspected_location_markers.dart

Added warning messages to fallback behavior to help identify if callbacks are not being provided properly (though this should not happen under normal operation).

Technical Details

Sheet Height Priority Order

The activeSheetHeight calculation follows this priority:

  1. Add sheet height (highest priority)
  2. Edit sheet height
  3. Navigation sheet height
  4. Tag sheet height (lowest priority - used for both node tags and suspected locations)

This ensures that session-based sheets (add/edit) always take precedence over informational sheets (tag/suspected location).

Debugging Output

When debugging is enabled, you'll see console output like:

[MeasuredSheet-NodeTag] Height changed: 0.0 -> 320.0
[SheetCoordinator] Updating tag sheet height: 0.0 -> 364.0
[SheetCoordinator] Active sheet height: 364.0 (add: 0.0, edit: 0.0, nav: 0.0, tag: 364.0)

This helps trace the height measurement and coordination flow.

SheetAwareMap Behavior

The SheetAwareMap widget:

  • Moves the map up by sheetHeight pixels (top: -sheetHeight)
  • Extends the map rendering area by the same amount (height: availableHeight + sheetHeight)
  • This keeps the visual center in the middle of the area above the sheet
  • Uses smooth animation (300ms duration with Curves.easeOut)

Files Modified

Core Fix

  • lib/screens/home_screen.dart - Fixed race condition in _openEditNodeSheet()

Enhanced Debugging

  • lib/widgets/measured_sheet.dart - Added debug labels and logging
  • lib/screens/coordinators/sheet_coordinator.dart - Added debug logging for height coordination
  • lib/widgets/map/node_markers.dart - Enhanced fallback robustness
  • lib/widgets/map/suspected_location_markers.dart - Enhanced fallback robustness

Version & Release

  • pubspec.yaml - Updated version to 1.8.2+32
  • assets/changelog.json - Added v1.8.2 changelog entry

Expected Behavior After Fix

Node Tag Sheets

  1. Tap a surveillance device marker
  2. Tag sheet opens with smooth animation
  3. Map shifts up so the device marker appears in the center of the visible area above the sheet
  4. Tap "Edit" button
  5. Transition to edit sheet is smooth without map bounce
  6. Map remains properly positioned during edit session

Suspected Location Sheets

  1. Tap a suspected location marker (yellow diamond)
  2. Sheet opens with smooth animation
  3. Map shifts up so the suspected location appears in the center of the visible area above the sheet
  4. Tap "Close"
  5. Map returns to original position with smooth animation

Consistency

Both tag sheets now behave identically to the add/edit node sheets in terms of map positioning.

Testing Recommendations

Basic Functionality

  1. Node tag sheets: Tap various surveillance device markers and verify map positioning
  2. Suspected location sheets: Tap suspected location markers and verify map positioning
  3. Sheet transitions: Open tag sheet → tap Edit → verify smooth transition without bounce
  4. Different devices: Test on both phones and tablets in portrait/landscape
  5. Different sheet heights: Test with nodes having many tags vs few tags

Edge Cases

  1. Quick transitions: Rapidly tap Edit button to test race condition fix
  2. Orientation changes: Rotate device while sheets are open
  3. Background/foreground: Send app to background and return
  4. Memory pressure: Test with multiple apps running

Debug Console Monitoring

Monitor console output for:

  • Height measurement logging from MeasuredSheet-* components
  • Height coordination logging from SheetCoordinator
  • Any warning messages from fallback behavior (should not appear)

Brutalist Code Principles Applied

1. Simple, Explicit Solution

  • Fixed the race condition with one clear line: set the flag before the operation that depends on it
  • No complex state machine or coordination logic

2. Enhanced Debugging Without Complexity

  • Added simple debug labels and logging
  • Minimal overhead, easy to enable/disable
  • Helps troubleshoot without changing behavior

3. Robust Fallbacks

  • Enhanced existing fallback behavior with warning messages
  • Maintains functionality even if something goes wrong
  • Clear indication in logs if fallback is used

4. Consistent Pattern Application

  • All MeasuredSheet instances now have debug labels
  • All sheet types follow the same coordination pattern
  • Uniform debugging approach across components

This fix maintains the project's brutalist philosophy by solving the core problem simply and directly while adding appropriate safeguards and debugging capabilities.