Skip to content

Commit 5597bcd

Browse files
Copilotbdlukaa
andauthored
fix: Correctly handle system text scaling on DatePicker, TimePicker, AutoSuggestBox popups (#1286)
* Initial plan * fix: overflow on TimePicker/DatePicker with system text scaling Co-authored-by: bdlukaa <45696119+bdlukaa@users.noreply.github.com> * fix: Support large text scales on example app * fix: Support larger text scales on date and time picker buttons * fix: Adapt info badge to text scale * fix: Do not apply text scaling to auto suggest box overlay * fix: Improve media query usage * chore: Update changelog --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bdlukaa <45696119+bdlukaa@users.noreply.github.com> Co-authored-by: Bruno D'Luka <brunodlukaa@gmail.com>
1 parent 9fdc51e commit 5597bcd

File tree

16 files changed

+97
-84
lines changed

16 files changed

+97
-84
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [next]
2+
3+
- fix: Correctly handle system text scaling on `DatePicker`, `TimePicker`, `AutoSuggestBox` popups ([#1321](https://github.com/bdlukaa/fluent_ui/issues/1321), [#1286](https://github.com/bdlukaa/fluent_ui/pull/1286))
4+
15
## 4.14.0
26

37
- refactor: Consistent theme classes

example/lib/screens/forms/date_picker.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ DatePicker(
6868
showMonth: showMonth,
6969
showYear: showYear,
7070
),
71-
SizedBox(
72-
width: 150,
71+
ConstrainedBox(
72+
constraints: const BoxConstraints(minWidth: 150),
7373
child: Column(
7474
mainAxisSize: MainAxisSize.min,
7575
crossAxisAlignment: CrossAxisAlignment.start,

example/lib/screens/popups/teaching_tip.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ showTeachingTip(
150150
),
151151
),
152152
const SizedBox(width: 18),
153-
SizedBox(
154-
width: 150,
153+
ConstrainedBox(
154+
constraints: const BoxConstraints(minWidth: 150),
155155
child: ComboBox<String>(
156156
placeholder: const Text('Alignment'),
157157
items: List.generate(alignments.length, (final index) {

example/lib/screens/theming/colors.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ class ColorBlock extends StatelessWidget {
190190
focused: states.isFocused,
191191
renderOutside: false,
192192
child: Container(
193-
height: 85,
194-
width: 85,
193+
height: MediaQuery.textScalerOf(context).scale(85),
194+
width: MediaQuery.textScalerOf(context).scale(85),
195195
padding: const EdgeInsetsDirectional.all(6),
196196
color: color,
197197
child: Column(

example/lib/widgets/code_snippet_card.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ class _CodeSnippetCardState extends State<CodeSnippetCard>
7373
},
7474
trailing: isOpen
7575
? Container(
76-
height: 31,
77-
constraints: const BoxConstraints(minWidth: 80),
76+
margin: const EdgeInsetsDirectional.symmetric(
77+
vertical: 4,
78+
),
79+
constraints: const BoxConstraints(
80+
minWidth: 80,
81+
minHeight: 32,
82+
),
7883
child: Button(
7984
style: ButtonStyle(
8085
backgroundColor: isCopying

example/lib/widgets/material_equivalents.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class _UIEquivalentsState extends State<UIEquivalents> {
272272
height: 216,
273273
padding: const EdgeInsetsDirectional.only(top: 6),
274274
margin: EdgeInsetsDirectional.only(
275-
bottom: MediaQuery.of(context).viewInsets.bottom,
275+
bottom: MediaQuery.viewInsetsOf(context).bottom,
276276
),
277277
color: c.CupertinoColors.systemBackground.resolveFrom(
278278
context,
@@ -327,7 +327,7 @@ class _UIEquivalentsState extends State<UIEquivalents> {
327327
height: 216,
328328
padding: const EdgeInsetsDirectional.only(top: 6),
329329
margin: EdgeInsetsDirectional.only(
330-
bottom: MediaQuery.of(context).viewInsets.bottom,
330+
bottom: MediaQuery.viewInsetsOf(context).bottom,
331331
),
332332
color: c.CupertinoColors.systemBackground.resolveFrom(
333333
context,

lib/src/controls/flyouts/menu_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class MenuBarState extends State<MenuBar> {
219219
groupId: MenuBar,
220220
onTapOutside: (_) => closeFlyout(),
221221
child: Container(
222-
height: 40,
222+
constraints: const BoxConstraints(minHeight: 40),
223223
padding: EdgeInsetsDirectional.only(
224224
top: barMargin.top,
225225
bottom: barMargin.bottom,

lib/src/controls/form/auto_suggest_box.dart

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ class AutoSuggestBoxState<T> extends State<AutoSuggestBox<T>> {
607607
);
608608

609609
final screenHeight =
610-
MediaQuery.sizeOf(context).height -
610+
MediaQuery.heightOf(context) -
611611
MediaQuery.viewPaddingOf(context).bottom;
612612
final overlayY = globalOffset.dy + box.size.height;
613613
final maxHeight = (screenHeight - overlayY).clamp(
@@ -964,68 +964,70 @@ class _AutoSuggestBoxOverlayState<T> extends State<_AutoSuggestBoxOverlay<T>> {
964964
final theme = FluentTheme.of(context);
965965
final localizations = FluentLocalizations.of(context);
966966

967-
return TextFieldTapRegion(
968-
child: FocusScope(
969-
node: widget.node,
970-
child: Container(
971-
constraints: BoxConstraints(maxHeight: widget.maxHeight),
972-
decoration: ShapeDecoration(
973-
shape: const RoundedRectangleBorder(
974-
borderRadius: BorderRadius.vertical(bottom: Radius.circular(4)),
975-
),
976-
color: theme.resources.cardBackgroundFillColorDefault,
977-
shadows: [
978-
BoxShadow(
979-
color: Colors.black.withValues(alpha: 0.05),
980-
offset: const Offset(-1, 1),
981-
blurRadius: 2,
982-
spreadRadius: 3,
967+
return MediaQuery.withNoTextScaling(
968+
child: TextFieldTapRegion(
969+
child: FocusScope(
970+
node: widget.node,
971+
child: Container(
972+
constraints: BoxConstraints(maxHeight: widget.maxHeight),
973+
decoration: ShapeDecoration(
974+
shape: const RoundedRectangleBorder(
975+
borderRadius: BorderRadius.vertical(bottom: Radius.circular(4)),
983976
),
984-
BoxShadow(
985-
color: Colors.black.withValues(alpha: 0.05),
986-
offset: const Offset(1, 1),
987-
blurRadius: 2,
988-
spreadRadius: 3,
977+
color: theme.resources.cardBackgroundFillColorDefault,
978+
shadows: [
979+
BoxShadow(
980+
color: Colors.black.withValues(alpha: 0.05),
981+
offset: const Offset(-1, 1),
982+
blurRadius: 2,
983+
spreadRadius: 3,
984+
),
985+
BoxShadow(
986+
color: Colors.black.withValues(alpha: 0.05),
987+
offset: const Offset(1, 1),
988+
blurRadius: 2,
989+
spreadRadius: 3,
990+
),
991+
],
992+
),
993+
child: Acrylic(
994+
child: ValueListenableBuilder<TextEditingValue>(
995+
valueListenable: widget.controller,
996+
builder: (context, value, _) {
997+
final sortedItems = widget.sorter(value.text, items);
998+
late Widget result;
999+
if (sortedItems.isEmpty) {
1000+
result =
1001+
widget.noResultsFoundBuilder?.call(context) ??
1002+
Padding(
1003+
padding: const EdgeInsetsDirectional.only(bottom: 4),
1004+
child: _AutoSuggestBoxOverlayTile(
1005+
text: Text(localizations.noResultsFoundLabel),
1006+
),
1007+
);
1008+
} else {
1009+
result = ListView.builder(
1010+
itemExtent: tileHeight,
1011+
controller: scrollController,
1012+
key: ValueKey<int>(sortedItems.length),
1013+
shrinkWrap: true,
1014+
padding: const EdgeInsetsDirectional.only(bottom: 4),
1015+
itemCount: sortedItems.length,
1016+
itemBuilder: (context, index) {
1017+
final item = sortedItems[index];
1018+
return widget.itemBuilder?.call(context, item) ??
1019+
_AutoSuggestBoxOverlayTile(
1020+
text: item.child ?? Text(item.label),
1021+
semanticLabel: item.semanticLabel ?? item.label,
1022+
selected: item._selected || widget.node.hasFocus,
1023+
onSelected: () => widget.onSelected(item),
1024+
);
1025+
},
1026+
);
1027+
}
1028+
return result;
1029+
},
9891030
),
990-
],
991-
),
992-
child: Acrylic(
993-
child: ValueListenableBuilder<TextEditingValue>(
994-
valueListenable: widget.controller,
995-
builder: (context, value, _) {
996-
final sortedItems = widget.sorter(value.text, items);
997-
late Widget result;
998-
if (sortedItems.isEmpty) {
999-
result =
1000-
widget.noResultsFoundBuilder?.call(context) ??
1001-
Padding(
1002-
padding: const EdgeInsetsDirectional.only(bottom: 4),
1003-
child: _AutoSuggestBoxOverlayTile(
1004-
text: Text(localizations.noResultsFoundLabel),
1005-
),
1006-
);
1007-
} else {
1008-
result = ListView.builder(
1009-
itemExtent: tileHeight,
1010-
controller: scrollController,
1011-
key: ValueKey<int>(sortedItems.length),
1012-
shrinkWrap: true,
1013-
padding: const EdgeInsetsDirectional.only(bottom: 4),
1014-
itemCount: sortedItems.length,
1015-
itemBuilder: (context, index) {
1016-
final item = sortedItems[index];
1017-
return widget.itemBuilder?.call(context, item) ??
1018-
_AutoSuggestBoxOverlayTile(
1019-
text: item.child ?? Text(item.label),
1020-
semanticLabel: item.semanticLabel ?? item.label,
1021-
selected: item._selected || widget.node.hasFocus,
1022-
onSelected: () => widget.onSelected(item),
1023-
);
1024-
},
1025-
);
1026-
}
1027-
return result;
1028-
},
10291031
),
10301032
),
10311033
),

lib/src/controls/form/selection_controls.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class _FluentTextSelectionControlsToolbarState
396396
final midpointAnchor = Offset(
397397
(widget.selectionMidpoint.dx - widget.globalEditableRegion.left).clamp(
398398
MediaQuery.paddingOf(context).left,
399-
MediaQuery.sizeOf(context).width - MediaQuery.paddingOf(context).right,
399+
MediaQuery.widthOf(context) - MediaQuery.paddingOf(context).right,
400400
),
401401
widget.selectionMidpoint.dy - widget.globalEditableRegion.top,
402402
);

lib/src/controls/layout/page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class PageHeader extends StatelessWidget {
252252
/// [kPageDefaultVerticalPadding]
253253
static double horizontalPadding(BuildContext context) {
254254
assert(debugCheckHasMediaQuery(context));
255-
final screenWidth = MediaQuery.sizeOf(context).width;
255+
final screenWidth = MediaQuery.widthOf(context);
256256
final isSmallScreen = screenWidth < 640.0;
257257
final horizontalPadding = isSmallScreen
258258
? 12.0

0 commit comments

Comments
 (0)