[Android] PredictiveBackEvent.fromMap does not guard against invalid swipeEdge value
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
### Steps to reproduce
1. Run any Flutter app on an Android emulator with predictive back enabled.
2. Press the Android system Back button from the emulator/device navigation controls.
3. Observe that Flutter receives a predictive back event where `swipeEdge` is `2`.
4. The framework crashes in `PredictiveBackEvent.fromMap` when it tries to read `SwipeEdge.values[2]`.
### Expected results
Flutter should not crash when the Android platform sends a predictive back event with an unexpected `swipeEdge` value.
The framework should handle the value safely, either by validating the enum index before accessing `SwipeEdge.values`, using a fallback value, or ignoring the invalid predictive back event.
### Actual results
Flutter throws a `RangeError` from `PredictiveBackEvent.fromMap` when pressing the Android system Back button in the emulator.
The incoming platform map contains:
```dart
{
progress: 0.0,
swipeEdge: 2,
touchOffset: [0.0, 0.0],
}
### Code sample
```markdown
```dart
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: FirstPage(),
);
}
}
class FirstPage extends StatelessWidget {
const FirstPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('First page')),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const SecondPage(),
),
);
},
child: const Text('Open second page'),
),
),
);
}
}
class SecondPage extends StatelessWidget {
const SecondPage({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
appBar: AppBar(title: Text('Second page')),
body: Center(
child: Text(
'Press the Android system Back button from the emulator controls.',
),
),
);
}
}
### Screenshots or Video
Screenshots / Video demonstration
### Logs
Logs
```console
[Paste your logs here]
```
### Flutter Doctor output
Doctor output
```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.41.7, on macOS 26.4.1 25E253 darwin-arm64, locale en-EG)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 26.4.1)
[✓] Chrome - develop for the web
[✓] Connected device (5 available)
[✓] Network resources
• No issues found!
```
Contributor guide
Assessment
This issue has not been assessed yet.