@@ -893,6 +893,162 @@ void main() {
893
893
handle.dispose ();
894
894
}, variant: const TargetPlatformVariant (< TargetPlatform > { TargetPlatform .iOS, TargetPlatform .macOS }));
895
895
896
+ testWidgetsWithLeakTracking ('Collapsed ExpansionTile properties can be updated with setState' , (WidgetTester tester) async {
897
+ const Key expansionTileKey = Key ('expansionTileKey' );
898
+ ShapeBorder collapsedShape = const RoundedRectangleBorder (
899
+ borderRadius: BorderRadius .all (Radius .circular (4 )),
900
+ );
901
+ Color collapsedTextColor = const Color (0xffffffff );
902
+ Color collapsedBackgroundColor = const Color (0xffff0000 );
903
+ Color collapsedIconColor = const Color (0xffffffff );
904
+
905
+ await tester.pumpWidget (MaterialApp (
906
+ home: Material (
907
+ child: StatefulBuilder (
908
+ builder: (BuildContext context, StateSetter setState) {
909
+ return Column (
910
+ children: < Widget > [
911
+ ExpansionTile (
912
+ key: expansionTileKey,
913
+ collapsedShape: collapsedShape,
914
+ collapsedTextColor: collapsedTextColor,
915
+ collapsedBackgroundColor: collapsedBackgroundColor,
916
+ collapsedIconColor: collapsedIconColor,
917
+ title: const TestText ('title' ),
918
+ trailing: const TestIcon (),
919
+ children: const < Widget > [
920
+ SizedBox (height: 100 , width: 100 ),
921
+ ],
922
+ ),
923
+ // This button is used to update the ExpansionTile properties.
924
+ FilledButton (
925
+ onPressed: () {
926
+ setState (() {
927
+ collapsedShape = const RoundedRectangleBorder (
928
+ borderRadius: BorderRadius .all (Radius .circular (16 )),
929
+ );
930
+ collapsedTextColor = const Color (0xff000000 );
931
+ collapsedBackgroundColor = const Color (0xffffff00 );
932
+ collapsedIconColor = const Color (0xff000000 );
933
+ });
934
+ },
935
+ child: const Text ('Update collapsed properties' ),
936
+ ),
937
+ ],
938
+ );
939
+ }
940
+ ),
941
+ ),
942
+ ));
943
+
944
+ ShapeDecoration shapeDecoration = tester.firstWidget <Container >(find.descendant (
945
+ of: find.byKey (expansionTileKey),
946
+ matching: find.byType (Container ),
947
+ )).decoration! as ShapeDecoration ;
948
+
949
+ // Test initial ExpansionTile properties.
950
+ expect (shapeDecoration.shape, const RoundedRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (4 ))));
951
+ expect (shapeDecoration.color, const Color (0xffff0000 ));
952
+ expect (tester.state <TestIconState >(find.byType (TestIcon )).iconTheme.color, const Color (0xffffffff ));
953
+ expect (tester.state <TestTextState >(find.byType (TestText )).textStyle.color, const Color (0xffffffff ));
954
+
955
+ // Tap the button to update the ExpansionTile properties.
956
+ await tester.tap (find.text ('Update collapsed properties' ));
957
+ await tester.pumpAndSettle ();
958
+
959
+ shapeDecoration = tester.firstWidget <Container >(find.descendant (
960
+ of: find.byKey (expansionTileKey),
961
+ matching: find.byType (Container ),
962
+ )).decoration! as ShapeDecoration ;
963
+
964
+ // Test updated ExpansionTile properties.
965
+ expect (shapeDecoration.shape, const RoundedRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (16 ))));
966
+ expect (shapeDecoration.color, const Color (0xffffff00 ));
967
+ expect (tester.state <TestIconState >(find.byType (TestIcon )).iconTheme.color, const Color (0xff000000 ));
968
+ expect (tester.state <TestTextState >(find.byType (TestText )).textStyle.color, const Color (0xff000000 ));
969
+ });
970
+
971
+ testWidgetsWithLeakTracking ('Expanded ExpansionTile properties can be updated with setState' , (WidgetTester tester) async {
972
+ const Key expansionTileKey = Key ('expansionTileKey' );
973
+ ShapeBorder shape = const RoundedRectangleBorder (
974
+ borderRadius: BorderRadius .all (Radius .circular (12 )),
975
+ );
976
+ Color textColor = const Color (0xff00ffff );
977
+ Color backgroundColor = const Color (0xff0000ff );
978
+ Color iconColor = const Color (0xff00ffff );
979
+
980
+ await tester.pumpWidget (MaterialApp (
981
+ home: Material (
982
+ child: StatefulBuilder (
983
+ builder: (BuildContext context, StateSetter setState) {
984
+ return Column (
985
+ children: < Widget > [
986
+ ExpansionTile (
987
+ key: expansionTileKey,
988
+ shape: shape,
989
+ textColor: textColor,
990
+ backgroundColor: backgroundColor,
991
+ iconColor: iconColor,
992
+ title: const TestText ('title' ),
993
+ trailing: const TestIcon (),
994
+ children: const < Widget > [
995
+ SizedBox (height: 100 , width: 100 ),
996
+ ],
997
+ ),
998
+ // This button is used to update the ExpansionTile properties.
999
+ FilledButton (
1000
+ onPressed: () {
1001
+ setState (() {
1002
+ shape = const RoundedRectangleBorder (
1003
+ borderRadius: BorderRadius .all (Radius .circular (6 )),
1004
+ );
1005
+ textColor = const Color (0xffffffff );
1006
+ backgroundColor = const Color (0xff123456 );
1007
+ iconColor = const Color (0xffffffff );
1008
+ });
1009
+ },
1010
+ child: const Text ('Update collapsed properties' ),
1011
+ ),
1012
+ ],
1013
+ );
1014
+ }
1015
+ ),
1016
+ ),
1017
+ ));
1018
+
1019
+ // Tap to expand the ExpansionTile.
1020
+ await tester.tap (find.text ('title' ));
1021
+ await tester.pumpAndSettle ();
1022
+
1023
+ ShapeDecoration shapeDecoration = tester.firstWidget <Container >(find.descendant (
1024
+ of: find.byKey (expansionTileKey),
1025
+ matching: find.byType (Container ),
1026
+ )).decoration! as ShapeDecoration ;
1027
+
1028
+ // Test initial ExpansionTile properties.
1029
+ expect (shapeDecoration.shape, const RoundedRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (12 ))));
1030
+ expect (shapeDecoration.color, const Color (0xff0000ff ));
1031
+ expect (tester.state <TestIconState >(find.byType (TestIcon )).iconTheme.color, const Color (0xff00ffff ));
1032
+ expect (tester.state <TestTextState >(find.byType (TestText )).textStyle.color, const Color (0xff00ffff ));
1033
+
1034
+ // Tap the button to update the ExpansionTile properties.
1035
+ await tester.tap (find.text ('Update collapsed properties' ));
1036
+ await tester.pumpAndSettle ();
1037
+
1038
+ shapeDecoration = tester.firstWidget <Container >(find.descendant (
1039
+ of: find.byKey (expansionTileKey),
1040
+ matching: find.byType (Container ),
1041
+ )).decoration! as ShapeDecoration ;
1042
+ iconColor = tester.state <TestIconState >(find.byType (TestIcon )).iconTheme.color! ;
1043
+ textColor = tester.state <TestTextState >(find.byType (TestText )).textStyle.color! ;
1044
+
1045
+ // Test updated ExpansionTile properties.
1046
+ expect (shapeDecoration.shape, const RoundedRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (6 ))));
1047
+ expect (shapeDecoration.color, const Color (0xff123456 ));
1048
+ expect (tester.state <TestIconState >(find.byType (TestIcon )).iconTheme.color, const Color (0xffffffff ));
1049
+ expect (tester.state <TestTextState >(find.byType (TestText )).textStyle.color, const Color (0xffffffff ));
1050
+ });
1051
+
896
1052
group ('Material 2' , () {
897
1053
// These tests are only relevant for Material 2. Once Material 2
898
1054
// support is deprecated and the APIs are removed, these tests
0 commit comments