@@ -911,7 +911,7 @@ void main() {
911
911
expect (modalBarrier.color, barrierColor);
912
912
});
913
913
914
- testWidgetsWithLeakTracking ('BottomSheet uses fallback values in material3 ' ,
914
+ testWidgetsWithLeakTracking ('Material3 - BottomSheet uses fallback values' ,
915
915
(WidgetTester tester) async {
916
916
const Color surfaceColor = Colors .pink;
917
917
const Color surfaceTintColor = Colors .blue;
@@ -951,7 +951,7 @@ void main() {
951
951
expect (tester.getSize (finder).width, 640 );
952
952
});
953
953
954
- testWidgetsWithLeakTracking ('BottomSheet has transparent shadow in material3 ' , (WidgetTester tester) async {
954
+ testWidgetsWithLeakTracking ('Material3 - BottomSheet has transparent shadow' , (WidgetTester tester) async {
955
955
await tester.pumpWidget (MaterialApp (
956
956
theme: ThemeData (
957
957
useMaterial3: true ,
@@ -975,7 +975,7 @@ void main() {
975
975
expect (material.shadowColor, Colors .transparent);
976
976
});
977
977
978
- testWidgetsWithLeakTracking ('modal BottomSheet with scrollController has semantics' , (WidgetTester tester) async {
978
+ testWidgetsWithLeakTracking ('Material2 - Modal BottomSheet with ScrollController has semantics' , (WidgetTester tester) async {
979
979
final SemanticsTester semantics = SemanticsTester (tester);
980
980
final GlobalKey <ScaffoldState > scaffoldKey = GlobalKey <ScaffoldState >();
981
981
@@ -1048,12 +1048,89 @@ void main() {
1048
1048
semantics.dispose ();
1049
1049
});
1050
1050
1051
- testWidgetsWithLeakTracking ('modal BottomSheet with drag handle has semantics' , (WidgetTester tester) async {
1051
+ testWidgetsWithLeakTracking ('Material3 - Modal BottomSheet with ScrollController has semantics' , (WidgetTester tester) async {
1052
1052
final SemanticsTester semantics = SemanticsTester (tester);
1053
1053
final GlobalKey <ScaffoldState > scaffoldKey = GlobalKey <ScaffoldState >();
1054
1054
1055
1055
await tester.pumpWidget (MaterialApp (
1056
- theme: ThemeData .light (useMaterial3: true ),
1056
+ theme: ThemeData (useMaterial3: true ),
1057
+ home: Scaffold (
1058
+ key: scaffoldKey,
1059
+ body: const Center (child: Text ('body' )),
1060
+ ),
1061
+ ));
1062
+
1063
+ showModalBottomSheet <void >(
1064
+ context: scaffoldKey.currentContext! ,
1065
+ builder: (BuildContext context) {
1066
+ return DraggableScrollableSheet (
1067
+ expand: false ,
1068
+ builder: (_, ScrollController controller) {
1069
+ return SingleChildScrollView (
1070
+ controller: controller,
1071
+ child: const Text ('BottomSheet' ),
1072
+ );
1073
+ },
1074
+ );
1075
+ },
1076
+ );
1077
+
1078
+ await tester.pump (); // bottom sheet show animation starts
1079
+ await tester.pump (const Duration (seconds: 1 )); // animation done
1080
+
1081
+ expect (semantics, hasSemantics (TestSemantics .root (
1082
+ children: < TestSemantics > [
1083
+ TestSemantics .rootChild (
1084
+ children: < TestSemantics > [
1085
+ TestSemantics (
1086
+ children: < TestSemantics > [
1087
+ TestSemantics (
1088
+ label: 'Dialog' ,
1089
+ textDirection: TextDirection .ltr,
1090
+ flags: < SemanticsFlag > [
1091
+ SemanticsFlag .scopesRoute,
1092
+ SemanticsFlag .namesRoute,
1093
+ ],
1094
+ children: < TestSemantics > [
1095
+ TestSemantics (
1096
+ children: < TestSemantics > [
1097
+ TestSemantics (
1098
+ flags: < SemanticsFlag > [SemanticsFlag .hasImplicitScrolling],
1099
+ children: < TestSemantics > [
1100
+ TestSemantics (
1101
+ label: 'BottomSheet' ,
1102
+ textDirection: TextDirection .ltr,
1103
+ ),
1104
+ ],
1105
+ ),
1106
+ ],
1107
+ ),
1108
+ ],
1109
+ ),
1110
+ ],
1111
+ ),
1112
+ TestSemantics (
1113
+ children: < TestSemantics > [
1114
+ TestSemantics (
1115
+ actions: < SemanticsAction > [SemanticsAction .tap, SemanticsAction .dismiss],
1116
+ label: 'Scrim' ,
1117
+ textDirection: TextDirection .ltr,
1118
+ ),
1119
+ ],
1120
+ ),
1121
+ ],
1122
+ ),
1123
+ ],
1124
+ ), ignoreTransform: true , ignoreRect: true , ignoreId: true ));
1125
+ semantics.dispose ();
1126
+ });
1127
+
1128
+ testWidgetsWithLeakTracking ('Material3 - Modal BottomSheet with drag handle has semantics' , (WidgetTester tester) async {
1129
+ final SemanticsTester semantics = SemanticsTester (tester);
1130
+ final GlobalKey <ScaffoldState > scaffoldKey = GlobalKey <ScaffoldState >();
1131
+
1132
+ await tester.pumpWidget (MaterialApp (
1133
+ theme: ThemeData (useMaterial3: true ),
1057
1134
home: Scaffold (
1058
1135
key: scaffoldKey,
1059
1136
body: const Center (child: Text ('body' )),
@@ -1123,7 +1200,7 @@ void main() {
1123
1200
const Color hoveringColor= Colors .green;
1124
1201
1125
1202
await tester.pumpWidget (MaterialApp (
1126
- theme: ThemeData .light (useMaterial3 : true ).copyWith (
1203
+ theme: ThemeData .light ().copyWith (
1127
1204
bottomSheetTheme: BottomSheetThemeData (
1128
1205
dragHandleColor: MaterialStateColor .resolveWith ((Set <MaterialState > states) {
1129
1206
if (states.contains (MaterialState .hovered)) {
@@ -1139,7 +1216,6 @@ void main() {
1139
1216
),
1140
1217
));
1141
1218
1142
-
1143
1219
showModalBottomSheet <void >(
1144
1220
context: scaffoldKey.currentContext! ,
1145
1221
showDragHandle: true ,
@@ -1182,7 +1258,6 @@ void main() {
1182
1258
1183
1259
testWidgetsWithLeakTracking ('showModalBottomSheet does not use root Navigator by default' , (WidgetTester tester) async {
1184
1260
await tester.pumpWidget (MaterialApp (
1185
- theme: ThemeData (useMaterial3: false ),
1186
1261
home: Scaffold (
1187
1262
body: Navigator (onGenerateRoute: (RouteSettings settings) => MaterialPageRoute <void >(builder: (_) {
1188
1263
return const _TestPage ();
@@ -1207,7 +1282,8 @@ void main() {
1207
1282
1208
1283
// Bottom sheet is displayed in correct position within the inner navigator
1209
1284
// and above the BottomNavigationBar.
1210
- expect (tester.getBottomLeft (find.byType (BottomSheet )).dy, 544.0 );
1285
+ final double tabBarHeight = tester.getSize (find.byType (BottomNavigationBar )).height;
1286
+ expect (tester.getBottomLeft (find.byType (BottomSheet )).dy, 600 - tabBarHeight);
1211
1287
});
1212
1288
1213
1289
testWidgetsWithLeakTracking ('showModalBottomSheet uses root Navigator when specified' , (WidgetTester tester) async {
@@ -1790,10 +1866,10 @@ void main() {
1790
1866
});
1791
1867
1792
1868
group ('constraints' , () {
1793
- testWidgetsWithLeakTracking ('default constraints are max width 640 in material 3 ' , (WidgetTester tester) async {
1869
+ testWidgetsWithLeakTracking ('Material3 - Default constraints are max width 640' , (WidgetTester tester) async {
1794
1870
await tester.pumpWidget (
1795
1871
MaterialApp (
1796
- theme: ThemeData . light (useMaterial3: true ),
1872
+ theme: ThemeData (useMaterial3: true ),
1797
1873
home: const MediaQuery (
1798
1874
data: MediaQueryData (size: Size (1000 , 1000 )),
1799
1875
child: Scaffold (
@@ -1806,8 +1882,9 @@ void main() {
1806
1882
expect (tester.getSize (find.byType (Placeholder )).width, 640 );
1807
1883
});
1808
1884
1809
- testWidgetsWithLeakTracking ('No constraints by default for bottomSheet property' , (WidgetTester tester) async {
1885
+ testWidgetsWithLeakTracking ('Material2 - No constraints by default for bottomSheet property' , (WidgetTester tester) async {
1810
1886
await tester.pumpWidget (MaterialApp (
1887
+ // This test is specific to Material2 because Material3 sets constraints by default for BottomSheet.
1811
1888
theme: ThemeData (useMaterial3: false ),
1812
1889
home: const Scaffold (
1813
1890
body: Center (child: Text ('body' )),
@@ -1823,6 +1900,7 @@ void main() {
1823
1900
1824
1901
testWidgetsWithLeakTracking ('No constraints by default for showBottomSheet' , (WidgetTester tester) async {
1825
1902
await tester.pumpWidget (MaterialApp (
1903
+ // This test is specific to Material2 because Material3 sets constraints by default for BottomSheet.
1826
1904
theme: ThemeData (useMaterial3: false ),
1827
1905
home: Scaffold (
1828
1906
body: Builder (builder: (BuildContext context) {
@@ -1851,6 +1929,7 @@ void main() {
1851
1929
1852
1930
testWidgetsWithLeakTracking ('No constraints by default for showModalBottomSheet' , (WidgetTester tester) async {
1853
1931
await tester.pumpWidget (MaterialApp (
1932
+ // This test is specific to Material2 because Material3 sets constraints by default for BottomSheet.
1854
1933
theme: ThemeData (useMaterial3: false ),
1855
1934
home: Scaffold (
1856
1935
body: Builder (builder: (BuildContext context) {
@@ -1878,7 +1957,35 @@ void main() {
1878
1957
);
1879
1958
});
1880
1959
1881
- testWidgetsWithLeakTracking ('Theme constraints used for bottomSheet property' , (WidgetTester tester) async {
1960
+ testWidgetsWithLeakTracking ('Material3 - Theme constraints used for bottomSheet property' , (WidgetTester tester) async {
1961
+ const double sheetMaxWidth = 80.0 ;
1962
+ await tester.pumpWidget (MaterialApp (
1963
+ theme: ThemeData (
1964
+ useMaterial3: true ,
1965
+ bottomSheetTheme: const BottomSheetThemeData (
1966
+ constraints: BoxConstraints (maxWidth: sheetMaxWidth),
1967
+ ),
1968
+ ),
1969
+ home: Scaffold (
1970
+ body: const Center (child: Text ('body' )),
1971
+ bottomSheet: const Text ('BottomSheet' ),
1972
+ floatingActionButton: FloatingActionButton (onPressed: () {}, child: const Icon (Icons .add)),
1973
+ ),
1974
+ ));
1975
+ expect (find.text ('BottomSheet' ), findsOneWidget);
1976
+
1977
+ // Should be centered and only 80dp wide.
1978
+ final Rect bottomSheetRect = tester.getRect (find.text ('BottomSheet' ));
1979
+ expect (bottomSheetRect.left, 800 / 2 - sheetMaxWidth / 2 );
1980
+ expect (bottomSheetRect.width, sheetMaxWidth);
1981
+
1982
+ // Ensure the FAB is overlapping the top of the sheet.
1983
+ expect (find.byIcon (Icons .add), findsOneWidget);
1984
+ final Rect iconRect = tester.getRect (find.byIcon (Icons .add));
1985
+ expect (iconRect.top, bottomSheetRect.top - iconRect.height / 2 );
1986
+ });
1987
+
1988
+ testWidgetsWithLeakTracking ('Material2 - Theme constraints used for bottomSheet property' , (WidgetTester tester) async {
1882
1989
await tester.pumpWidget (MaterialApp (
1883
1990
theme: ThemeData (
1884
1991
useMaterial3: false ,
@@ -1907,11 +2014,11 @@ void main() {
1907
2014
});
1908
2015
1909
2016
testWidgetsWithLeakTracking ('Theme constraints used for showBottomSheet' , (WidgetTester tester) async {
2017
+ const double sheetMaxWidth = 80.0 ;
1910
2018
await tester.pumpWidget (MaterialApp (
1911
2019
theme: ThemeData (
1912
- useMaterial3: false ,
1913
2020
bottomSheetTheme: const BottomSheetThemeData (
1914
- constraints: BoxConstraints (maxWidth: 80 ),
2021
+ constraints: BoxConstraints (maxWidth: sheetMaxWidth ),
1915
2022
),
1916
2023
),
1917
2024
home: Scaffold (
@@ -1933,19 +2040,19 @@ void main() {
1933
2040
await tester.tap (find.text ('Press me' ));
1934
2041
await tester.pumpAndSettle ();
1935
2042
expect (find.text ('BottomSheet' ), findsOneWidget);
1936
- // Should be centered and only 80dp wide
1937
- expect (
1938
- tester.getRect (find.text ('BottomSheet' )),
1939
- const Rect . fromLTRB ( 360 , 558 , 440 , 600 ),
1940
- );
2043
+
2044
+ // Should be centered and only 80dp wide.
2045
+ final Rect bottomSheetRect = tester.getRect (find.text ('BottomSheet' ));
2046
+ expect (bottomSheetRect.left, 800 / 2 - sheetMaxWidth / 2 );
2047
+ expect (bottomSheetRect.width, sheetMaxWidth );
1941
2048
});
1942
2049
1943
2050
testWidgetsWithLeakTracking ('Theme constraints used for showModalBottomSheet' , (WidgetTester tester) async {
2051
+ const double sheetMaxWidth = 80.0 ;
1944
2052
await tester.pumpWidget (MaterialApp (
1945
2053
theme: ThemeData (
1946
- useMaterial3: false ,
1947
2054
bottomSheetTheme: const BottomSheetThemeData (
1948
- constraints: BoxConstraints (maxWidth: 80 ),
2055
+ constraints: BoxConstraints (maxWidth: sheetMaxWidth ),
1949
2056
),
1950
2057
),
1951
2058
home: Scaffold (
@@ -1968,17 +2075,17 @@ void main() {
1968
2075
await tester.tap (find.text ('Press me' ));
1969
2076
await tester.pumpAndSettle ();
1970
2077
expect (find.text ('BottomSheet' ), findsOneWidget);
1971
- // Should be centered and only 80dp wide
1972
- expect (
1973
- tester.getRect (find.text ('BottomSheet' )),
1974
- const Rect . fromLTRB ( 360 , 558 , 440 , 600 ),
1975
- );
2078
+
2079
+ // Should be centered and only 80dp wide.
2080
+ final Rect bottomSheetRect = tester.getRect (find.text ('BottomSheet' ));
2081
+ expect (bottomSheetRect.left, 800 / 2 - sheetMaxWidth / 2 );
2082
+ expect (bottomSheetRect.width, sheetMaxWidth );
1976
2083
});
1977
2084
1978
2085
testWidgetsWithLeakTracking ('constraints param overrides theme for showBottomSheet' , (WidgetTester tester) async {
2086
+ const double sheetMaxWidth = 100.0 ;
1979
2087
await tester.pumpWidget (MaterialApp (
1980
2088
theme: ThemeData (
1981
- useMaterial3: false ,
1982
2089
bottomSheetTheme: const BottomSheetThemeData (
1983
2090
constraints: BoxConstraints (maxWidth: 80 ),
1984
2091
),
@@ -1991,7 +2098,7 @@ void main() {
1991
2098
onPressed: () {
1992
2099
Scaffold .of (context).showBottomSheet <void >(
1993
2100
(BuildContext context) => const Text ('BottomSheet' ),
1994
- constraints: const BoxConstraints (maxWidth: 100 ),
2101
+ constraints: const BoxConstraints (maxWidth: sheetMaxWidth ),
1995
2102
);
1996
2103
},
1997
2104
),
@@ -2003,17 +2110,17 @@ void main() {
2003
2110
await tester.tap (find.text ('Press me' ));
2004
2111
await tester.pumpAndSettle ();
2005
2112
expect (find.text ('BottomSheet' ), findsOneWidget);
2006
- // Should be centered and only 100dp wide instead of 80dp wide
2007
- expect (
2008
- tester.getRect (find.text ('BottomSheet' )),
2009
- const Rect . fromLTRB ( 350 , 572 , 450 , 600 ),
2010
- );
2113
+
2114
+ // Should be centered and only 80dp wide.
2115
+ final Rect bottomSheetRect = tester.getRect (find.text ('BottomSheet' ));
2116
+ expect (bottomSheetRect.left, 800 / 2 - sheetMaxWidth / 2 );
2117
+ expect (bottomSheetRect.width, sheetMaxWidth );
2011
2118
});
2012
2119
2013
2120
testWidgetsWithLeakTracking ('constraints param overrides theme for showModalBottomSheet' , (WidgetTester tester) async {
2121
+ const double sheetMaxWidth = 100.0 ;
2014
2122
await tester.pumpWidget (MaterialApp (
2015
2123
theme: ThemeData (
2016
- useMaterial3: false ,
2017
2124
bottomSheetTheme: const BottomSheetThemeData (
2018
2125
constraints: BoxConstraints (maxWidth: 80 ),
2019
2126
),
@@ -2027,7 +2134,7 @@ void main() {
2027
2134
showModalBottomSheet <void >(
2028
2135
context: context,
2029
2136
builder: (BuildContext context) => const Text ('BottomSheet' ),
2030
- constraints: const BoxConstraints (maxWidth: 100 ),
2137
+ constraints: const BoxConstraints (maxWidth: sheetMaxWidth ),
2031
2138
);
2032
2139
},
2033
2140
),
@@ -2039,11 +2146,11 @@ void main() {
2039
2146
await tester.tap (find.text ('Press me' ));
2040
2147
await tester.pumpAndSettle ();
2041
2148
expect (find.text ('BottomSheet' ), findsOneWidget);
2042
- // Should be centered and only 100dp instead of 80dp wide
2043
- expect (
2044
- tester.getRect (find.text ('BottomSheet' )),
2045
- const Rect . fromLTRB ( 350 , 572 , 450 , 600 ),
2046
- );
2149
+
2150
+ // Should be centered and only 80dp wide.
2151
+ final Rect bottomSheetRect = tester.getRect (find.text ('BottomSheet' ));
2152
+ expect (bottomSheetRect.left, 800 / 2 - sheetMaxWidth / 2 );
2153
+ expect (bottomSheetRect.width, sheetMaxWidth );
2047
2154
});
2048
2155
2049
2156
group ('scrollControlDisabledMaxHeightRatio' , () {
0 commit comments