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:
- Both sheets use
MeasuredSheetwrapper to track height - Both sheets call
SheetCoordinator.updateTagSheetHeight() SheetCoordinator.activeSheetHeightincludes tag sheet height as the lowest prioritySheetAwareMapreceives 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
- User taps "Edit" in NodeTagSheet
appState.startEditSession(node)is called- Auto-show logic calls
_openEditNodeSheet() _openEditNodeSheet()callsNavigator.of(context).pop()to close the tag sheet- The tag sheet's
.closed.then(...)callback runs and callsresetTagSheetHeightbecause_transitioningToEditis still false - 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 = trueBEFORE 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 logginglib/screens/coordinators/sheet_coordinator.dart- Added debug logging for height updates and active height calculationlib/screens/home_screen.dart- Added debug labels to all MeasuredSheet instances
Debug Labels Added:
NodeTag- For node tag sheetsSuspectedLocation- For suspected location sheetsAddNode- For add node sheetsEditNode- For edit node sheetsNavigation- For navigation sheets
3. Improved Fallback Robustness
Files:
lib/widgets/map/node_markers.dartlib/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:
- Add sheet height (highest priority)
- Edit sheet height
- Navigation sheet height
- 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
sheetHeightpixels (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 logginglib/screens/coordinators/sheet_coordinator.dart- Added debug logging for height coordinationlib/widgets/map/node_markers.dart- Enhanced fallback robustnesslib/widgets/map/suspected_location_markers.dart- Enhanced fallback robustness
Version & Release
pubspec.yaml- Updated version to 1.8.2+32assets/changelog.json- Added v1.8.2 changelog entry
Expected Behavior After Fix
Node Tag Sheets
- Tap a surveillance device marker
- Tag sheet opens with smooth animation
- Map shifts up so the device marker appears in the center of the visible area above the sheet
- Tap "Edit" button
- Transition to edit sheet is smooth without map bounce
- Map remains properly positioned during edit session
Suspected Location Sheets
- Tap a suspected location marker (yellow diamond)
- Sheet opens with smooth animation
- Map shifts up so the suspected location appears in the center of the visible area above the sheet
- Tap "Close"
- 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
- Node tag sheets: Tap various surveillance device markers and verify map positioning
- Suspected location sheets: Tap suspected location markers and verify map positioning
- Sheet transitions: Open tag sheet → tap Edit → verify smooth transition without bounce
- Different devices: Test on both phones and tablets in portrait/landscape
- Different sheet heights: Test with nodes having many tags vs few tags
Edge Cases
- Quick transitions: Rapidly tap Edit button to test race condition fix
- Orientation changes: Rotate device while sheets are open
- Background/foreground: Send app to background and return
- 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.