|
| 1 | +import 'dart:ui' as ui; |
| 2 | +import 'package:checks/checks.dart'; |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter_test/flutter_test.dart'; |
| 5 | +import 'package:legacy_checks/legacy_checks.dart'; |
| 6 | +import 'package:zulip/widgets/inset_shadow.dart'; |
| 7 | + |
| 8 | +import '../flutter_checks.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + testWidgets('no additional padding added', (tester) async { |
| 12 | + await tester.pumpWidget(const Directionality( |
| 13 | + textDirection: TextDirection.ltr, |
| 14 | + child: Align( |
| 15 | + // Position child at the top-left corner of the box at (0, 0) |
| 16 | + // to ease the check on [Rect] later. |
| 17 | + alignment: Alignment.topLeft, |
| 18 | + child: SizedBox(width: 20, height: 20, |
| 19 | + child: InsetShadowBox(top: 7, bottom: 3, |
| 20 | + color: Colors.red, |
| 21 | + child: Placeholder()))))); |
| 22 | + |
| 23 | + final childRect = tester.getRect(find.byType(Placeholder)); |
| 24 | + check(childRect).equals(const Rect.fromLTRB(0, 0, 20, 20)); |
| 25 | + }); |
| 26 | + |
| 27 | + testWidgets('render shadow correctly', (tester) async { |
| 28 | + PaintPatternPredicate paintGradient({required Rect rect}) { |
| 29 | + // This is inspired by |
| 30 | + // https://github.com/flutter/flutter/blob/7b5462cc34af903e2f2de4be7540ff858685cdfc/packages/flutter/test/cupertino/route_test.dart#L1449-L1475 |
| 31 | + return (Symbol methodName, List<dynamic> arguments) { |
| 32 | + check(methodName).equals(#drawRect); |
| 33 | + check(arguments[0]).isA<Rect>().equals(rect); |
| 34 | + check(arguments[1]).isA<Paint>().shader.isA<ui.Gradient>(); |
| 35 | + return true; |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + await tester.pumpWidget(const Directionality( |
| 40 | + textDirection: TextDirection.ltr, |
| 41 | + child: Center( |
| 42 | + // This would be forced to fill up the screen |
| 43 | + // if not wrapped in a widget like [Center]. |
| 44 | + child: SizedBox(width: 100, height: 100, |
| 45 | + child: InsetShadowBox(top: 3, bottom: 7, |
| 46 | + color: Colors.red, |
| 47 | + child: SizedBox(width: 30, height: 30)))))); |
| 48 | + |
| 49 | + final box = tester.renderObject(find.byType(InsetShadowBox)); |
| 50 | + check(box).legacyMatcher((paints |
| 51 | + // The coordinate system of these [Rect]'s is relative to the parent |
| 52 | + // of the [Gradient] from [InsetShadowBox], not the entire [FlutterView]. |
| 53 | + ..something(paintGradient(rect: const Rect.fromLTRB(0, 0, 100, 0+3))) |
| 54 | + ..something(paintGradient(rect: const Rect.fromLTRB(0, 100-7, 100, 100))) |
| 55 | + ) as Matcher); |
| 56 | + }); |
| 57 | +} |
0 commit comments