Replace hardcoded platform identity checks in the framework with capability-based queries
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
### Description
Currently, the Flutter framework relies on hardcoded platform identity checks (e.g., `defaultTargetPlatform` or `Theme.of(context).platform`) to determine behavior. This creates friction for out-of-tree custom embedders, who are forced to spoof their OS identity to inherit basic capabilities.
**Proposal:**
* Replace hardcoded platform identity checks within the core framework with capability-based queries (e.g., `supportsPhysicsBasedScrolling`).
* Establish and document a mechanism for custom embedders to declare their supported capabilities to the framework.
* Allow existing Flutter-maintained platforms (like Android) to serve as an extensible "base." This would allow custom platforms that share most (but not all) behaviors with a supported platform to inherit its capabilities and deviate slightly only where needed.
Here are several examples:
1. `FlexibleSpaceBar` uses `Theme.of(context).platform` to decide whether to center titles.
https://github.com/flutter/flutter/blob/00b14ee0eee3fc91dbf3284daff57ff1ebd22389/packages/flutter/lib/src/material/flexible_space_bar.dart#L191-L200
2. `Drawer` relies on platform checks to determine layout, semantics, and system back button presence, ex:
https://github.com/flutter/flutter/blob/00b14ee0eee3fc91dbf3284daff57ff1ebd22389/packages/flutter/lib/src/material/drawer.dart#L253-L259
3. `TextMagnifier` hardcodes the magnifier implementation by switching on `defaultTargetPlatform`, returning null on unrecognized platforms.
https://github.com/flutter/flutter/blob/00b14ee0eee3fc91dbf3284daff57ff1ebd22389/packages/flutter/lib/src/material/magnifier.dart#L47-L57
4. The `Radio.adaptive` constructor uses a switch statement to return a CupertinoRadio for Apple platforms and defaults to the standard Material radio for all others.
https://github.com/flutter/flutter/blob/00b14ee0eee3fc91dbf3284daff57ff1ebd22389/packages/flutter/lib/src/material/radio.dart#L518-L540
5. `Autocomplete` assigns keyboard shortcuts by switching on `defaultTargetPlatform`.
https://github.com/flutter/flutter/blob/00b14ee0eee3fc91dbf3284daff57ff1ebd22389/packages/flutter/lib/src/widgets/autocomplete.dart#L412-L419
Contributor guide
Assessment
This issue has not been assessed yet.