22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ // This file is run as part of a reduced test set in CI on Mac and Windows
6+ // machines.
7+ @Tags (< String > ['reduced-test-set' ])
8+ library ;
9+
10+ import 'package:flutter/foundation.dart' ;
511import 'package:flutter/material.dart' ;
612import 'package:flutter/services.dart' ;
713import 'package:flutter_test/flutter_test.dart' ;
@@ -51,8 +57,7 @@ void main() {
5157 expect (tester.getSize (find.byType (Ink )), const Size (800 , height));
5258 });
5359
54- testWidgets ('The InkWell widget renders an ink splash' , (WidgetTester tester) async {
55- const Color highlightColor = Color (0xAAFF0000 );
60+ testWidgets ('Material2 - InkWell widget renders an ink splash' , (WidgetTester tester) async {
5661 const Color splashColor = Color (0xAA0000FF );
5762 const BorderRadius borderRadius = BorderRadius .all (Radius .circular (6.0 ));
5863
@@ -66,7 +71,6 @@ void main() {
6671 height: 60.0 ,
6772 child: InkWell (
6873 borderRadius: borderRadius,
69- highlightColor: highlightColor,
7074 splashColor: splashColor,
7175 onTap: () { },
7276 ),
@@ -91,15 +95,77 @@ void main() {
9195 ..clipRRect (rrect: RRect .fromLTRBR (0.0 , 0.0 , 200.0 , 60.0 , const Radius .circular (6.0 )))
9296 ..circle (x: 100.0 , y: 30.0 , radius: 21.0 , color: splashColor)
9397 ..restore ()
94- ..rrect (
95- rrect: RRect .fromLTRBR (300.0 , 270.0 , 500.0 , 330.0 , const Radius .circular (6.0 )),
96- color: highlightColor,
97- ),
9898 );
9999
100100 await gesture.up ();
101101 });
102102
103+ testWidgets ('Material3 - InkWell widget renders an ink splash' , (WidgetTester tester) async {
104+ const Key inkWellKey = Key ('InkWell' );
105+ const Color splashColor = Color (0xAA0000FF );
106+ const BorderRadius borderRadius = BorderRadius .all (Radius .circular (6.0 ));
107+
108+ await tester.pumpWidget (
109+ MaterialApp (
110+ home: Material (
111+ child: Center (
112+ child: SizedBox (
113+ width: 200.0 ,
114+ height: 60.0 ,
115+ child: InkWell (
116+ key: inkWellKey,
117+ borderRadius: borderRadius,
118+ splashColor: splashColor,
119+ onTap: () { },
120+ ),
121+ ),
122+ ),
123+ ),
124+ ),
125+ );
126+
127+ final Offset center = tester.getCenter (find.byType (InkWell ));
128+ final TestGesture gesture = await tester.startGesture (center);
129+ await tester.pump (); // start gesture
130+ await tester.pump (const Duration (milliseconds: 200 )); // wait for splash to be well under way
131+
132+ final RenderBox box = Material .of (tester.element (find.byType (InkWell ))) as RenderBox ;
133+ if (kIsWeb && isCanvasKit) {
134+ expect (
135+ box,
136+ paints
137+ ..save ()
138+ ..translate (x: 0.0 , y: 0.0 )
139+ ..clipRect ()
140+ ..save ()
141+ ..translate (x: 300.0 , y: 270.0 )
142+ ..clipRRect (rrect: RRect .fromLTRBR (0.0 , 0.0 , 200.0 , 60.0 , const Radius .circular (6.0 )))
143+ ..circle ()
144+ ..restore ()
145+ );
146+ } else {
147+ expect (
148+ box,
149+ paints
150+ ..translate (x: 0.0 , y: 0.0 )
151+ ..save ()
152+ ..translate (x: 300.0 , y: 270.0 )
153+ ..clipRRect (rrect: RRect .fromLTRBR (0.0 , 0.0 , 200.0 , 60.0 , const Radius .circular (6.0 )))
154+ ..rect (rect: const Rect .fromLTRB (0.0 , 0.0 , 200 , 60 ))
155+ ..restore ()
156+ );
157+ }
158+
159+ // Material 3 uses the InkSparkle which uses a shader, so we can't capture
160+ // the effect with paint methods. Use a golden test instead.
161+ await expectLater (
162+ find.byKey (inkWellKey),
163+ matchesGoldenFile ('m3_ink_well.renders.ink_splash.png' ),
164+ );
165+
166+ await gesture.up ();
167+ }, skip: kIsWeb && ! isCanvasKit); // https://github.com/flutter/flutter/issues/99933
168+
103169 testWidgets ('The InkWell widget renders an ink ripple' , (WidgetTester tester) async {
104170 const Color highlightColor = Color (0xAAFF0000 );
105171 const Color splashColor = Color (0xB40000FF );
@@ -186,7 +252,7 @@ void main() {
186252 expect (box, ripplePattern (inkWellCenter - tapDownOffset, 105.0 , 0 ));
187253 });
188254
189- testWidgets ('Does the Ink widget render anything' , (WidgetTester tester) async {
255+ testWidgets ('Material2 - Does the Ink widget render anything' , (WidgetTester tester) async {
190256 await tester.pumpWidget (
191257 MaterialApp (
192258 theme: ThemeData (useMaterial3: false ),
@@ -269,6 +335,94 @@ void main() {
269335 await gesture.up ();
270336 });
271337
338+ testWidgets ('Material3 - Does the Ink widget render anything' , (WidgetTester tester) async {
339+ const Key inkWellKey = Key ('InkWell' );
340+ await tester.pumpWidget (
341+ MaterialApp (
342+ home: Material (
343+ child: Center (
344+ child: Ink (
345+ color: Colors .blue,
346+ width: 200.0 ,
347+ height: 200.0 ,
348+ child: InkWell (
349+ key: inkWellKey,
350+ splashColor: Colors .green,
351+ onTap: () { },
352+ ),
353+ ),
354+ ),
355+ ),
356+ ),
357+ );
358+
359+ final Offset center = tester.getCenter (find.byType (InkWell ));
360+ final TestGesture gesture = await tester.startGesture (center);
361+ await tester.pump (); // start gesture
362+ await tester.pump (const Duration (milliseconds: 200 )); // wait for splash to be well under way
363+
364+ final RenderBox box = Material .of (tester.element (find.byType (InkWell )))as RenderBox ;
365+ expect (box, paints..rect (rect: const Rect .fromLTRB (300.0 , 200.0 , 500.0 , 400.0 ), color: Color (Colors .blue.value)));
366+
367+ // Material 3 uses the InkSparkle which uses a shader, so we can't capture
368+ // the effect with paint methods. Use a golden test instead.
369+ await expectLater (
370+ find.byKey (inkWellKey),
371+ matchesGoldenFile ('m3_ink.renders.anything.0.png' ),
372+ );
373+
374+ await tester.pumpWidget (
375+ MaterialApp (
376+ home: Material (
377+ child: Center (
378+ child: Ink (
379+ color: Colors .red,
380+ width: 200.0 ,
381+ height: 200.0 ,
382+ child: InkWell (
383+ key: inkWellKey,
384+ splashColor: Colors .green,
385+ onTap: () { },
386+ ),
387+ ),
388+ ),
389+ ),
390+ ),
391+ );
392+
393+ expect (Material .of (tester.element (find.byType (InkWell ))), same (box));
394+
395+ expect (box, paints..rect (rect: const Rect .fromLTRB (300.0 , 200.0 , 500.0 , 400.0 ), color: Color (Colors .red.value)));
396+
397+ // Material 3 uses the InkSparkle which uses a shader, so we can't capture
398+ // the effect with paint methods. Use a golden test instead.
399+ await expectLater (
400+ find.byKey (inkWellKey),
401+ matchesGoldenFile ('m3_ink.renders.anything.1.png' ),
402+ );
403+
404+ await tester.pumpWidget (
405+ MaterialApp (
406+ home: Material (
407+ child: Center (
408+ child: InkWell ( // This is at a different depth in the tree so it's now a new InkWell.
409+ key: inkWellKey,
410+ splashColor: Colors .green,
411+ onTap: () { },
412+ ),
413+ ),
414+ ),
415+ ),
416+ );
417+
418+ expect (Material .of (tester.element (find.byType (InkWell ))), same (box));
419+
420+ expect (box, isNot (paints..rect ()));
421+ expect (box, isNot (paints..rect ()));
422+
423+ await gesture.up ();
424+ });
425+
272426 testWidgets ('The InkWell widget renders an SelectAction or ActivateAction-induced ink ripple' , (WidgetTester tester) async {
273427 const Color highlightColor = Color (0xAAFF0000 );
274428 const Color splashColor = Color (0xB40000FF );
@@ -517,7 +671,7 @@ void main() {
517671 expect (tester.takeException (), isNull);
518672 });
519673
520- testWidgets ('Custom rectCallback renders an ink splash from its center' , (WidgetTester tester) async {
674+ testWidgets ('Material2 - Custom rectCallback renders an ink splash from its center' , (WidgetTester tester) async {
521675 const Color splashColor = Color (0xff00ff00 );
522676
523677 Widget buildWidget ({InteractiveInkFeatureFactory ? splashFactory}) {
@@ -572,6 +726,62 @@ void main() {
572726 );
573727 });
574728
729+ testWidgets ('Material3 - Custom rectCallback renders an ink splash from its center' , (WidgetTester tester) async {
730+ const Key inkWResponseKey = Key ('InkResponse' );
731+ const Color splashColor = Color (0xff00ff00 );
732+
733+ Widget buildWidget ({InteractiveInkFeatureFactory ? splashFactory}) {
734+ return MaterialApp (
735+ home: Material (
736+ child: Center (
737+ child: SizedBox (
738+ width: 100.0 ,
739+ height: 200.0 ,
740+ child: InkResponse (
741+ key: inkWResponseKey,
742+ splashColor: splashColor,
743+ containedInkWell: true ,
744+ highlightShape: BoxShape .rectangle,
745+ splashFactory: splashFactory,
746+ onTap: () { },
747+ ),
748+ ),
749+ ),
750+ ),
751+ );
752+ }
753+
754+ await tester.pumpWidget (buildWidget ());
755+
756+ final Offset center = tester.getCenter (find.byType (SizedBox ));
757+ TestGesture gesture = await tester.startGesture (center);
758+ await tester.pump (); // start gesture
759+ await tester.pumpAndSettle (); // Finish rendering ink splash.
760+
761+ // Material 3 uses the InkSparkle which uses a shader, so we can't capture
762+ // the effect with paint methods. Use a golden test instead.
763+ await expectLater (
764+ find.byKey (inkWResponseKey),
765+ matchesGoldenFile ('m3_ink_response.renders.ink_splash_from_its_center.0.png' ),
766+ );
767+
768+ await gesture.up ();
769+
770+ await tester.pumpWidget (buildWidget (splashFactory: _InkRippleFactory ()));
771+ await tester.pumpAndSettle (); // Finish rendering ink splash.
772+
773+ gesture = await tester.startGesture (center);
774+ await tester.pump (); // start gesture
775+ await tester.pumpAndSettle (); // Finish rendering ink splash.
776+
777+ // Material 3 uses the InkSparkle which uses a shader, so we can't capture
778+ // the effect with paint methods. Use a golden test instead.
779+ await expectLater (
780+ find.byKey (inkWResponseKey),
781+ matchesGoldenFile ('m3_ink_response.renders.ink_splash_from_its_center.1.png' ),
782+ );
783+ });
784+
575785 testWidgets ('Ink with isVisible=false does not paint' , (WidgetTester tester) async {
576786 const Color testColor = Color (0xffff1234 );
577787 Widget inkWidget ({required bool isVisible}) {
0 commit comments