Repository navigation
Fix RangeError in PredictiveBackEvent when Android sends EDGE_NONE - #191306
muhammadkamel wants to merge 2 commits into
Conversation
Android can send swipeEdge=2 (BackEvent.EDGE_NONE) for button-triggered predictive back events, which previously crashed fromMap. Map that value to SwipeEdge.none instead of indexing SwipeEdge.values. Fixes flutter#186168
There was a problem hiding this comment.
Code Review
This pull request introduces a new SwipeEdge.none enum value to represent button-triggered back events (corresponding to Android's BackEvent.EDGE_NONE). It updates PredictiveBackEvent parsing, isButtonEvent detection, and page transitions to handle this new state, and adds comprehensive unit tests. Feedback suggests explicitly casting map['swipeEdge'] to int and asserting it is non-null during deserialization to maintain type safety and prevent silently ignoring malformed values.
| swipeEdge: switch (map['swipeEdge']) { | ||
| 0 => SwipeEdge.left, | ||
| 1 => SwipeEdge.right, | ||
| 2 || _ => SwipeEdge.none, | ||
| }, |
There was a problem hiding this comment.
To maintain type safety and consistency with how other fields (like progress and touchOffset) are extracted from the map, we should explicitly cast map['swipeEdge'] to int and assert that it is non-null. This prevents silently ignoring null or malformed values, which would otherwise be incorrectly treated as SwipeEdge.none and could mask integration bugs.
| swipeEdge: switch (map['swipeEdge']) { | |
| 0 => SwipeEdge.left, | |
| 1 => SwipeEdge.right, | |
| 2 || _ => SwipeEdge.none, | |
| }, | |
| swipeEdge: switch (map['swipeEdge']! as int) { | |
| 0 => SwipeEdge.left, | |
| 1 => SwipeEdge.right, | |
| _ => SwipeEdge.none, | |
| }, |
|
This pull request contains changes to Material or Cupertino, which are currently frozen in this repository. Changes should be made in Please refer to #188444 for instructions. |
Material is frozen in flutter/flutter. Map Android EDGE_NONE to an existing SwipeEdge value so fromMap no longer throws, without adding a new enum case that would require a frozen exhaustive switch update.
This is the framework/services-only split of #185140, per Piinks' decoupling guidance and the Material/Cupertino freeze in this repository (#188444).
On some Android 14+ devices, the platform sends
swipeEdge: 2(BackEvent.EDGE_NONE) for button-triggered predictive back events.PredictiveBackEvent.fromMappreviously indexedSwipeEdge.values[2], which threw aRangeErrorbecause the enum only hasleftandright.This PR:
swipeEdgevalues explicitly (0→ left,1→ right,2and unknown → left) sofromMapnever throwsSwipeEdgeunchanged (no newnonevalue), because adding an enum case would require an exhaustive-switch update in frozen Material codeisButtonEvent(touchOffset == nullorOffset.zerowith zero progress), which matches the crash payload from the issueMaterial widget tests and transition behavior for
EDGE_NONEbelong inmaterial_uiin flutter/packages. A dedicatedSwipeEdge.nonevalue can be added later if Material is no longer frozen here, or ported with that follow-up.Fixes #186168
Pre-launch Checklist
///).