mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Use alphabetic baselines for layout of InputDecorator (#44029)
This commit is contained in:
parent
2110dfe0f5
commit
8cd892b39b
@ -907,7 +907,13 @@ class _RenderDecoration extends RenderBox {
|
||||
return 0.0;
|
||||
}
|
||||
box.layout(constraints, parentUsesSize: true);
|
||||
final double baseline = box.getDistanceToBaseline(textBaseline);
|
||||
// Since internally, all layout is performed against the alphabetic baseline,
|
||||
// (eg, ascents/descents are all relative to alphabetic, even if the font is
|
||||
// an ideographic or hanging font), we should always obtain the reference
|
||||
// baseline from the alphabetic baseline. The ideographic baseline is for
|
||||
// use post-layout and is derived from the alphabetic baseline combined with
|
||||
// the font metrics.
|
||||
final double baseline = box.getDistanceToBaseline(TextBaseline.alphabetic);
|
||||
assert(baseline != null && baseline >= 0.0);
|
||||
return baseline;
|
||||
}
|
||||
|
||||
@ -3551,4 +3551,47 @@ void main() {
|
||||
'alignLabelWithHint: true',
|
||||
]);
|
||||
});
|
||||
|
||||
testWidgets('uses alphabetic baseline for CJK layout', (WidgetTester tester) async {
|
||||
await tester.binding.setLocale('zh', 'CN');
|
||||
final Typography typography = Typography();
|
||||
|
||||
final FocusNode focusNode = FocusNode();
|
||||
final TextEditingController controller = TextEditingController();
|
||||
// The dense theme uses ideographic baselines
|
||||
Widget buildFrame(bool alignLabelWithHint) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
textTheme: typography.dense,
|
||||
),
|
||||
home: Material(
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'label',
|
||||
alignLabelWithHint: alignLabelWithHint,
|
||||
hintText: 'hint',
|
||||
hintStyle: const TextStyle(
|
||||
fontFamily: 'Cough',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(buildFrame(true));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// These numbers should be the values from using alphabetic baselines:
|
||||
// Ideographic (incorrect) value is 31.299999713897705
|
||||
expect(tester.getTopLeft(find.text('hint')).dy, 28.75);
|
||||
|
||||
// Ideographic (incorrect) value is 50.299999713897705
|
||||
expect(tester.getBottomLeft(find.text('hint')).dy, 47.75);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user