|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import 'package:flutter/foundation.dart';
|
| 6 | +import 'package:flutter/gestures.dart'; |
6 | 7 | import 'package:flutter/material.dart';
|
7 | 8 | import 'package:flutter_test/flutter_test.dart';
|
8 | 9 |
|
| 10 | +import '../rendering/mock_canvas.dart'; |
| 11 | + |
9 | 12 | void main() {
|
10 | 13 | testWidgets('Navigation bar updates destinations when tapped', (WidgetTester tester) async {
|
11 | 14 | int mutatedIndex = -1;
|
@@ -553,6 +556,122 @@ void main() {
|
553 | 556 |
|
554 | 557 | expect(newHeight, equals(initialHeight));
|
555 | 558 | });
|
| 559 | + |
| 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 | + ); |
| 577 | + |
| 578 | + await tester.pumpWidget(widget); |
| 579 | + |
| 580 | + final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); |
| 581 | + await gesture.addPointer(); |
| 582 | + await gesture.moveTo(tester.getCenter(find.byIcon(Icons.access_alarm))); |
| 583 | + await tester.pumpAndSettle(); |
| 584 | + |
| 585 | + final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures'); |
| 586 | + const Offset indicatorCenter = Offset(600, 30); |
| 587 | + const Size includedIndicatorSize = Size(64, 32); |
| 588 | + const Size excludedIndicatorSize = Size(74, 40); |
| 589 | + expect( |
| 590 | + inkFeatures, |
| 591 | + paints |
| 592 | + ..clipPath( |
| 593 | + pathMatcher: isPathThat( |
| 594 | + includes: <Offset>[ |
| 595 | + // Left center. |
| 596 | + Offset(indicatorCenter.dx - (includedIndicatorSize.width / 2), indicatorCenter.dy), |
| 597 | + // Top center. |
| 598 | + Offset(indicatorCenter.dx, indicatorCenter.dy - (includedIndicatorSize.height / 2)), |
| 599 | + // Right center. |
| 600 | + Offset(indicatorCenter.dx + (includedIndicatorSize.width / 2), indicatorCenter.dy), |
| 601 | + // Bottom center. |
| 602 | + Offset(indicatorCenter.dx, indicatorCenter.dy + (includedIndicatorSize.height / 2)), |
| 603 | + ], |
| 604 | + excludes: <Offset>[ |
| 605 | + // Left center. |
| 606 | + Offset(indicatorCenter.dx - (excludedIndicatorSize.width / 2), indicatorCenter.dy), |
| 607 | + // Top center. |
| 608 | + Offset(indicatorCenter.dx, indicatorCenter.dy - (excludedIndicatorSize.height / 2)), |
| 609 | + // Right center. |
| 610 | + Offset(indicatorCenter.dx + (excludedIndicatorSize.width / 2), indicatorCenter.dy), |
| 611 | + // Bottom center. |
| 612 | + Offset(indicatorCenter.dx, indicatorCenter.dy + (excludedIndicatorSize.height / 2)), |
| 613 | + ], |
| 614 | + ), |
| 615 | + ) |
| 616 | + ..circle( |
| 617 | + x: indicatorCenter.dx, |
| 618 | + y: indicatorCenter.dy, |
| 619 | + radius: 35.0, |
| 620 | + color: const Color(0x0a000000), |
| 621 | + ) |
| 622 | + ); |
| 623 | + }); |
| 624 | + |
| 625 | + testWidgets('Navigation indicator scale transform', (WidgetTester tester) async { |
| 626 | + int selectedIndex = 0; |
| 627 | + |
| 628 | + Widget buildNavigationBar() { |
| 629 | + return MaterialApp( |
| 630 | + theme: ThemeData.light(), |
| 631 | + home: Scaffold( |
| 632 | + bottomNavigationBar: Center( |
| 633 | + child: NavigationBar( |
| 634 | + selectedIndex: selectedIndex, |
| 635 | + destinations: const <Widget>[ |
| 636 | + NavigationDestination( |
| 637 | + icon: Icon(Icons.ac_unit), |
| 638 | + label: 'AC', |
| 639 | + ), |
| 640 | + NavigationDestination( |
| 641 | + icon: Icon(Icons.access_alarm), |
| 642 | + label: 'Alarm', |
| 643 | + ), |
| 644 | + ], |
| 645 | + onDestinationSelected: (int i) { }, |
| 646 | + ), |
| 647 | + ), |
| 648 | + ), |
| 649 | + ); |
| 650 | + } |
| 651 | + |
| 652 | + await tester.pumpWidget(buildNavigationBar()); |
| 653 | + await tester.pumpAndSettle(); |
| 654 | + final Finder transformFinder = find.descendant( |
| 655 | + of: find.byType(NavigationIndicator), |
| 656 | + matching: find.byType(Transform), |
| 657 | + ).last; |
| 658 | + Matrix4 transform = tester.widget<Transform>(transformFinder).transform; |
| 659 | + expect(transform.getColumn(0)[0], 0.0); |
| 660 | + |
| 661 | + selectedIndex = 1; |
| 662 | + await tester.pumpWidget(buildNavigationBar()); |
| 663 | + await tester.pump(const Duration(milliseconds: 100)); |
| 664 | + transform = tester.widget<Transform>(transformFinder).transform; |
| 665 | + expect(transform.getColumn(0)[0], closeTo(0.7805849514007568, precisionErrorTolerance)); |
| 666 | + |
| 667 | + await tester.pump(const Duration(milliseconds: 100)); |
| 668 | + transform = tester.widget<Transform>(transformFinder).transform; |
| 669 | + expect(transform.getColumn(0)[0], closeTo(0.9473570239543915, precisionErrorTolerance)); |
| 670 | + |
| 671 | + await tester.pumpAndSettle(); |
| 672 | + transform = tester.widget<Transform>(transformFinder).transform; |
| 673 | + expect(transform.getColumn(0)[0], 1.0); |
| 674 | + }); |
556 | 675 | }
|
557 | 676 |
|
558 | 677 | Widget _buildWidget(Widget child) {
|
|
0 commit comments