1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart';
import '../widgets/test_border.dart' show TestBorder;
class NotifyMaterial extends StatelessWidget {
const NotifyMaterial({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
LayoutChangedNotification().dispatch(context);
return Container();
}
}
Widget buildMaterial({
double elevation = 0.0,
Color shadowColor = const Color(0xFF00FF00),
Color color = const Color(0xFF0000FF),
}) {
return Center(
child: SizedBox(
height: 100.0,
width: 100.0,
child: Material(
color: color,
shadowColor: shadowColor,
elevation: elevation,
shape: const CircleBorder(),
),
),
);
}
RenderPhysicalShape getModel(WidgetTester tester) {
return tester.renderObject(find.byType(PhysicalShape));
}
class PaintRecorder extends CustomPainter {
PaintRecorder(this.log);
final List<Size> log;
@override
void paint(Canvas canvas, Size size) {
log.add(size);
final Paint paint = Paint()..color = const Color(0xFF0000FF);
canvas.drawRect(Offset.zero & size, paint);
}
@override
bool shouldRepaint(PaintRecorder oldDelegate) => false;
}
class ElevationColor {
const ElevationColor(this.elevation, this.color);
final double elevation;
final Color color;
}
void main() {
// Regression test for https://github.com/flutter/flutter/issues/81504
testWidgets('MaterialApp.home nullable and update test', (WidgetTester tester) async {
// _WidgetsAppState._usesNavigator == true
await tester.pumpWidget(const MaterialApp(home: SizedBox.shrink()));
// _WidgetsAppState._usesNavigator == false
await tester.pumpWidget(const MaterialApp()); // Do not crash!
// _WidgetsAppState._usesNavigator == true
await tester.pumpWidget(const MaterialApp(home: SizedBox.shrink())); // Do not crash!
expect(tester.takeException(), null);
});
testWidgets('default Material debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const Material().debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString())
.toList();
expect(description, <String>['type: canvas']);
});
testWidgets('Material implements debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const Material(
color: Color(0xFFFFFFFF),
shadowColor: Color(0xffff0000),
textStyle: TextStyle(color: Color(0xff00ff00)),
borderRadius: BorderRadiusDirectional.all(Radius.circular(10)),
).debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString())
.toList();
expect(description, <String>[
'type: canvas',
'color: Color(0xffffffff)',
'shadowColor: Color(0xffff0000)',
'textStyle.inherit: true',
'textStyle.color: Color(0xff00ff00)',
'borderRadius: BorderRadiusDirectional.circular(10.0)',
]);
});
testWidgets('LayoutChangedNotification test', (WidgetTester tester) async {
await tester.pumpWidget(
const Material(
child: NotifyMaterial(),
),
);
});
testWidgets('ListView scroll does not repaint', (WidgetTester tester) async {
final List<Size> log = <Size>[];
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Column(
children: <Widget>[
SizedBox(
width: 150.0,
height: 150.0,
child: CustomPaint(
painter: PaintRecorder(log),
),
),
Expanded(
child: Material(
child: Column(
children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
Container(
height: 2000.0,
color: const Color(0xFF00FF00),
),
],
),
),
SizedBox(
width: 100.0,
height: 100.0,
child: CustomPaint(
painter: PaintRecorder(log),
),
),
],
),
),
),
],
),
),
);
// We paint twice because we have two CustomPaint widgets in the tree above
// to test repainting both inside and outside the Material widget.
expect(log, equals(<Size>[
const Size(150.0, 150.0),
const Size(100.0, 100.0),
]));
log.clear();
await tester.drag(find.byType(ListView), const Offset(0.0, -300.0));
await tester.pump();
expect(log, isEmpty);
});
testWidgets('Shadows animate smoothly', (WidgetTester tester) async {
// This code verifies that the PhysicalModel's elevation animates over
// a kThemeChangeDuration time interval.
await tester.pumpWidget(buildMaterial());
final RenderPhysicalShape modelA = getModel(tester);
expect(modelA.elevation, equals(0.0));
await tester.pumpWidget(buildMaterial(elevation: 9.0));
final RenderPhysicalShape modelB = getModel(tester);
expect(modelB.elevation, equals(0.0));
await tester.pump(const Duration(milliseconds: 1));
final RenderPhysicalShape modelC = getModel(tester);
expect(modelC.elevation, moreOrLessEquals(0.0, epsilon: 0.001));
await tester.pump(kThemeChangeDuration ~/ 2);
final RenderPhysicalShape modelD = getModel(tester);
expect(modelD.elevation, isNot(moreOrLessEquals(0.0, epsilon: 0.001)));
await tester.pump(kThemeChangeDuration);
final RenderPhysicalShape modelE = getModel(tester);
expect(modelE.elevation, equals(9.0));
});
testWidgets('Shadow colors animate smoothly', (WidgetTester tester) async {
// This code verifies that the PhysicalModel's shadowColor animates over
// a kThemeChangeDuration time interval.
await tester.pumpWidget(buildMaterial());
final RenderPhysicalShape modelA = getModel(tester);
expect(modelA.shadowColor, equals(const Color(0xFF00FF00)));
await tester.pumpWidget(buildMaterial(shadowColor: const Color(0xFFFF0000)));
final RenderPhysicalShape modelB = getModel(tester);
expect(modelB.shadowColor, equals(const Color(0xFF00FF00)));
await tester.pump(const Duration(milliseconds: 1));
final RenderPhysicalShape modelC = getModel(tester);
expect(modelC.shadowColor, within<Color>(distance: 1, from: const Color(0xFF00FF00)));
await tester.pump(kThemeChangeDuration ~/ 2);
final RenderPhysicalShape modelD = getModel(tester);
expect(modelD.shadowColor, isNot(within<Color>(distance: 1, from: const Color(0xFF00FF00))));
await tester.pump(kThemeChangeDuration);
final RenderPhysicalShape modelE = getModel(tester);
expect(modelE.shadowColor, equals(const Color(0xFFFF0000)));
});
testWidgets('Transparent material widget does not absorb hit test', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/58665.
bool pressed = false;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Stack(
children: <Widget>[
ElevatedButton(
onPressed: () {
pressed = true;
},
child: null,
),
const Material(
type: MaterialType.transparency,
child: SizedBox(
width: 400.0,
height: 500.0,
),
),
],
),
),
),
);
await tester.tap(find.byType(ElevatedButton));
expect(pressed, isTrue);
});
group('Elevation Overlay', () {
testWidgets('applyElevationOverlayColor set to false does not change surface color', (WidgetTester tester) async {
const Color surfaceColor = Color(0xFF121212);
await tester.pumpWidget(Theme(
data: ThemeData(
applyElevationOverlayColor: false,
colorScheme: const ColorScheme.dark().copyWith(surface: surfaceColor),
),
child: buildMaterial(color: surfaceColor, elevation: 8.0),
));
final RenderPhysicalShape model = getModel(tester);
expect(model.color, equals(surfaceColor));
});
testWidgets('applyElevationOverlayColor set to true applies a semi-transparent onSurface color to the surface color', (WidgetTester tester) async {
const Color surfaceColor = Color(0xFF121212);
const Color onSurfaceColor = Colors.greenAccent;
// The colors we should get with a base surface color of 0xFF121212 for
// and a given elevation
const List<ElevationColor> elevationColors = <ElevationColor>[
ElevationColor(0.0, Color(0xFF121212)),
ElevationColor(1.0, Color(0xFF161D19)),
ElevationColor(2.0, Color(0xFF18211D)),
ElevationColor(3.0, Color(0xFF19241E)),
ElevationColor(4.0, Color(0xFF1A2620)),
ElevationColor(6.0, Color(0xFF1B2922)),
ElevationColor(8.0, Color(0xFF1C2C24)),
ElevationColor(12.0, Color(0xFF1D3027)),
ElevationColor(16.0, Color(0xFF1E3329)),
ElevationColor(24.0, Color(0xFF20362B)),
];
for (final ElevationColor test in elevationColors) {
await tester.pumpWidget(
Theme(
data: ThemeData(
applyElevationOverlayColor: true,
colorScheme: const ColorScheme.dark().copyWith(
surface: surfaceColor,
onSurface: onSurfaceColor,
),
),
child: buildMaterial(
color: surfaceColor,
elevation: test.elevation,
),
),
);
await tester.pumpAndSettle(); // wait for the elevation animation to finish
final RenderPhysicalShape model = getModel(tester);
expect(model.color, equals(test.color));
}
});
testWidgets('overlay will not apply to materials using a non-surface color', (WidgetTester tester) async {
await tester.pumpWidget(
Theme(
data: ThemeData(
applyElevationOverlayColor: true,
colorScheme: const ColorScheme.dark(),
),
child: buildMaterial(
color: Colors.cyan,
elevation: 8.0,
),
),
);
final RenderPhysicalShape model = getModel(tester);
// Shouldn't change, as it is not using a ColorScheme.surface color
expect(model.color, equals(Colors.cyan));
});
testWidgets('overlay will not apply to materials using a light theme', (WidgetTester tester) async {
await tester.pumpWidget(
Theme(
data: ThemeData(
applyElevationOverlayColor: true,
colorScheme: const ColorScheme.light(),
),
child: buildMaterial(
color: Colors.cyan,
elevation: 8.0,
),
),
);
final RenderPhysicalShape model = getModel(tester);
// Shouldn't change, as it was under a light color scheme.
expect(model.color, equals(Colors.cyan));
});
testWidgets('overlay will apply to materials with a non-opaque surface color', (WidgetTester tester) async {
const Color surfaceColor = Color(0xFF121212);
const Color surfaceColorWithOverlay = Color(0xC6353535);
await tester.pumpWidget(
Theme(
data: ThemeData(
applyElevationOverlayColor: true,
colorScheme: const ColorScheme.dark(),
),
child: buildMaterial(
color: surfaceColor.withOpacity(.75),
elevation: 8.0,
),
),
);
final RenderPhysicalShape model = getModel(tester);
expect(model.color, equals(surfaceColorWithOverlay));
expect(model.color, isNot(equals(surfaceColor)));
});
testWidgets('Expected overlay color can be computed using colorWithOverlay', (WidgetTester tester) async {
const Color surfaceColor = Color(0xFF123456);
const Color onSurfaceColor = Color(0xFF654321);
const double elevation = 8.0;
final Color surfaceColorWithOverlay =
ElevationOverlay.colorWithOverlay(surfaceColor, onSurfaceColor, elevation);
await tester.pumpWidget(
Theme(
data: ThemeData(
applyElevationOverlayColor: true,
colorScheme: const ColorScheme.dark(
surface: surfaceColor,
onSurface: onSurfaceColor,
),
),
child: buildMaterial(
color: surfaceColor,
elevation: elevation,
),
),
);
final RenderPhysicalShape model = getModel(tester);
expect(model.color, equals(surfaceColorWithOverlay));
expect(model.color, isNot(equals(surfaceColor)));
});
});
group('Transparency clipping', () {
testWidgets('No clip by default', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.transparency,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), hasNoImmediateClip);
});
testWidgets('clips to bounding rect by default given Clip.antiAlias', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.transparency,
clipBehavior: Clip.antiAlias,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), clipsWithBoundingRect);
});
testWidgets('clips to rounded rect when borderRadius provided given Clip.antiAlias', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.transparency,
borderRadius: const BorderRadius.all(Radius.circular(10.0)),
clipBehavior: Clip.antiAlias,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(
find.byKey(materialKey),
clipsWithBoundingRRect(
borderRadius: const BorderRadius.all(Radius.circular(10.0)),
),
);
});
testWidgets('clips to shape when provided given Clip.antiAlias', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.transparency,
shape: const StadiumBorder(),
clipBehavior: Clip.antiAlias,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(
find.byKey(materialKey),
clipsWithShapeBorder(
shape: const StadiumBorder(),
),
);
});
testWidgets('supports directional clips', (WidgetTester tester) async {
final List<String> logs = <String>[];
final ShapeBorder shape = TestBorder((String message) { logs.add(message); });
Widget buildMaterial() {
return Material(
type: MaterialType.transparency,
shape: shape,
clipBehavior: Clip.antiAlias,
child: const SizedBox(width: 100.0, height: 100.0),
);
}
final Widget material = buildMaterial();
// verify that a regular clip works as one would expect
logs.add('--0');
await tester.pumpWidget(material);
// verify that pumping again doesn't recompute the clip
// even though the widget itself is new (the shape doesn't change identity)
logs.add('--1');
await tester.pumpWidget(buildMaterial());
// verify that Material passes the TextDirection on to its shape when it's transparent
logs.add('--2');
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: material,
));
// verify that changing the text direction from LTR to RTL has an effect
// even though the widget itself is identical
logs.add('--3');
await tester.pumpWidget(Directionality(
textDirection: TextDirection.rtl,
child: material,
));
// verify that pumping again with a text direction has no effect
logs.add('--4');
await tester.pumpWidget(Directionality(
textDirection: TextDirection.rtl,
child: buildMaterial(),
));
logs.add('--5');
// verify that changing the text direction and the widget at the same time
// works as expected
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: material,
));
expect(logs, <String>[
'--0',
'getOuterPath Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) null',
'paint Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) null',
'--1',
'--2',
'getOuterPath Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) TextDirection.ltr',
'paint Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) TextDirection.ltr',
'--3',
'getOuterPath Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) TextDirection.rtl',
'paint Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) TextDirection.rtl',
'--4',
'--5',
'getOuterPath Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) TextDirection.ltr',
'paint Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) TextDirection.ltr',
]);
});
});
group('PhysicalModels', () {
testWidgets('canvas', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalModel(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.zero,
elevation: 0.0,
));
});
testWidgets('canvas with borderRadius and elevation', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
elevation: 1.0,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalModel(
shape: BoxShape.rectangle,
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
elevation: 1.0,
));
});
testWidgets('canvas with shape and elevation', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
shape: const StadiumBorder(),
elevation: 1.0,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalShape(
shape: const StadiumBorder(),
elevation: 1.0,
));
});
testWidgets('card', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.card,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalModel(
shape: BoxShape.rectangle,
borderRadius: const BorderRadius.all(Radius.circular(2.0)),
elevation: 0.0,
));
});
testWidgets('card with borderRadius and elevation', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.card,
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
elevation: 5.0,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalModel(
shape: BoxShape.rectangle,
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
elevation: 5.0,
));
});
testWidgets('card with shape and elevation', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.card,
shape: const StadiumBorder(),
elevation: 5.0,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalShape(
shape: const StadiumBorder(),
elevation: 5.0,
));
});
testWidgets('circle', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.circle,
color: const Color(0xFF0000FF),
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalModel(
shape: BoxShape.circle,
elevation: 0.0,
));
});
testWidgets('button', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.button,
color: const Color(0xFF0000FF),
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalModel(
shape: BoxShape.rectangle,
borderRadius: const BorderRadius.all(Radius.circular(2.0)),
elevation: 0.0,
));
});
testWidgets('button with elevation and borderRadius', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.button,
color: const Color(0xFF0000FF),
borderRadius: const BorderRadius.all(Radius.circular(6.0)),
elevation: 4.0,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalModel(
shape: BoxShape.rectangle,
borderRadius: const BorderRadius.all(Radius.circular(6.0)),
elevation: 4.0,
));
});
testWidgets('button with elevation and shape', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.button,
color: const Color(0xFF0000FF),
shape: const StadiumBorder(),
elevation: 4.0,
child: const SizedBox(width: 100.0, height: 100.0),
),
);
expect(find.byKey(materialKey), rendersOnPhysicalShape(
shape: const StadiumBorder(),
elevation: 4.0,
));
});
});
group('Border painting', () {
testWidgets('border is painted on physical layers', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.button,
color: const Color(0xFF0000FF),
shape: const CircleBorder(
side: BorderSide(
width: 2.0,
color: Color(0xFF0000FF),
),
),
child: const SizedBox(width: 100.0, height: 100.0),
),
);
final RenderBox box = tester.renderObject(find.byKey(materialKey));
expect(box, paints..circle());
});
testWidgets('border is painted for transparent material', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.transparency,
shape: const CircleBorder(
side: BorderSide(
width: 2.0,
color: Color(0xFF0000FF),
),
),
child: const SizedBox(width: 100.0, height: 100.0),
),
);
final RenderBox box = tester.renderObject(find.byKey(materialKey));
expect(box, paints..circle());
});
testWidgets('border is not painted for when border side is none', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.transparency,
shape: const CircleBorder(),
child: const SizedBox(width: 100.0, height: 100.0),
),
);
final RenderBox box = tester.renderObject(find.byKey(materialKey));
expect(box, isNot(paints..circle()));
});
testWidgets('border is painted above child by default', (WidgetTester tester) async {
final Key painterKey = UniqueKey();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: RepaintBoundary(
key: painterKey,
child: Card(
child: SizedBox(
width: 200,
height: 300,
child: Material(
clipBehavior: Clip.hardEdge,
shape: const RoundedRectangleBorder(
side: BorderSide(color: Colors.grey, width: 6),
borderRadius: BorderRadius.all(Radius.circular(8)),
),
child: Column(
children: <Widget>[
Container(
color: Colors.green,
height: 150,
),
],
),
),
),
),
),
),
));
await expectLater(
find.byKey(painterKey),
matchesGoldenFile('material.border_paint_above.png'),
);
});
testWidgets('border is painted below child when specified', (WidgetTester tester) async {
final Key painterKey = UniqueKey();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: RepaintBoundary(
key: painterKey,
child: Card(
child: SizedBox(
width: 200,
height: 300,
child: Material(
clipBehavior: Clip.hardEdge,
shape: const RoundedRectangleBorder(
side: BorderSide(color: Colors.grey, width: 6),
borderRadius: BorderRadius.all(Radius.circular(8)),
),
borderOnForeground: false,
child: Column(
children: <Widget>[
Container(
color: Colors.green,
height: 150,
),
],
),
),
),
),
),
),
));
await expectLater(
find.byKey(painterKey),
matchesGoldenFile('material.border_paint_below.png'),
);
});
});
}