Unverified Commit 6adc8246 authored by hangyu's avatar hangyu Committed by GitHub

Update navigationBar label's maxScaleFactor to meet GAR requirement (#141998)

fixes: https://github.com/flutter/flutter/issues/141997
parent 8fb4a648
...@@ -18,6 +18,7 @@ import 'tooltip.dart'; ...@@ -18,6 +18,7 @@ import 'tooltip.dart';
const double _kIndicatorHeight = 32; const double _kIndicatorHeight = 32;
const double _kIndicatorWidth = 64; const double _kIndicatorWidth = 64;
const double _kMaxLabelTextScaleFactor = 1.3;
// Examples can assume: // Examples can assume:
// late BuildContext context; // late BuildContext context;
...@@ -422,9 +423,11 @@ class NavigationDestination extends StatelessWidget { ...@@ -422,9 +423,11 @@ class NavigationDestination extends StatelessWidget {
return Padding( return Padding(
padding: const EdgeInsets.only(top: 4), padding: const EdgeInsets.only(top: 4),
child: MediaQuery.withClampedTextScaling( child: MediaQuery.withClampedTextScaling(
// Don't scale labels of destinations, instead, tooltip text will // Set maximum text scale factor to _kMaxLabelTextScaleFactor for the
// upscale. // label to keep the visual hierarchy the same even with larger font
maxScaleFactor: 1.0, // sizes. To opt out, wrap the [label] widget in a [MediaQuery] widget
// with a different `TextScaler`.
maxScaleFactor: _kMaxLabelTextScaleFactor,
child: Text(label, style: textStyle), child: Text(label, style: textStyle),
), ),
); );
......
...@@ -425,6 +425,71 @@ void main() { ...@@ -425,6 +425,71 @@ void main() {
} }
}); });
testWidgets('Material3 - NavigationBar label can scale and has maxScaleFactor', (WidgetTester tester) async {
const String label = 'A';
Widget buildApp({ required TextScaler textScaler }) {
return MediaQuery(
data: MediaQueryData(textScaler: textScaler),
child: Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
child: MaterialApp(
home: Navigator(
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<void>(
builder: (BuildContext context) {
return Scaffold(
bottomNavigationBar: NavigationBar(
destinations: const <NavigationDestination>[
NavigationDestination(
label: label,
icon: Icon(Icons.ac_unit),
),
NavigationDestination(
label: 'B',
icon: Icon(Icons.battery_alert),
),
],
),
);
},
);
},
),
),
),
);
}
await tester.pumpWidget(buildApp(textScaler: TextScaler.noScaling));
expect(find.text(label), findsOneWidget);
if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933
expect( _sizeAlmostEqual(tester.getSize(find.text(label)), const Size(12.5, 16.0)), true);
}
await tester.pumpWidget(buildApp(textScaler: const TextScaler.linear(1.1)));
await tester.pumpAndSettle();
if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933
expect( _sizeAlmostEqual(tester.getSize(find.text(label)), const Size(13.7, 18.0)), true);
}
await tester.pumpWidget(buildApp(textScaler: const TextScaler.linear(1.3)));
if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933
expect( _sizeAlmostEqual(tester.getSize(find.text(label)), const Size(16.1, 21.0)), true);
}
await tester.pumpWidget(buildApp(textScaler: const TextScaler.linear(4)));
if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933
expect( _sizeAlmostEqual(tester.getSize(find.text(label)), const Size(16.1, 21.0)), true);
}
});
testWidgets('Custom tooltips in NavigationBarDestination', (WidgetTester tester) async { testWidgets('Custom tooltips in NavigationBarDestination', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -1499,3 +1564,8 @@ class IconWithRandomColor extends StatelessWidget { ...@@ -1499,3 +1564,8 @@ class IconWithRandomColor extends StatelessWidget {
return Icon(icon, color: randomColor); return Icon(icon, color: randomColor);
} }
} }
bool _sizeAlmostEqual(Size a, Size b, {double maxDiff=0.05}) {
return (a.width - b.width).abs() <= maxDiff && (a.height - b.height).abs() <= maxDiff;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment