@@ -558,34 +558,165 @@ void main() {
558
558
});
559
559
560
560
testWidgets ('Navigation indicator renders ripple' , (WidgetTester tester) async {
561
- final Widget widget = _buildWidget (
562
- NavigationBar (
563
- destinations: const < Widget > [
564
- NavigationDestination (
565
- icon: Icon (Icons .ac_unit),
566
- label: 'AC' ,
567
- ),
568
- NavigationDestination (
569
- icon: Icon (Icons .access_alarm),
570
- label: 'Alarm' ,
571
- ),
572
- ],
573
- onDestinationSelected: (int i) {
574
- },
575
- ),
576
- );
561
+ // This is a regression test for https://github.com/flutter/flutter/issues/116751.
562
+ int selectedIndex = 0 ;
577
563
578
- await tester.pumpWidget (widget);
564
+ Widget buildWidget ({ NavigationDestinationLabelBehavior ? labelBehavior }) {
565
+ return _buildWidget (
566
+ NavigationBar (
567
+ selectedIndex: selectedIndex,
568
+ labelBehavior: labelBehavior,
569
+ destinations: const < Widget > [
570
+ NavigationDestination (
571
+ icon: Icon (Icons .ac_unit),
572
+ label: 'AC' ,
573
+ ),
574
+ NavigationDestination (
575
+ icon: Icon (Icons .access_alarm),
576
+ label: 'Alarm' ,
577
+ ),
578
+ ],
579
+ onDestinationSelected: (int i) { },
580
+ ),
581
+ );
582
+ }
583
+
584
+ await tester.pumpWidget (buildWidget ());
579
585
580
586
final TestGesture gesture = await tester.createGesture (kind: PointerDeviceKind .mouse);
581
587
await gesture.addPointer ();
582
588
await gesture.moveTo (tester.getCenter (find.byIcon (Icons .access_alarm)));
583
589
await tester.pumpAndSettle ();
584
590
585
591
final RenderObject inkFeatures = tester.allRenderObjects.firstWhere ((RenderObject object) => object.runtimeType.toString () == '_RenderInkFeatures' );
586
- const Offset indicatorCenter = Offset (600 , 30 );
592
+ Offset indicatorCenter = const Offset (600 , 30 );
587
593
const Size includedIndicatorSize = Size (64 , 32 );
588
594
const Size excludedIndicatorSize = Size (74 , 40 );
595
+
596
+ // Test ripple when NavigationBar is using `NavigationDestinationLabelBehavior.alwaysShow` (default).
597
+ expect (
598
+ inkFeatures,
599
+ paints
600
+ ..clipPath (
601
+ pathMatcher: isPathThat (
602
+ includes: < Offset > [
603
+ // Left center.
604
+ Offset (indicatorCenter.dx - (includedIndicatorSize.width / 2 ), indicatorCenter.dy),
605
+ // Top center.
606
+ Offset (indicatorCenter.dx, indicatorCenter.dy - (includedIndicatorSize.height / 2 )),
607
+ // Right center.
608
+ Offset (indicatorCenter.dx + (includedIndicatorSize.width / 2 ), indicatorCenter.dy),
609
+ // Bottom center.
610
+ Offset (indicatorCenter.dx, indicatorCenter.dy + (includedIndicatorSize.height / 2 )),
611
+ ],
612
+ excludes: < Offset > [
613
+ // Left center.
614
+ Offset (indicatorCenter.dx - (excludedIndicatorSize.width / 2 ), indicatorCenter.dy),
615
+ // Top center.
616
+ Offset (indicatorCenter.dx, indicatorCenter.dy - (excludedIndicatorSize.height / 2 )),
617
+ // Right center.
618
+ Offset (indicatorCenter.dx + (excludedIndicatorSize.width / 2 ), indicatorCenter.dy),
619
+ // Bottom center.
620
+ Offset (indicatorCenter.dx, indicatorCenter.dy + (excludedIndicatorSize.height / 2 )),
621
+ ],
622
+ ),
623
+ )
624
+ ..circle (
625
+ x: indicatorCenter.dx,
626
+ y: indicatorCenter.dy,
627
+ radius: 35.0 ,
628
+ color: const Color (0x0a000000 ),
629
+ )
630
+ );
631
+
632
+ // Test ripple when NavigationBar is using `NavigationDestinationLabelBehavior.alwaysHide`.
633
+ await tester.pumpWidget (buildWidget (labelBehavior: NavigationDestinationLabelBehavior .alwaysHide));
634
+ await gesture.moveTo (tester.getCenter (find.byIcon (Icons .access_alarm)));
635
+ await tester.pumpAndSettle ();
636
+
637
+ indicatorCenter = const Offset (600 , 40 );
638
+
639
+ expect (
640
+ inkFeatures,
641
+ paints
642
+ ..clipPath (
643
+ pathMatcher: isPathThat (
644
+ includes: < Offset > [
645
+ // Left center.
646
+ Offset (indicatorCenter.dx - (includedIndicatorSize.width / 2 ), indicatorCenter.dy),
647
+ // Top center.
648
+ Offset (indicatorCenter.dx, indicatorCenter.dy - (includedIndicatorSize.height / 2 )),
649
+ // Right center.
650
+ Offset (indicatorCenter.dx + (includedIndicatorSize.width / 2 ), indicatorCenter.dy),
651
+ // Bottom center.
652
+ Offset (indicatorCenter.dx, indicatorCenter.dy + (includedIndicatorSize.height / 2 )),
653
+ ],
654
+ excludes: < Offset > [
655
+ // Left center.
656
+ Offset (indicatorCenter.dx - (excludedIndicatorSize.width / 2 ), indicatorCenter.dy),
657
+ // Top center.
658
+ Offset (indicatorCenter.dx, indicatorCenter.dy - (excludedIndicatorSize.height / 2 )),
659
+ // Right center.
660
+ Offset (indicatorCenter.dx + (excludedIndicatorSize.width / 2 ), indicatorCenter.dy),
661
+ // Bottom center.
662
+ Offset (indicatorCenter.dx, indicatorCenter.dy + (excludedIndicatorSize.height / 2 )),
663
+ ],
664
+ ),
665
+ )
666
+ ..circle (
667
+ x: indicatorCenter.dx,
668
+ y: indicatorCenter.dy,
669
+ radius: 35.0 ,
670
+ color: const Color (0x0a000000 ),
671
+ )
672
+ );
673
+
674
+ // Test ripple when NavigationBar is using `NavigationDestinationLabelBehavior.onlyShowSelected`.
675
+ await tester.pumpWidget (buildWidget (labelBehavior: NavigationDestinationLabelBehavior .onlyShowSelected));
676
+ await gesture.moveTo (tester.getCenter (find.byIcon (Icons .access_alarm)));
677
+ await tester.pumpAndSettle ();
678
+
679
+ expect (
680
+ inkFeatures,
681
+ paints
682
+ ..clipPath (
683
+ pathMatcher: isPathThat (
684
+ includes: < Offset > [
685
+ // Left center.
686
+ Offset (indicatorCenter.dx - (includedIndicatorSize.width / 2 ), indicatorCenter.dy),
687
+ // Top center.
688
+ Offset (indicatorCenter.dx, indicatorCenter.dy - (includedIndicatorSize.height / 2 )),
689
+ // Right center.
690
+ Offset (indicatorCenter.dx + (includedIndicatorSize.width / 2 ), indicatorCenter.dy),
691
+ // Bottom center.
692
+ Offset (indicatorCenter.dx, indicatorCenter.dy + (includedIndicatorSize.height / 2 )),
693
+ ],
694
+ excludes: < Offset > [
695
+ // Left center.
696
+ Offset (indicatorCenter.dx - (excludedIndicatorSize.width / 2 ), indicatorCenter.dy),
697
+ // Top center.
698
+ Offset (indicatorCenter.dx, indicatorCenter.dy - (excludedIndicatorSize.height / 2 )),
699
+ // Right center.
700
+ Offset (indicatorCenter.dx + (excludedIndicatorSize.width / 2 ), indicatorCenter.dy),
701
+ // Bottom center.
702
+ Offset (indicatorCenter.dx, indicatorCenter.dy + (excludedIndicatorSize.height / 2 )),
703
+ ],
704
+ ),
705
+ )
706
+ ..circle (
707
+ x: indicatorCenter.dx,
708
+ y: indicatorCenter.dy,
709
+ radius: 35.0 ,
710
+ color: const Color (0x0a000000 ),
711
+ )
712
+ );
713
+
714
+ // Make sure ripple is shifted when selectedIndex changes.
715
+ selectedIndex = 1 ;
716
+ await tester.pumpWidget (buildWidget (labelBehavior: NavigationDestinationLabelBehavior .onlyShowSelected));
717
+ await tester.pumpAndSettle ();
718
+ indicatorCenter = const Offset (600 , 30 );
719
+
589
720
expect (
590
721
inkFeatures,
591
722
paints
0 commit comments