Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

DisplayFeatureSubScreen.subScreensInBounds depends on the order of displayFeatures and can return a sub-screen that spans a fold

未关闭 适合新手
#195,216 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
79/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
dart, flutter
领域
frontend, mobile

调研方向

从 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]:

  1. The fold splits 0…951 into 0…455.5 and 495.5…951.
  2. The band (867…951) does not intersect 0…455.5, but the vertical branch still runs: screen.left < bounds.left adds Rect.fromLTWH(0, 0, 867 - 0, …), a sub-screen 0…867 that reaches back across the fold. The second piece becomes 495.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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

flutter/flutter 的其他 Issue

查看 flutter/flutter 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。