Unverified Commit bff417ac authored by hangyu's avatar hangyu Committed by GitHub

Update material banner maxScaleFactor to meet GAR requirement (#142015)

fixes: https://github.com/flutter/flutter/issues/142012
parent e86c1c88
...@@ -17,6 +17,7 @@ import 'theme.dart'; ...@@ -17,6 +17,7 @@ import 'theme.dart';
const Duration _materialBannerTransitionDuration = Duration(milliseconds: 250); const Duration _materialBannerTransitionDuration = Duration(milliseconds: 250);
const Curve _materialBannerHeightCurve = Curves.fastOutSlowIn; const Curve _materialBannerHeightCurve = Curves.fastOutSlowIn;
const double _kMaxContentTextScaleFactor = 1.5;
/// Specify how a [MaterialBanner] was closed. /// Specify how a [MaterialBanner] was closed.
/// ///
...@@ -365,21 +366,31 @@ class _MaterialBannerState extends State<MaterialBanner> { ...@@ -365,21 +366,31 @@ class _MaterialBannerState extends State<MaterialBanner> {
padding: leadingPadding, padding: leadingPadding,
child: widget.leading, child: widget.leading,
), ),
Expanded( MediaQuery.withClampedTextScaling(
child: DefaultTextStyle( // Set maximum text scale factor to _kMaxContentTextScaleFactor for the
style: textStyle!, // content to keep the visual hierarchy the same even with larger font
child: widget.content, // sizes.
maxScaleFactor: _kMaxContentTextScaleFactor,
child: Expanded(
child: DefaultTextStyle(
style: textStyle!,
child: widget.content,
),
), ),
), ),
if (isSingleRow) if (isSingleRow)
actionsBar, MediaQuery.withClampedTextScaling(
// Set maximum text scale factor to _kMaxContentTextScaleFactor for the
// actionsBar to keep the visual hierarchy the same even with larger font
// sizes.
maxScaleFactor: _kMaxContentTextScaleFactor,
child: actionsBar,
),
], ],
), ),
), ),
if (!isSingleRow) if (!isSingleRow) actionsBar,
actionsBar, if (elevation == 0) Divider(height: 0, color: dividerColor),
if (elevation == 0)
Divider(height: 0, color: dividerColor),
], ],
), ),
), ),
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -236,6 +237,51 @@ void main() { ...@@ -236,6 +237,51 @@ void main() {
expect(contentBottomLeft.dx, lessThan(actionsTopRight.dx)); expect(contentBottomLeft.dx, lessThan(actionsTopRight.dx));
}); });
testWidgets('material banner content can scale and has maxScaleFactor', (WidgetTester tester) async {
const String label = 'A';
Widget buildApp({ required TextScaler textScaler }) {
return MaterialApp(
home: MediaQuery(
data: MediaQueryData(textScaler: textScaler),
child: MaterialBanner(
forceActionsBelow: true,
content: const SizedBox(child:Center(child:Text(label))),
actions: <Widget>[
TextButton(
child: const Text('B'),
onPressed: () { },
),
],
),
),
);
}
await tester.pumpWidget(buildApp(textScaler: TextScaler.noScaling));
expect(find.text(label), findsOneWidget);
if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933
expect(tester.getSize(find.text(label)), const Size(14.25, 20.0));
}
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(15.65, 22.0)), true);
}
await tester.pumpWidget(buildApp(textScaler: const TextScaler.linear(1.5)));
if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933
expect(_sizeAlmostEqual(tester.getSize(find.text(label)), const Size(21.25, 30)), 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(21.25, 30)), true);
}
});
group('MaterialBanner elevation', () { group('MaterialBanner elevation', () {
Widget buildBanner(Key tapTarget, {double? elevation, double? themeElevation}) { Widget buildBanner(Key tapTarget, {double? elevation, double? themeElevation}) {
return MaterialApp( return MaterialApp(
...@@ -1117,3 +1163,7 @@ Material _getMaterialFromText(WidgetTester tester, String text) { ...@@ -1117,3 +1163,7 @@ Material _getMaterialFromText(WidgetTester tester, String text) {
RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) { RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.descendant(of: find.byType(MaterialBanner), matching: find.text(text))).renderObject! as RenderParagraph; return tester.element<StatelessElement>(find.descendant(of: find.byType(MaterialBanner), matching: find.text(text))).renderObject! as RenderParagraph;
} }
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