@@ -144,7 +144,7 @@ void main() {
144
144
expect (find.byType (ExpandIcon ), findsOneWidget);
145
145
await tester.tap (find.byType (ExpandIcon ));
146
146
expect (capturedIndex, 0 );
147
- expect (capturedIsExpanded, isFalse );
147
+ expect (capturedIsExpanded, isTrue );
148
148
box = tester.renderObject (find.byType (ExpansionPanelList ));
149
149
expect (box.size.height, equals (oldHeight));
150
150
@@ -556,7 +556,7 @@ void main() {
556
556
// Callback is invoked once with appropriate arguments
557
557
expect (callbackHistory.length, equals (1 ));
558
558
expect (callbackHistory.last['index' ], equals (1 ));
559
- expect (callbackHistory.last['isExpanded' ], equals (false ));
559
+ expect (callbackHistory.last['isExpanded' ], equals (true ));
560
560
561
561
// Close the same panel
562
562
await tester.tap (find.byType (ExpandIcon ).at (1 ));
@@ -565,7 +565,7 @@ void main() {
565
565
// Callback is invoked once with appropriate arguments
566
566
expect (callbackHistory.length, equals (2 ));
567
567
expect (callbackHistory.last['index' ], equals (1 ));
568
- expect (callbackHistory.last['isExpanded' ], equals (true ));
568
+ expect (callbackHistory.last['isExpanded' ], equals (false ));
569
569
});
570
570
571
571
testWidgets ('Radio mode calls expansionCallback twice if other panel open prior' , (WidgetTester tester) async {
@@ -630,7 +630,7 @@ void main() {
630
630
expect (callbackHistory.length, equals (1 ));
631
631
callbackResults = callbackHistory[callbackHistory.length - 1 ];
632
632
expect (callbackResults['index' ], equals (1 ));
633
- expect (callbackResults['isExpanded' ], equals (false ));
633
+ expect (callbackResults['isExpanded' ], equals (true ));
634
634
635
635
// Close a different panel
636
636
await tester.tap (find.byType (ExpandIcon ).at (2 ));
@@ -639,13 +639,108 @@ void main() {
639
639
// Callback is invoked the first time with correct arguments
640
640
expect (callbackHistory.length, equals (3 ));
641
641
callbackResults = callbackHistory[callbackHistory.length - 2 ];
642
- expect (callbackResults['index' ], equals (2 ));
642
+ expect (callbackResults['index' ], equals (1 ));
643
643
expect (callbackResults['isExpanded' ], equals (false ));
644
644
645
645
// Callback is invoked the second time with correct arguments
646
646
callbackResults = callbackHistory[callbackHistory.length - 1 ];
647
- expect (callbackResults['index' ], equals (1 ));
648
- expect (callbackResults['isExpanded' ], equals (false ));
647
+ expect (callbackResults['index' ], equals (2 ));
648
+ expect (callbackResults['isExpanded' ], equals (true ));
649
+ });
650
+
651
+ testWidgets ('ExpansionPanelList.radio callback displays true or false based on the visibility of a list item' , (WidgetTester tester) async {
652
+ late int lastExpanded;
653
+ bool topElementExpanded = false ;
654
+ bool bottomElementExpanded = false ;
655
+
656
+ final List <ExpansionPanel > demoItemsRadio = < ExpansionPanelRadio > [
657
+ // topElement
658
+ ExpansionPanelRadio (
659
+ headerBuilder: (BuildContext context, bool isExpanded) {
660
+ return Text (isExpanded ? 'B' : 'A' );
661
+ },
662
+ body: const SizedBox (height: 100.0 ),
663
+ value: 0 ,
664
+ ),
665
+ // bottomElement
666
+ ExpansionPanelRadio (
667
+ headerBuilder: (BuildContext context, bool isExpanded) {
668
+ return Text (isExpanded ? 'D' : 'C' );
669
+ },
670
+ body: const SizedBox (height: 100.0 ),
671
+ value: 1 ,
672
+ ),
673
+ ];
674
+
675
+ final ExpansionPanelList expansionListRadio = ExpansionPanelList .radio (
676
+ children: demoItemsRadio,
677
+ expansionCallback: (int index, bool isExpanded)
678
+ {
679
+ lastExpanded = index;
680
+ if (index == 0 )
681
+ {
682
+ topElementExpanded = isExpanded;
683
+ bottomElementExpanded = false ;
684
+ }
685
+ else
686
+ {
687
+ topElementExpanded = false ;
688
+ bottomElementExpanded = isExpanded;
689
+ }
690
+ }
691
+ );
692
+
693
+ await tester.pumpWidget (
694
+ MaterialApp (
695
+ home: SingleChildScrollView (
696
+ child: expansionListRadio,
697
+ ),
698
+ ),
699
+ );
700
+
701
+ // Initializes with all panels closed.
702
+ expect (find.text ('A' ), findsOneWidget);
703
+ expect (find.text ('B' ), findsNothing);
704
+ expect (find.text ('C' ), findsOneWidget);
705
+ expect (find.text ('D' ), findsNothing);
706
+
707
+ await tester.tap (find.byType (ExpandIcon ).at (0 ));
708
+ await tester.pump (const Duration (milliseconds: 200 ));
709
+ await tester.pumpAndSettle ();
710
+
711
+ // Now the first panel is open.
712
+ expect (find.text ('A' ), findsNothing);
713
+ expect (find.text ('B' ), findsOneWidget);
714
+ expect (find.text ('C' ), findsOneWidget);
715
+ expect (find.text ('D' ), findsNothing);
716
+
717
+ expect (lastExpanded,0 );
718
+ expect (topElementExpanded,true );
719
+
720
+ await tester.tap (find.byType (ExpandIcon ).at (1 ));
721
+ await tester.pump (const Duration (milliseconds: 200 ));
722
+ await tester.pumpAndSettle ();
723
+
724
+ // Open the other panel and ensure the first is now closed.
725
+ expect (lastExpanded,1 );
726
+ expect (bottomElementExpanded,true );
727
+ expect (topElementExpanded,false );
728
+ expect (find.text ('D' ), findsOneWidget);
729
+ expect (find.text ('A' ), findsOneWidget);
730
+
731
+ await tester.tap (find.byType (ExpandIcon ).at (1 ));
732
+ await tester.pump (const Duration (milliseconds: 200 ));
733
+ await tester.pumpAndSettle ();
734
+
735
+ // Close the item that was expanded should now be false.
736
+ expect (lastExpanded,1 );
737
+ expect (bottomElementExpanded,false );
738
+
739
+ // All panels should be closed.
740
+ expect (find.text ('A' ), findsOneWidget);
741
+ expect (find.text ('B' ), findsNothing);
742
+ expect (find.text ('C' ), findsOneWidget);
743
+ expect (find.text ('D' ), findsNothing);
649
744
});
650
745
651
746
testWidgets (
0 commit comments