|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'package:flutter/foundation.dart'; |
5 | 6 | import 'package:flutter/material.dart';
|
6 | 7 | import 'package:flutter/rendering.dart';
|
7 | 8 | import 'package:flutter_test/flutter_test.dart';
|
@@ -236,6 +237,51 @@ void main() {
|
236 | 237 | expect(contentBottomLeft.dx, lessThan(actionsTopRight.dx));
|
237 | 238 | });
|
238 | 239 |
|
| 240 | + testWidgets('material banner content can scale and has maxScaleFactor', (WidgetTester tester) async { |
| 241 | + |
| 242 | + const String label = 'A'; |
| 243 | + Widget buildApp({ required TextScaler textScaler }) { |
| 244 | + return MaterialApp( |
| 245 | + home: MediaQuery( |
| 246 | + data: MediaQueryData(textScaler: textScaler), |
| 247 | + child: MaterialBanner( |
| 248 | + forceActionsBelow: true, |
| 249 | + content: const SizedBox(child:Center(child:Text(label))), |
| 250 | + actions: <Widget>[ |
| 251 | + TextButton( |
| 252 | + child: const Text('B'), |
| 253 | + onPressed: () { }, |
| 254 | + ), |
| 255 | + ], |
| 256 | + ), |
| 257 | + ), |
| 258 | + ); |
| 259 | + } |
| 260 | + |
| 261 | + await tester.pumpWidget(buildApp(textScaler: TextScaler.noScaling)); |
| 262 | + expect(find.text(label), findsOneWidget); |
| 263 | + |
| 264 | + if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933 |
| 265 | + expect(tester.getSize(find.text(label)), const Size(14.25, 20.0)); |
| 266 | + } |
| 267 | + |
| 268 | + await tester.pumpWidget(buildApp(textScaler: const TextScaler.linear(1.1))); |
| 269 | + await tester.pumpAndSettle(); |
| 270 | + if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933 |
| 271 | + expect(_sizeAlmostEqual(tester.getSize(find.text(label)), const Size(15.65, 22.0)), true); |
| 272 | + } |
| 273 | + |
| 274 | + await tester.pumpWidget(buildApp(textScaler: const TextScaler.linear(1.5))); |
| 275 | + if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933 |
| 276 | + expect(_sizeAlmostEqual(tester.getSize(find.text(label)), const Size(21.25, 30)), true); |
| 277 | + } |
| 278 | + |
| 279 | + await tester.pumpWidget(buildApp(textScaler: const TextScaler.linear(4))); |
| 280 | + if (!kIsWeb || isCanvasKit) { // https://github.com/flutter/flutter/issues/99933 |
| 281 | + expect(_sizeAlmostEqual(tester.getSize(find.text(label)), const Size(21.25, 30)), true); |
| 282 | + } |
| 283 | + }); |
| 284 | + |
239 | 285 | group('MaterialBanner elevation', () {
|
240 | 286 | Widget buildBanner(Key tapTarget, {double? elevation, double? themeElevation}) {
|
241 | 287 | return MaterialApp(
|
@@ -1117,3 +1163,7 @@ Material _getMaterialFromText(WidgetTester tester, String text) {
|
1117 | 1163 | RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) {
|
1118 | 1164 | return tester.element<StatelessElement>(find.descendant(of: find.byType(MaterialBanner), matching: find.text(text))).renderObject! as RenderParagraph;
|
1119 | 1165 | }
|
| 1166 | + |
| 1167 | +bool _sizeAlmostEqual(Size a, Size b, {double maxDiff=0.05}) { |
| 1168 | + return (a.width - b.width).abs() <= maxDiff && (a.height - b.height).abs() <= maxDiff; |
| 1169 | +} |
0 commit comments