@@ -445,4 +445,90 @@ void main() {
445445 throw 'Expected: paint.color.alpha == 0, found: ${paint .color .alpha }' ;
446446 }));
447447 });
448+
449+ testWidgets ('Custom rectCallback renders an ink splash from its center' , (WidgetTester tester) async {
450+ const Color splashColor = Color (0xff00ff00 );
451+
452+ Widget buildWidget ({InteractiveInkFeatureFactory ? splashFactory}) {
453+ return Directionality (
454+ textDirection: TextDirection .ltr,
455+ child: Material (
456+ child: Center (
457+ child: SizedBox (
458+ width: 100.0 ,
459+ height: 200.0 ,
460+ child: InkResponse (
461+ splashColor: splashColor,
462+ containedInkWell: true ,
463+ highlightShape: BoxShape .rectangle,
464+ splashFactory: splashFactory,
465+ onTap: () { },
466+ ),
467+ ),
468+ ),
469+ ),
470+ );
471+ }
472+
473+ await tester.pumpWidget (buildWidget ());
474+
475+ final Offset center = tester.getCenter (find.byType (SizedBox ));
476+ TestGesture gesture = await tester.startGesture (center);
477+ await tester.pump (); // start gesture
478+ await tester.pumpAndSettle (); // Finish rendering ink splash.
479+
480+ RenderBox box = Material .of (tester.element (find.byType (InkResponse ))) as RenderBox ;
481+ expect (
482+ box,
483+ paints
484+ ..circle (x: 50.0 , y: 100.0 , color: splashColor)
485+ );
486+
487+ await gesture.up ();
488+
489+ await tester.pumpWidget (buildWidget (splashFactory: _InkRippleFactory ()));
490+ await tester.pumpAndSettle (); // Finish rendering ink splash.
491+
492+ gesture = await tester.startGesture (center);
493+ await tester.pump (); // start gesture
494+ await tester.pumpAndSettle (); // Finish rendering ink splash.
495+
496+ box = Material .of (tester.element (find.byType (InkResponse ))) as RenderBox ;
497+ expect (
498+ box,
499+ paints
500+ ..circle (x: 50.0 , y: 50.0 , color: splashColor)
501+ );
502+ });
503+ }
504+
505+ class _InkRippleFactory extends InteractiveInkFeatureFactory {
506+ @override
507+ InteractiveInkFeature create ({
508+ required MaterialInkController controller,
509+ required RenderBox referenceBox,
510+ required Offset position,
511+ required Color color,
512+ required TextDirection textDirection,
513+ bool containedInkWell = false ,
514+ RectCallback ? rectCallback,
515+ BorderRadius ? borderRadius,
516+ ShapeBorder ? customBorder,
517+ double ? radius,
518+ VoidCallback ? onRemoved,
519+ }) {
520+ return InkRipple (
521+ controller: controller,
522+ referenceBox: referenceBox,
523+ position: position,
524+ color: color,
525+ containedInkWell: containedInkWell,
526+ rectCallback: () => Offset .zero & const Size (100 , 100 ),
527+ borderRadius: borderRadius,
528+ customBorder: customBorder,
529+ radius: radius,
530+ onRemoved: onRemoved,
531+ textDirection: textDirection,
532+ );
533+ }
448534}
0 commit comments