fix(interactive_layer): clamp floating menu within parents smaller than the menu - #497
Closed
usman-deriv wants to merge 1 commit into
Closed
Conversation
…an the menu `SelectedDrawingFloatingMenu.onPanUpdate` clamps the dragged position with `newPosition.dx.clamp(0.0, parentSize.width - _menuSize.width)` (and the same for Y). `num.clamp(lower, upper)` throws `ArgumentError(lower)` when `lower > upper`, so whenever the parent Stack (the chart's interactive layer) is smaller than the ~144x40 menu on either axis — a keyboard squeezing the chart, split-screen / pop-up view, very small charts — the upper bound goes negative and every drag update throws `Invalid argument(s): 0.0` from `_SelectedDrawingFloatingMenuState.build.<fn>`. This surfaced as a fatal crash in production (Crashlytics 398cd50ce4d525e33e61b79fd1f640b8, DerivApp Android 1.17.8). Floor both upper bounds at 0 with `math.max` before clamping. When the parent is larger than the menu this is the identity, so behaviour is unchanged; when it is smaller the menu is pinned to the parent's origin instead of throwing. Adds a widget test that mounts the menu in a Stack smaller than the menu and drags it: it reproduces the ArgumentError on the previous code and passes with the fix. It also covers one-axis overflow and the normal "menu fits" clamping. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contributor
Reviewer's GuideFixes a production drag-time ArgumentError by ensuring floating-menu clamp upper bounds never fall below zero, pinning oversized menus to the parent origin while retaining normal boundary behavior; focused widget tests cover both overflow axes and the unchanged fitting case. Sequence diagram for safe floating-menu draggingsequenceDiagram
participant User
participant Menu as SelectedDrawingFloatingMenu
participant Parent as ParentRenderBox
participant Dart as Dart clamp
participant Controller as InteractiveLayerController
User->>Menu: onPanUpdate(details)
Menu->>Parent: read size
Menu->>Menu: math.max(0, parentSize - menuSize)
Menu->>Dart: newPosition.dx.clamp(0.0, maxX)
Menu->>Dart: newPosition.dy.clamp(0.0, maxY)
alt parent smaller than menu
Dart-->>Menu: (0, 0)
else parent fits menu
Dart-->>Menu: bounded position
end
Menu->>Controller: update floatingMenuPosition
Flow diagram for oversized floating-menu clampingflowchart TD
A[Drag floating menu] --> B[Read parent and menu sizes]
B --> C["Compute maxX and maxY with math.max(0, parent minus menu)"]
C --> D{Parent smaller on an axis?}
D -->|Yes| E[Clamp that axis to 0]
D -->|No| F[Clamp within normal parent bounds]
E --> G[Update menu position without exception]
F --> G
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes issue: production fatal — Crashlytics
398cd50ce4d525e33e61b79fd1f640b8(DerivApp Android 1.17.8); no GitHub issue filed.This PR contains the following changes:
Root cause
SelectedDrawingFloatingMenu.onPanUpdate(lib/src/deriv_chart/interactive_layer/widgets/selected_drawing_floating_menu.dart) keeps the dragged menu inside its parent with:Dart's
num.clamp(lower, upper)throwsArgumentError(lower)whenlower > upper. Whenever the parentStack(the chart's interactive layer) is smaller than the menu (~144×40 logical px) on either axis,parentSize.* - _menuSize.*goes negative, the bounds invert, and every drag update throws.Crash signature
Reported as a fatal in production (Crashlytics
398cd50ce4d525e33e61b79fd1f640b8, DerivApp Android 1.17.8).When it triggers
Any drag of the floating menu while the chart is narrower or shorter than the menu:
Fix
Floor both upper bounds at zero before clamping:
When the parent is larger than the menu
max(0, …)is the identity, so existing behaviour is unchanged. When it is smaller, the menu is pinned to the parent's origin instead of throwing._menuSize == Size.zero(not yet measured) still yields the parent size as the bound, as before.Test
New
test/deriv_chart/chart/interactive_layer/selected_drawing_floating_menu_test.dartmounts the real menu (with aHorizontalLineInteractableDrawing) inside aStackof a controlled size and pans it viatester.dragFrom:tester.takeException()is null and the menu /InteractiveLayerController.floatingMenuPositionend at(0, 0).[0, parent − menu], the overflowing axis stays pinned at 0.parent − menu(regression guard for the unchanged path).On the previous code test 1 and 2 fail with exactly the production signature (
Invalid argument(s): 0.0fromdouble.clampvia_SelectedDrawingFloatingMenuState.build.<anonymous closure>, lines 129 / 131); with the fix all three pass. Fullflutter testsuite: 177 passed.flutter analyzereports no issues in the changed files;dart formatclean.Pre-launch Checklist (For PR creator)
🤖 Generated with Claude Code
Summary by Sourcery
Prevent floating drawing menu drag crashes in constrained chart layouts.
Bug Fixes:
Tests: