DisplayFeatureSubScreen.subScreensInBounds depends on the order of displayFeatures and can return a sub-screen that spans a fold
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 79/100
Línea de trabajo
Empieza con packages/flutter/lib/src/widgets/display_feature_sub_screen.dart y sigue cómo subScreensInBounds divide las subpantallas actuales para las características de pantalla verticales y horizontales. Añade una prueba de widget basada en la reproducción que compruebe ambos órdenes de las características. Se considerará terminado cuando las subpantallas resultantes y la ubicación del diálogo sean independientes del orden y ninguna cruce el pliegue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Dart
- Estrellas
- 180k
- Forks
- 33.9k
- Merge medio
- 2 d 5 h
- PR fusionados (30 d)
- 306
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de flutter/flutter
-
c: tech-debt framework team-framework
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
P2 team-web triaged-web
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
DropdownButtonFormField: InputDecoration looks enabled and reacts to hover when enabled: falseAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
has reproducible steps p: go_router p: go_router_builder package team-ecosystem workaround available
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
flutter/flutter#195151 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[material_ui] An untitled AlertDialog pads its content 16 from the top, not 24Posiblemente ocupada @LahaLuhem la tomó hace 1 día. Abiertop: material_ui package team-design
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
flutter/flutter#195096 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de flutter/flutter
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 5 días
-
[Bug] 附近设备权限未申请Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
bggRGjQaUbCoE/PiliPlus#3369 ·
Los mantenedores suelen responder en 1 día
-
auto-implement
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
bannzai/kashakeibo#143 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
[lsp] Remove DartAnalysisServerService.serverReadyForRequest() from EnableDartSupportForModuleAbiertoP1
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
flutter/flutter-intellij#9177 ·
Los mantenedores suelen responder en 1 día