DisplayFeatureSubScreen.subScreensInBounds depends on the order of displayFeatures and can return a sub-screen that spans a fold
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 packages/flutter/lib/src/widgets/display_feature_sub_screen.dart 开始,追踪 subScreensInBounds 如何针对垂直和水平显示特征拆分当前子屏幕。根据复现案例添加一个 widget 测试,检查两种特征顺序。完成标准是:拆分后的子屏幕和对话框位置不受顺序影响,并且都不会跨越折叠处。
由索引模型根据 Issue 内容生成。
描述
Steps to reproduce
DisplayFeatureSubScreen.subScreensInBounds gives different sub-screens for the same display features depending on their order in MediaQuery.displayFeatures. With a fold in the middle and a second full-height feature at one edge (here a cutout band on the right, as on a foldable with a side system area), the order [fold, band] produces a sub-screen that spans the fold, so a dialog lands across the crease. The order [band, fold] gives the expected halves.
Run this widget test (Flutter 3.47.7 stable, Dart 3.13.5):
import 'dart:ui' show DisplayFeature, DisplayFeatureState, DisplayFeatureType;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
const _band = DisplayFeature(
bounds: Rect.fromLTRB(867, 0, 951, 669),
type: DisplayFeatureType.cutout,
state: DisplayFeatureState.unknown,
);
const _fold = DisplayFeature(
bounds: Rect.fromLTRB(455.5, 0, 495.5, 669),
type: DisplayFeatureType.fold,
state: DisplayFeatureState.postureHalfOpened,
);
Future<Rect> _dialogRect(WidgetTester tester, List<DisplayFeature> features) async {
tester.view.physicalSize = const Size(951, 669);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
late BuildContext ctx;
await tester.pumpWidget(MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(displayFeatures: features),
child: child!,
),
home: Builder(builder: (inner) { ctx = inner; return const SizedBox.expand(); }),
));
showDialog<void>(
context: ctx,
anchorPoint: const Offset(951, 0),
builder: (_) => const Center(child: SizedBox(key: ValueKey('d'), width: 300, height: 100)),
);
await tester.pumpAndSettle();
return tester.getRect(find.byKey(const ValueKey('d')));
}
bool _crossesFold(Rect r) => r.left < _fold.bounds.right && r.right > _fold.bounds.left;
void main() {
testWidgets('[band, fold]', (tester) async {
final r = await _dialogRect(tester, const [_band, _fold]);
expect(_crossesFold(r), isFalse); // passes: Rect.fromLTRB(531.3, 284.5, 831.3, 384.5)
});
testWidgets('[fold, band]', (tester) async {
final r = await _dialogRect(tester, const [_fold, _band]);
expect(_crossesFold(r), isFalse); // fails: Rect.fromLTRB(283.5, 284.5, 583.5, 384.5)
});
}
Expected results
The sub-screens, and so the dialog's position, do not depend on the order of displayFeatures. In both cases the dialog anchored at the top-right lands in the right half, between the fold (495.5) and the band (867), as it does for [band, fold].
Actual results
With [fold, band] the dialog is centred in a sub-screen 0…867 and straddles the fold (283.5…583.5 against a fold at 455.5…495.5).
subScreensInBounds (packages/flutter/lib/src/widgets/display_feature_sub_screen.dart) splits every current sub-screen by each full-height feature without checking that the feature intersects that sub-screen, and it builds the left piece as bounds.left - screen.left without clamping to screen.right. Tracing [fold, band]:
- The fold splits
0…951into0…455.5and495.5…951. - The band (
867…951) does not intersect0…455.5, but the vertical branch still runs:screen.left < bounds.leftaddsRect.fromLTWH(0, 0, 867 - 0, …), a sub-screen0…867that reaches back across the fold. The second piece becomes495.5…867.
The anchor then picks 0…867.
Suggested fix: skip a feature that does not overlap the current sub-screen (keep the sub-screen as is), or clamp the pieces to the sub-screen (min(bounds.left, screen.right) for the left piece's right edge, max(bounds.right, screen.left) for the right piece's left edge). The same applies to the horizontal branch.
Context
This shows up when an app projects more than one full-height feature, for example a fold plus a side system area on a foldable such as the iPhone Duo. We work around it by always listing the edge band before the fold.
Flutter Doctor output
Flutter 3.47.7 (stable, revision abaf9c5237), Dart 3.13.5, macOS 26.7.1. Reproduces in flutter test with no device.
- 主要语言
- Dart
- 星标
- 180k
- 派生
- 33.9k
- 平均合并
- 2 天 57 分钟
- 30 天内合并 PR
- 292
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
flutter/flutter 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
c: tech-debt framework team-framework
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
P2 team-web triaged-web
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
[go_router_builder] onExit method not detected in mixins可能已有人在做 @rahulshahDEV 今天认领。 未关闭has reproducible steps p: go_router p: go_router_builder package team-ecosystem workaround available
难度 2/5 1-3 小时 新手友好度 72/100
flutter/flutter#195151 · 2 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 4 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
area: templates bug
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
vicajilau/flutter_file_picker#2279 ·
维护者通常 1 天内回复
-
Github Issue needs-triage
难度 2/5 1-3 小时 新手友好度 65/100
shorebirdtech/shorebird#4187 ·
维护者通常 1 天内回复