Unverified Commit cea728af authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Update tests in material library for Material 3 by default (#128300)

parent ce248e87
...@@ -119,6 +119,7 @@ void main() { ...@@ -119,6 +119,7 @@ void main() {
testWidgets('ThemeData properties are used when no CardTheme is set', (WidgetTester tester) async { testWidgets('ThemeData properties are used when no CardTheme is set', (WidgetTester tester) async {
final ThemeData themeData = _themeData(); final ThemeData themeData = _themeData();
final bool material3 = themeData.useMaterial3;
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
theme: themeData, theme: themeData,
...@@ -128,7 +129,7 @@ void main() { ...@@ -128,7 +129,7 @@ void main() {
)); ));
final Material material = _getCardMaterial(tester); final Material material = _getCardMaterial(tester);
expect(material.color, themeData.cardColor); expect(material.color, material3 ? themeData.colorScheme.surface: themeData.cardColor);
}); });
testWidgets('CardTheme customizes shape', (WidgetTester tester) async { testWidgets('CardTheme customizes shape', (WidgetTester tester) async {
......
...@@ -474,14 +474,16 @@ void main() { ...@@ -474,14 +474,16 @@ void main() {
}); });
testWidgets('Checkbox color rendering', (WidgetTester tester) async { testWidgets('Checkbox color rendering', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
const Color borderColor = Color(0xff2196f3); const Color borderColor = Color(0xff2196f3);
const Color m3BorderColor = Color(0xFF6750A4);
Color checkColor = const Color(0xffFFFFFF); Color checkColor = const Color(0xffFFFFFF);
Color activeColor; Color activeColor;
Widget buildFrame({Color? activeColor, Color? checkColor, ThemeData? themeData}) { Widget buildFrame({Color? activeColor, Color? checkColor, ThemeData? themeData}) {
return Material( return Material(
child: Theme( child: Theme(
data: themeData ?? ThemeData(), data: themeData ?? theme,
child: StatefulBuilder( child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) { builder: (BuildContext context, StateSetter setState) {
return Checkbox( return Checkbox(
...@@ -502,13 +504,13 @@ void main() { ...@@ -502,13 +504,13 @@ void main() {
await tester.pumpWidget(buildFrame(checkColor: checkColor)); await tester.pumpWidget(buildFrame(checkColor: checkColor));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getCheckboxRenderer(), paints..path(color: borderColor)..path(color: checkColor)); // paints's color is 0xFFFFFFFF (default color) expect(getCheckboxRenderer(), paints..path(color: theme.useMaterial3 ? m3BorderColor : borderColor)..path(color: checkColor)); // paints's color is 0xFFFFFFFF (default color)
checkColor = const Color(0xFF000000); checkColor = const Color(0xFF000000);
await tester.pumpWidget(buildFrame(checkColor: checkColor)); await tester.pumpWidget(buildFrame(checkColor: checkColor));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getCheckboxRenderer(), paints..path(color: borderColor)..path(color: checkColor)); // paints's color is 0xFF000000 (params) expect(getCheckboxRenderer(), paints..path(color: theme.useMaterial3 ? m3BorderColor : borderColor)..path(color: checkColor)); // paints's color is 0xFF000000 (params)
activeColor = const Color(0xFF00FF00); activeColor = const Color(0xFF00FF00);
...@@ -520,7 +522,7 @@ void main() { ...@@ -520,7 +522,7 @@ void main() {
themeData = themeData.copyWith(colorScheme: colorScheme); themeData = themeData.copyWith(colorScheme: colorScheme);
await tester.pumpWidget(buildFrame( await tester.pumpWidget(buildFrame(
themeData: themeData), themeData: themeData),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getCheckboxRenderer(), paints..path(color: activeColor)); // paints's color is 0xFF00FF00 (theme) expect(getCheckboxRenderer(), paints..path(color: activeColor)); // paints's color is 0xFF00FF00 (theme)
...@@ -567,7 +569,7 @@ void main() { ...@@ -567,7 +569,7 @@ void main() {
material3 material3
? (paints ? (paints
..circle(color: Colors.orange[500]) ..circle(color: Colors.orange[500])
..path(color: const Color(0xff2196f3)) ..path(color: theme.colorScheme.primary)
..path(color: theme.colorScheme.onPrimary)) ..path(color: theme.colorScheme.onPrimary))
: (paints : (paints
..circle(color: Colors.orange[500]) ..circle(color: Colors.orange[500])
...@@ -586,7 +588,7 @@ void main() { ...@@ -586,7 +588,7 @@ void main() {
..circle(color: Colors.orange[500]) ..circle(color: Colors.orange[500])
..drrect( ..drrect(
color: material3 ? theme.colorScheme.onSurface : const Color(0x8a000000), color: material3 ? theme.colorScheme.onSurface : const Color(0x8a000000),
outer: RRect.fromLTRBR(15.0, 15.0, 33.0, 33.0, const Radius.circular(1.0)), outer: RRect.fromLTRBR(15.0, 15.0, 33.0, 33.0, material3 ? const Radius.circular(2.0) : const Radius.circular(1.0)),
inner: RRect.fromLTRBR(17.0, 17.0, 31.0, 31.0, Radius.zero), inner: RRect.fromLTRBR(17.0, 17.0, 31.0, 31.0, Radius.zero),
), ),
); );
...@@ -601,7 +603,7 @@ void main() { ...@@ -601,7 +603,7 @@ void main() {
paints paints
..drrect( ..drrect(
color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000), color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000),
outer: RRect.fromLTRBR(15.0, 15.0, 33.0, 33.0, const Radius.circular(1.0)), outer: RRect.fromLTRBR(15.0, 15.0, 33.0, 33.0, material3 ? const Radius.circular(2.0) : const Radius.circular(1.0)),
inner: RRect.fromLTRBR(17.0, 17.0, 31.0, 31.0, Radius.zero), inner: RRect.fromLTRBR(17.0, 17.0, 31.0, 31.0, Radius.zero),
), ),
); );
...@@ -697,7 +699,7 @@ void main() { ...@@ -697,7 +699,7 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Checkbox))), Material.of(tester.element(find.byType(Checkbox))),
paints paints
..path(color: const Color(0xff2196f3)) ..path(color: material3 ? const Color(0xff6750a4) : const Color(0xff2196f3))
..path(color: material3 ? theme.colorScheme.onPrimary : const Color(0xffffffff), style: PaintingStyle.stroke, strokeWidth: 2.0), ..path(color: material3 ? theme.colorScheme.onPrimary : const Color(0xffffffff), style: PaintingStyle.stroke, strokeWidth: 2.0),
); );
...@@ -710,7 +712,7 @@ void main() { ...@@ -710,7 +712,7 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Checkbox))), Material.of(tester.element(find.byType(Checkbox))),
paints paints
..path(color: const Color(0xff2196f3)) ..path(color: material3 ? const Color(0xff6750a4) : const Color(0xff2196f3))
..path(color: material3 ? theme.colorScheme.onPrimary : const Color(0xffffffff), style: PaintingStyle.stroke, strokeWidth: 2.0), ..path(color: material3 ? theme.colorScheme.onPrimary : const Color(0xffffffff), style: PaintingStyle.stroke, strokeWidth: 2.0),
); );
...@@ -1450,7 +1452,7 @@ void main() { ...@@ -1450,7 +1452,7 @@ void main() {
await gesture.up(); await gesture.up();
}); });
testWidgets('Checkbox BorderSide side only applies when unselected', (WidgetTester tester) async { testWidgets('Checkbox BorderSide side only applies when unselected in M2', (WidgetTester tester) async {
const Color borderColor = Color(0xfff44336); const Color borderColor = Color(0xfff44336);
const Color activeColor = Color(0xff123456); const Color activeColor = Color(0xff123456);
const BorderSide side = BorderSide( const BorderSide side = BorderSide(
...@@ -1460,7 +1462,7 @@ void main() { ...@@ -1460,7 +1462,7 @@ void main() {
Widget buildApp({ bool? value, bool enabled = true }) { Widget buildApp({ bool? value, bool enabled = true }) {
return MaterialApp( return MaterialApp(
theme: theme, theme: ThemeData(useMaterial3: false),
home: Material( home: Material(
child: Center( child: Center(
child: Checkbox( child: Checkbox(
...@@ -1520,6 +1522,7 @@ void main() { ...@@ -1520,6 +1522,7 @@ void main() {
width: 4, width: 4,
color: borderColor, color: borderColor,
); );
final bool material3 = theme.useMaterial3;
Widget buildApp({ bool? value, bool enabled = true }) { Widget buildApp({ bool? value, bool enabled = true }) {
return MaterialApp( return MaterialApp(
...@@ -1543,7 +1546,7 @@ void main() { ...@@ -1543,7 +1546,7 @@ void main() {
paints paints
..drrect( ..drrect(
color: borderColor, color: borderColor,
outer: RRect.fromLTRBR(15, 15, 33, 33, const Radius.circular(1)), outer: material3 ? RRect.fromLTRBR(15, 15, 33, 33, const Radius.circular(2)) : RRect.fromLTRBR(15, 15, 33, 33, const Radius.circular(1)),
inner: RRect.fromLTRBR(19, 19, 29, 29, Radius.zero), inner: RRect.fromLTRBR(19, 19, 29, 29, Radius.zero),
), ),
); );
......
...@@ -60,9 +60,11 @@ void main() { ...@@ -60,9 +60,11 @@ void main() {
testWidgets('Default values are used when no Drawer or DrawerThemeData properties are specified', (WidgetTester tester) async { testWidgets('Default values are used when no Drawer or DrawerThemeData properties are specified', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final bool useMaterial3 = ThemeData().useMaterial3; final ThemeData theme = ThemeData();
final bool useMaterial3 = theme.useMaterial3;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: theme,
home: Scaffold( home: Scaffold(
key: scaffoldKey, key: scaffoldKey,
drawer: const Drawer(), drawer: const Drawer(),
...@@ -72,10 +74,10 @@ void main() { ...@@ -72,10 +74,10 @@ void main() {
scaffoldKey.currentState!.openDrawer(); scaffoldKey.currentState!.openDrawer();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(_drawerMaterial(tester).color, null); expect(_drawerMaterial(tester).color, useMaterial3 ? theme.colorScheme.surface : null);
expect(_drawerMaterial(tester).elevation, 16.0); expect(_drawerMaterial(tester).elevation, useMaterial3 ? 1.0 : 16.0);
expect(_drawerMaterial(tester).shadowColor, useMaterial3 ? Colors.transparent : ThemeData().shadowColor); expect(_drawerMaterial(tester).shadowColor, useMaterial3 ? Colors.transparent : ThemeData().shadowColor);
expect(_drawerMaterial(tester).surfaceTintColor, useMaterial3 ? ThemeData().colorScheme.surfaceTint : null); expect(_drawerMaterial(tester).surfaceTintColor, useMaterial3 ? theme.colorScheme.surfaceTint : null);
expect( expect(
_drawerMaterial(tester).shape, _drawerMaterial(tester).shape,
useMaterial3 useMaterial3
...@@ -88,9 +90,11 @@ void main() { ...@@ -88,9 +90,11 @@ void main() {
testWidgets('Default values are used when no Drawer or DrawerThemeData properties are specified in end drawer', (WidgetTester tester) async { testWidgets('Default values are used when no Drawer or DrawerThemeData properties are specified in end drawer', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final bool useMaterial3 = ThemeData().useMaterial3; final ThemeData theme = ThemeData();
final bool useMaterial3 = theme.useMaterial3;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: theme,
home: Scaffold( home: Scaffold(
key: scaffoldKey, key: scaffoldKey,
endDrawer: const Drawer(), endDrawer: const Drawer(),
...@@ -100,8 +104,8 @@ void main() { ...@@ -100,8 +104,8 @@ void main() {
scaffoldKey.currentState!.openEndDrawer(); scaffoldKey.currentState!.openEndDrawer();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(_drawerMaterial(tester).color, null); expect(_drawerMaterial(tester).color, useMaterial3 ? theme.colorScheme.surface : null);
expect(_drawerMaterial(tester).elevation, 16.0); expect(_drawerMaterial(tester).elevation, useMaterial3 ? 1.0 : 16.0);
expect(_drawerMaterial(tester).shadowColor, useMaterial3 ? Colors.transparent : ThemeData().shadowColor); expect(_drawerMaterial(tester).shadowColor, useMaterial3 ? Colors.transparent : ThemeData().shadowColor);
expect(_drawerMaterial(tester).surfaceTintColor, useMaterial3 ? ThemeData().colorScheme.surfaceTint : null); expect(_drawerMaterial(tester).surfaceTintColor, useMaterial3 ? ThemeData().colorScheme.surfaceTint : null);
expect( expect(
......
...@@ -113,6 +113,7 @@ void main() { ...@@ -113,6 +113,7 @@ void main() {
(WidgetTester tester) async { (WidgetTester tester) async {
final ThemeData themeData = ThemeData(); final ThemeData themeData = ThemeData();
final bool useMaterial3 = themeData.useMaterial3;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: themeData, theme: themeData,
...@@ -128,7 +129,7 @@ void main() { ...@@ -128,7 +129,7 @@ void main() {
final Finder textField = find.byType(TextField); final Finder textField = find.byType(TextField);
final Size anchorSize = tester.getSize(textField); final Size anchorSize = tester.getSize(textField);
expect(anchorSize, const Size(180.0, 56.0)); expect(anchorSize, useMaterial3 ? const Size(195.0, 60.0) : const Size(180.0, 56.0));
await tester.tap(find.byType(DropdownMenu<TestMenu>)); await tester.tap(find.byType(DropdownMenu<TestMenu>));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -138,7 +139,7 @@ void main() { ...@@ -138,7 +139,7 @@ void main() {
matching: find.byType(Material), matching: find.byType(Material),
); );
final Size menuSize = tester.getSize(menuMaterial); final Size menuSize = tester.getSize(menuMaterial);
expect(menuSize, const Size(180.0, 304.0)); expect(menuSize, useMaterial3 ? const Size(195.0, 304.0) : const Size(180.0, 304.0));
// The text field should have same width as the menu // The text field should have same width as the menu
// when the width property is not null. // when the width property is not null.
...@@ -146,7 +147,7 @@ void main() { ...@@ -146,7 +147,7 @@ void main() {
final Finder anchor = find.byType(TextField); final Finder anchor = find.byType(TextField);
final Size size = tester.getSize(anchor); final Size size = tester.getSize(anchor);
expect(size, const Size(200.0, 56.0)); expect(size, useMaterial3 ? const Size(200.0, 60.0) : const Size(200.0, 56.0));
await tester.tap(anchor); await tester.tap(anchor);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -218,6 +219,7 @@ void main() { ...@@ -218,6 +219,7 @@ void main() {
testWidgets('The menuHeight property can be used to show a shorter scrollable menu list instead of the complete list', testWidgets('The menuHeight property can be used to show a shorter scrollable menu list instead of the complete list',
(WidgetTester tester) async { (WidgetTester tester) async {
final ThemeData themeData = ThemeData(); final ThemeData themeData = ThemeData();
final bool material3 = themeData.useMaterial3;
await tester.pumpWidget(buildTest(themeData, menuChildren)); await tester.pumpWidget(buildTest(themeData, menuChildren));
await tester.tap(find.byType(DropdownMenu<TestMenu>)); await tester.tap(find.byType(DropdownMenu<TestMenu>));
...@@ -237,7 +239,7 @@ void main() { ...@@ -237,7 +239,7 @@ void main() {
matching: find.byType(Padding), matching: find.byType(Padding),
).first; ).first;
final Size menuViewSize = tester.getSize(menuView); final Size menuViewSize = tester.getSize(menuView);
expect(menuViewSize, const Size(180.0, 304.0)); // 304 = 288 + vertical padding(2 * 8) expect(menuViewSize, material3 ? const Size(195.0, 304.0) : const Size(180.0, 304.0)); // 304 = 288 + vertical padding(2 * 8)
// Constrains the menu height. // Constrains the menu height.
await tester.pumpWidget(Container()); await tester.pumpWidget(Container());
...@@ -253,7 +255,7 @@ void main() { ...@@ -253,7 +255,7 @@ void main() {
).first; ).first;
final Size updatedMenuSize = tester.getSize(updatedMenu); final Size updatedMenuSize = tester.getSize(updatedMenu);
expect(updatedMenuSize, const Size(180.0, 100.0)); expect(updatedMenuSize, material3 ? const Size(195.0, 100.0) : const Size(180.0, 100.0));
}); });
testWidgets('The text in the menu button should be aligned with the text of ' testWidgets('The text in the menu button should be aligned with the text of '
......
...@@ -246,8 +246,8 @@ void main() { ...@@ -246,8 +246,8 @@ void main() {
); );
}); });
testWidgets('NavigationBar uses proper defaults when no parameters are given', (WidgetTester tester) async { testWidgets('NavigationBar uses proper defaults when no parameters are given - M2', (WidgetTester tester) async {
// Pre-M3 settings that were hand coded. // M2 settings that were hand coded.
await tester.pumpWidget( await tester.pumpWidget(
_buildWidget( _buildWidget(
NavigationBar( NavigationBar(
...@@ -263,6 +263,7 @@ void main() { ...@@ -263,6 +263,7 @@ void main() {
], ],
onDestinationSelected: (int i) {}, onDestinationSelected: (int i) {},
), ),
useMaterial3: false,
), ),
); );
...@@ -272,13 +273,14 @@ void main() { ...@@ -272,13 +273,14 @@ void main() {
expect(tester.getSize(find.byType(NavigationBar)).height, 80); expect(tester.getSize(find.byType(NavigationBar)).height, 80);
expect(_getIndicatorDecoration(tester)?.color, const Color(0x3d2196f3)); expect(_getIndicatorDecoration(tester)?.color, const Color(0x3d2196f3));
expect(_getIndicatorDecoration(tester)?.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16))); expect(_getIndicatorDecoration(tester)?.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)));
});
testWidgets('NavigationBar uses proper defaults when no parameters are given - M3', (WidgetTester tester) async {
// M3 settings from the token database. // M3 settings from the token database.
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget( await tester.pumpWidget(
_buildWidget( _buildWidget(
Theme( NavigationBar(
data: ThemeData.light().copyWith(useMaterial3: true),
child: NavigationBar(
destinations: const <Widget>[ destinations: const <Widget>[
NavigationDestination( NavigationDestination(
icon: Icon(Icons.ac_unit), icon: Icon(Icons.ac_unit),
...@@ -291,15 +293,15 @@ void main() { ...@@ -291,15 +293,15 @@ void main() {
], ],
onDestinationSelected: (int i) {}, onDestinationSelected: (int i) {},
), ),
), useMaterial3: theme.useMaterial3
), ),
); );
expect(_getMaterial(tester).color, ThemeData().colorScheme.surface); expect(_getMaterial(tester).color, theme.colorScheme.surface);
expect(_getMaterial(tester).surfaceTintColor, ThemeData().colorScheme.surfaceTint); expect(_getMaterial(tester).surfaceTintColor, theme.colorScheme.surfaceTint);
expect(_getMaterial(tester).elevation, 3); expect(_getMaterial(tester).elevation, 3);
expect(tester.getSize(find.byType(NavigationBar)).height, 80); expect(tester.getSize(find.byType(NavigationBar)).height, 80);
expect(_getIndicatorDecoration(tester)?.color, const Color(0xff2196f3)); expect(_getIndicatorDecoration(tester)?.color, theme.colorScheme.secondaryContainer);
expect(_getIndicatorDecoration(tester)?.shape, const StadiumBorder()); expect(_getIndicatorDecoration(tester)?.shape, const StadiumBorder());
}); });
...@@ -315,9 +317,9 @@ void main() { ...@@ -315,9 +317,9 @@ void main() {
DefaultMaterialLocalizations.delegate, DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate, DefaultWidgetsLocalizations.delegate,
], ],
child: Directionality( child: MaterialApp(
textDirection: TextDirection.ltr, theme: ThemeData(useMaterial3: false),
child: Navigator( home: Navigator(
onGenerateRoute: (RouteSettings settings) { onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<void>( return MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
...@@ -1269,9 +1271,9 @@ void main() { ...@@ -1269,9 +1271,9 @@ void main() {
}); });
} }
Widget _buildWidget(Widget child) { Widget _buildWidget(Widget child, { bool? useMaterial3 }) {
return MaterialApp( return MaterialApp(
theme: ThemeData.light(), theme: ThemeData(useMaterial3: useMaterial3),
home: Scaffold( home: Scaffold(
bottomNavigationBar: Center( bottomNavigationBar: Center(
child: child, child: child,
......
...@@ -115,40 +115,37 @@ void main() { ...@@ -115,40 +115,37 @@ void main() {
}); });
testWidgets( testWidgets(
'NavigationDrawer uses proper defaults when no parameters are given', 'M3 NavigationDrawer uses proper defaults when no parameters are given',
(WidgetTester tester) async { (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final ThemeData theme= ThemeData.from(colorScheme: const ColorScheme.light()); final ThemeData theme = ThemeData(useMaterial3: true);
// M3 settings from the token database.
await tester.pumpWidget( await tester.pumpWidget(
_buildWidget( _buildWidget(
scaffoldKey, scaffoldKey,
Theme( NavigationDrawer(
data: ThemeData.light().copyWith(useMaterial3: true), children: <Widget>[
child: NavigationDrawer( Text('Headline', style: theme.textTheme.bodyLarge),
children: <Widget>[ NavigationDrawerDestination(
Text('Headline', style: theme.textTheme.bodyLarge), icon: Icon(Icons.ac_unit, color: theme.iconTheme.color),
NavigationDrawerDestination( label: Text('AC', style: theme.textTheme.bodySmall),
icon: Icon(Icons.ac_unit, color: theme.iconTheme.color), ),
label: Text('AC', style: theme.textTheme.bodySmall), NavigationDrawerDestination(
), icon: Icon(Icons.access_alarm, color: theme.iconTheme.color),
NavigationDrawerDestination( label: Text('Alarm', style: theme.textTheme.bodySmall),
icon: Icon(Icons.access_alarm, color: theme.iconTheme.color), ),
label: Text('Alarm', style: theme.textTheme.bodySmall), ],
), onDestinationSelected: (int i) {},
],
onDestinationSelected: (int i) {},
),
), ),
useMaterial3: theme.useMaterial3,
), ),
); );
scaffoldKey.currentState!.openDrawer(); scaffoldKey.currentState!.openDrawer();
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
expect(_getMaterial(tester).color, ThemeData().colorScheme.surface); expect(_getMaterial(tester).color, theme.colorScheme.surface);
expect(_getMaterial(tester).surfaceTintColor, ThemeData().colorScheme.surfaceTint); expect(_getMaterial(tester).surfaceTintColor, theme.colorScheme.surfaceTint);
expect(_getMaterial(tester).elevation, 1); expect(_getMaterial(tester).elevation, 1);
expect(_getIndicatorDecoration(tester)?.color, const Color(0xff2196f3)); expect(_getIndicatorDecoration(tester)?.color, theme.colorScheme.secondaryContainer);
expect(_getIndicatorDecoration(tester)?.shape, const StadiumBorder()); expect(_getIndicatorDecoration(tester)?.shape, const StadiumBorder());
}); });
...@@ -385,9 +382,9 @@ void main() { ...@@ -385,9 +382,9 @@ void main() {
}); });
} }
Widget _buildWidget(GlobalKey<ScaffoldState> scaffoldKey, Widget child) { Widget _buildWidget(GlobalKey<ScaffoldState> scaffoldKey, Widget child, { bool? useMaterial3 }) {
return MaterialApp( return MaterialApp(
theme: ThemeData.light(), theme: ThemeData(useMaterial3: useMaterial3),
home: Scaffold( home: Scaffold(
key: scaffoldKey, key: scaffoldKey,
drawer: child, drawer: child,
......
...@@ -13,10 +13,11 @@ void main() { ...@@ -13,10 +13,11 @@ void main() {
}); });
testWidgets('Default values are used when no NavigationRail or NavigationRailThemeData properties are specified', (WidgetTester tester) async { testWidgets('Default values are used when no NavigationRail or NavigationRailThemeData properties are specified', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light(useMaterial3: true);
// Material 3 defaults // Material 3 defaults
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData.light().copyWith(useMaterial3: true), theme: theme,
home: Scaffold( home: Scaffold(
body: NavigationRail( body: NavigationRail(
selectedIndex: 0, selectedIndex: 0,
...@@ -26,21 +27,21 @@ void main() { ...@@ -26,21 +27,21 @@ void main() {
), ),
); );
expect(_railMaterial(tester).color, ThemeData().colorScheme.surface); expect(_railMaterial(tester).color, theme.colorScheme.surface);
expect(_railMaterial(tester).elevation, 0); expect(_railMaterial(tester).elevation, 0);
expect(_destinationSize(tester).width, 80.0); expect(_destinationSize(tester).width, 80.0);
expect(_selectedIconTheme(tester).size, 24.0); expect(_selectedIconTheme(tester).size, 24.0);
expect(_selectedIconTheme(tester).color, ThemeData().colorScheme.onSecondaryContainer); expect(_selectedIconTheme(tester).color, theme.colorScheme.onSecondaryContainer);
expect(_selectedIconTheme(tester).opacity, null); expect(_selectedIconTheme(tester).opacity, null);
expect(_unselectedIconTheme(tester).size, 24.0); expect(_unselectedIconTheme(tester).size, 24.0);
expect(_unselectedIconTheme(tester).color, ThemeData().colorScheme.onSurface); expect(_unselectedIconTheme(tester).color, theme.colorScheme.onSurfaceVariant);
expect(_unselectedIconTheme(tester).opacity, null); expect(_unselectedIconTheme(tester).opacity, null);
expect(_selectedLabelStyle(tester).fontSize, 14.0); expect(_selectedLabelStyle(tester).fontSize, 14.0);
expect(_unselectedLabelStyle(tester).fontSize, 14.0); expect(_unselectedLabelStyle(tester).fontSize, 14.0);
expect(_destinationsAlign(tester).alignment, Alignment.topCenter); expect(_destinationsAlign(tester).alignment, Alignment.topCenter);
expect(_labelType(tester), NavigationRailLabelType.none); expect(_labelType(tester), NavigationRailLabelType.none);
expect(find.byType(NavigationIndicator), findsWidgets); expect(find.byType(NavigationIndicator), findsWidgets);
expect(_indicatorDecoration(tester)?.color, ThemeData().colorScheme.secondaryContainer); expect(_indicatorDecoration(tester)?.color, theme.colorScheme.secondaryContainer);
expect(_indicatorDecoration(tester)?.shape, const StadiumBorder()); expect(_indicatorDecoration(tester)?.shape, const StadiumBorder());
final InkResponse inkResponse = tester.allWidgets.firstWhere((Widget object) => object.runtimeType.toString() == '_IndicatorInkWell') as InkResponse; final InkResponse inkResponse = tester.allWidgets.firstWhere((Widget object) => object.runtimeType.toString() == '_IndicatorInkWell') as InkResponse;
expect(inkResponse.customBorder, const StadiumBorder()); expect(inkResponse.customBorder, const StadiumBorder());
......
...@@ -1016,20 +1016,25 @@ void main() { ...@@ -1016,20 +1016,25 @@ void main() {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
int? groupValue = 0; int? groupValue = 0;
final Color? hoverColor = Colors.orange[500]; final Color? hoverColor = Colors.orange[500];
final ThemeData theme = ThemeData();
final bool material3 = theme.useMaterial3;
Widget buildApp({bool enabled = true}) { Widget buildApp({bool enabled = true}) {
return wrap( return wrap(
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) { child: MaterialApp(
return RadioListTile<int>( theme: theme,
value: 0, home: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
onChanged: enabled ? (int? newValue) { return RadioListTile<int>(
setState(() { value: 0,
groupValue = newValue; onChanged: enabled ? (int? newValue) {
}); setState(() {
} : null, groupValue = newValue;
hoverColor: hoverColor, });
groupValue: groupValue, } : null,
); hoverColor: hoverColor,
}), groupValue: groupValue,
);
}),
),
); );
} }
await tester.pumpWidget(buildApp()); await tester.pumpWidget(buildApp());
...@@ -1040,8 +1045,8 @@ void main() { ...@@ -1040,8 +1045,8 @@ void main() {
Material.of(tester.element(find.byType(Radio<int>))), Material.of(tester.element(find.byType(Radio<int>))),
paints paints
..rect() ..rect()
..circle(color: const Color(0xff2196f3)) ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xff2196f3))
..circle(color: const Color(0xff2196f3)), ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xff2196f3)),
); );
// Start hovering // Start hovering
...@@ -1069,8 +1074,8 @@ void main() { ...@@ -1069,8 +1074,8 @@ void main() {
Material.of(tester.element(find.byType(Radio<int>))), Material.of(tester.element(find.byType(Radio<int>))),
paints paints
..rect() ..rect()
..circle(color: const Color(0x61000000)) ..circle(color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000))
..circle(color: const Color(0x61000000)), ..circle(color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000)),
); );
}); });
...@@ -1096,15 +1101,20 @@ void main() { ...@@ -1096,15 +1101,20 @@ void main() {
return null; return null;
} }
final ThemeData theme = ThemeData();
final bool material3 = theme.useMaterial3;
Widget buildRadio({bool active = false, bool useOverlay = true}) { Widget buildRadio({bool active = false, bool useOverlay = true}) {
return wrap( return wrap(
child: RadioListTile<bool>( child: MaterialApp(
value: active, theme: theme,
groupValue: true, home: RadioListTile<bool>(
onChanged: (_) { }, value: active,
fillColor: const MaterialStatePropertyAll<Color>(fillColor), groupValue: true,
overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, onChanged: (_) { },
hoverColor: hoverColor, fillColor: const MaterialStatePropertyAll<Color>(fillColor),
overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null,
hoverColor: hoverColor,
),
), ),
); );
} }
...@@ -1115,11 +1125,13 @@ void main() { ...@@ -1115,11 +1125,13 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
paints..circle() material3 ? (paints..circle(
..circle( color: fillColor.withAlpha(kRadialReactionAlpha),
color: fillColor.withAlpha(kRadialReactionAlpha), radius: 20,
radius: 20, )) : (paints..circle()..circle(
), color: fillColor.withAlpha(kRadialReactionAlpha),
radius: 20,
)),
reason: 'Default inactive pressed Radio should have overlay color from fillColor', reason: 'Default inactive pressed Radio should have overlay color from fillColor',
); );
...@@ -1129,11 +1141,13 @@ void main() { ...@@ -1129,11 +1141,13 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
paints..circle() material3 ? (paints..circle(
..circle( color: fillColor.withAlpha(kRadialReactionAlpha),
color: fillColor.withAlpha(kRadialReactionAlpha), radius: 20,
radius: 20, )) : (paints..circle()..circle(
), color: fillColor.withAlpha(kRadialReactionAlpha),
radius: 20,
)),
reason: 'Default active pressed Radio should have overlay color from fillColor', reason: 'Default active pressed Radio should have overlay color from fillColor',
); );
...@@ -1143,11 +1157,13 @@ void main() { ...@@ -1143,11 +1157,13 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
paints..circle() material3 ? (paints..circle(
..circle( color: inactivePressedOverlayColor,
color: inactivePressedOverlayColor, radius: 20,
radius: 20, )) : (paints..circle()..circle(
), color: inactivePressedOverlayColor,
radius: 20,
)),
reason: 'Inactive pressed Radio should have overlay color: $inactivePressedOverlayColor', reason: 'Inactive pressed Radio should have overlay color: $inactivePressedOverlayColor',
); );
...@@ -1157,11 +1173,13 @@ void main() { ...@@ -1157,11 +1173,13 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
paints..circle() material3 ? (paints..circle(
..circle( color: activePressedOverlayColor,
color: activePressedOverlayColor, radius: 20,
radius: 20, )) : (paints..circle()..circle(
), color: activePressedOverlayColor,
radius: 20,
)),
reason: 'Active pressed Radio should have overlay color: $activePressedOverlayColor', reason: 'Active pressed Radio should have overlay color: $activePressedOverlayColor',
); );
...@@ -1177,11 +1195,13 @@ void main() { ...@@ -1177,11 +1195,13 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
paints material3 ? (paints..circle(
..circle( color: hoverOverlayColor,
color: hoverOverlayColor, radius: 20,
radius: 20, )) : (paints..circle(
), color: hoverOverlayColor,
radius: 20,
)),
reason: 'Hovered Radio should use overlay color $hoverOverlayColor over $hoverColor', reason: 'Hovered Radio should use overlay color $hoverOverlayColor over $hoverColor',
); );
}); });
......
...@@ -474,6 +474,7 @@ void main() { ...@@ -474,6 +474,7 @@ void main() {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
int? groupValue = 0; int? groupValue = 0;
const Key radioKey = Key('radio'); const Key radioKey = Key('radio');
final bool material3 = theme.useMaterial3;
Widget buildApp({bool enabled = true}) { Widget buildApp({bool enabled = true}) {
return MaterialApp( return MaterialApp(
theme: theme, theme: theme,
...@@ -511,12 +512,12 @@ void main() { ...@@ -511,12 +512,12 @@ void main() {
Material.of(tester.element(find.byKey(radioKey))), Material.of(tester.element(find.byKey(radioKey))),
paints paints
..rect( ..rect(
color: const Color(0xffffffff), color: const Color(0xffffffff),
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
) )
..circle(color: Colors.orange[500]) ..circle(color: Colors.orange[500])
..circle(color: const Color(0xff2196f3)) ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xff2196f3))
..circle(color: const Color(0xff2196f3)), ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xff2196f3)),
); );
// Check when the radio isn't selected. // Check when the radio isn't selected.
...@@ -549,8 +550,8 @@ void main() { ...@@ -549,8 +550,8 @@ void main() {
color: const Color(0xffffffff), color: const Color(0xffffffff),
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
) )
..circle(color: const Color(0x61000000)) ..circle(color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000))
..circle(color: const Color(0x61000000)), ..circle(color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000)),
); );
}); });
...@@ -558,6 +559,7 @@ void main() { ...@@ -558,6 +559,7 @@ void main() {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
int? groupValue = 0; int? groupValue = 0;
const Key radioKey = Key('radio'); const Key radioKey = Key('radio');
final bool material3 = theme.useMaterial3;
Widget buildApp({bool enabled = true}) { Widget buildApp({bool enabled = true}) {
return MaterialApp( return MaterialApp(
theme: theme, theme: theme,
...@@ -596,8 +598,8 @@ void main() { ...@@ -596,8 +598,8 @@ void main() {
color: const Color(0xffffffff), color: const Color(0xffffffff),
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
) )
..circle(color: const Color(0xff2196f3)) ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xff2196f3))
..circle(color: const Color(0xff2196f3)), ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xff2196f3)),
); );
// Start hovering // Start hovering
...@@ -632,8 +634,8 @@ void main() { ...@@ -632,8 +634,8 @@ void main() {
color: const Color(0xffffffff), color: const Color(0xffffffff),
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
) )
..circle(color: const Color(0x61000000)) ..circle(color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000))
..circle(color: const Color(0x61000000)), ..circle(color: material3 ? theme.colorScheme.onSurface.withOpacity(0.38) : const Color(0x61000000)),
); );
}); });
...@@ -1262,6 +1264,7 @@ void main() { ...@@ -1262,6 +1264,7 @@ void main() {
}); });
testWidgets('Radio button default colors', (WidgetTester tester) async { testWidgets('Radio button default colors', (WidgetTester tester) async {
final bool material3 = theme.useMaterial3;
Widget buildRadio({bool enabled = true, bool selected = true}) { Widget buildRadio({bool enabled = true, bool selected = true}) {
return MaterialApp( return MaterialApp(
theme: theme, theme: theme,
...@@ -1281,8 +1284,8 @@ void main() { ...@@ -1281,8 +1284,8 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
paints paints
..circle(color: const Color(0xFF2196F3)) // Outer circle - blue primary value ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xFF2196F3)) // Outer circle - primary value
..circle(color: const Color(0xFF2196F3))..restore(), // Inner circle - blue primary value ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xFF2196F3))..restore(), // Inner circle - primary value
); );
await tester.pumpWidget(Container()); await tester.pumpWidget(Container());
...@@ -1293,7 +1296,7 @@ void main() { ...@@ -1293,7 +1296,7 @@ void main() {
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
paints paints
..save() ..save()
..circle(color: const Color(0xFF2196F3)) ..circle(color: material3 ? theme.colorScheme.primary : const Color(0xFF2196F3))
..restore(), ..restore(),
); );
...@@ -1365,7 +1368,7 @@ void main() { ...@@ -1365,7 +1368,7 @@ void main() {
expect( expect(
Material.of(tester.element(find.byType(Radio<bool>))), Material.of(tester.element(find.byType(Radio<bool>))),
material3 material3
? (paints..circle(color: colors.primary.withOpacity(0.12))..circle(color: colors.onSurface.withOpacity(1))) ? (paints..circle(color: colors.primary.withOpacity(0.12))..circle(color: colors.onSurfaceVariant.withOpacity(1)))
: (paints..circle(color: theme.unselectedWidgetColor.withAlpha(0x1F))..circle(color: theme.unselectedWidgetColor)) : (paints..circle(color: theme.unselectedWidgetColor.withAlpha(0x1F))..circle(color: theme.unselectedWidgetColor))
); );
......
...@@ -98,7 +98,10 @@ void main() { ...@@ -98,7 +98,10 @@ void main() {
testWidgets('Passing no SnackBarThemeData returns defaults', (WidgetTester tester) async { testWidgets('Passing no SnackBarThemeData returns defaults', (WidgetTester tester) async {
const String text = 'I am a snack bar.'; const String text = 'I am a snack bar.';
final ThemeData theme = ThemeData();
final bool material3 = theme.useMaterial3;
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
theme: theme,
home: Scaffold( home: Scaffold(
body: Builder( body: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
...@@ -123,8 +126,10 @@ void main() { ...@@ -123,8 +126,10 @@ void main() {
final Material material = _getSnackBarMaterial(tester); final Material material = _getSnackBarMaterial(tester);
final RenderParagraph content = _getSnackBarTextRenderObject(tester, text); final RenderParagraph content = _getSnackBarTextRenderObject(tester, text);
expect(content.text.style, Typography.material2018().white.titleMedium); expect(content.text.style, material3
expect(material.color, const Color(0xFF333333)); ? Typography.material2021().englishLike.bodyMedium?.merge(Typography.material2021().black.bodyMedium).copyWith(color: theme.colorScheme.onInverseSurface, decorationColor: theme.colorScheme.onSurface)
: Typography.material2018().white.titleMedium);
expect(material.color, material3 ? theme.colorScheme.inverseSurface : const Color(0xFF333333));
expect(material.elevation, 6.0); expect(material.elevation, 6.0);
expect(material.shape, null); expect(material.shape, null);
}); });
......
...@@ -217,9 +217,12 @@ void main() { ...@@ -217,9 +217,12 @@ void main() {
testWidgets('Stepper button test', (WidgetTester tester) async { testWidgets('Stepper button test', (WidgetTester tester) async {
bool continuePressed = false; bool continuePressed = false;
bool cancelPressed = false; bool cancelPressed = false;
final ThemeData theme = ThemeData();
final bool material3 = theme.useMaterial3;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: theme,
home: Material( home: Material(
child: Stepper( child: Stepper(
type: StepperType.horizontal, type: StepperType.horizontal,
...@@ -250,8 +253,8 @@ void main() { ...@@ -250,8 +253,8 @@ void main() {
), ),
); );
await tester.tap(find.text('CONTINUE')); await tester.tap(find.text(material3 ? 'Continue' : 'CONTINUE'));
await tester.tap(find.text('CANCEL')); await tester.tap(find.text(material3 ? 'Cancel' : 'CANCEL'));
expect(continuePressed, isTrue); expect(continuePressed, isTrue);
expect(cancelPressed, isTrue); expect(cancelPressed, isTrue);
...@@ -857,33 +860,39 @@ testWidgets('Stepper custom indexed controls test', (WidgetTester tester) async ...@@ -857,33 +860,39 @@ testWidgets('Stepper custom indexed controls test', (WidgetTester tester) async
} }
const OutlinedBorder buttonShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2))); const OutlinedBorder buttonShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2)));
const Rect continueButtonRect = Rect.fromLTRB(24.0, 212.0, 168.0, 260.0);
const Rect cancelButtonRect = Rect.fromLTRB(176.0, 212.0, 292.0, 260.0);
await tester.pumpWidget(buildFrame(ThemeData.light()));
expect(buttonMaterial('CONTINUE').color!.value, 0xff2196f3);
expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0xffffffff);
expect(buttonMaterial('CONTINUE').shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CONTINUE')), continueButtonRect);
expect(buttonMaterial('CANCEL').color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0x8a000000);
expect(buttonMaterial('CANCEL').shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CANCEL')), cancelButtonRect);
await tester.pumpWidget(buildFrame(ThemeData.dark())); final ThemeData themeLight = ThemeData.light();
final bool material3Light = themeLight.useMaterial3;
await tester.pumpWidget(buildFrame(themeLight));
final String continueStr = material3Light ? 'Continue' : 'CONTINUE';
final String cancelStr = material3Light ? 'Cancel' : 'CANCEL';
final Rect continueButtonRect = material3Light ? const Rect.fromLTRB(24.0, 212.0, 169.0, 260.0) : const Rect.fromLTRB(24.0, 212.0, 168.0, 260.0);
final Rect cancelButtonRect = material3Light ? const Rect.fromLTRB(177.0, 212.0, 294.0, 260.0) : const Rect.fromLTRB(176.0, 212.0, 292.0, 260.0);
expect(buttonMaterial(continueStr).color!.value, material3Light ? themeLight.colorScheme.primary.value : 0xff2196f3);
expect(buttonMaterial(continueStr).textStyle!.color!.value, 0xffffffff);
expect(buttonMaterial(continueStr).shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, continueStr)), continueButtonRect);
expect(buttonMaterial(cancelStr).color!.value, 0);
expect(buttonMaterial(cancelStr).textStyle!.color!.value, 0x8a000000);
expect(buttonMaterial(cancelStr).shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, cancelStr)), cancelButtonRect);
final ThemeData themeDark = ThemeData.dark();
final bool material3Dark = themeDark.useMaterial3;
await tester.pumpWidget(buildFrame(themeDark));
await tester.pumpAndSettle(); // Complete the theme animation. await tester.pumpAndSettle(); // Complete the theme animation.
expect(buttonMaterial('CONTINUE').color!.value, 0); expect(buttonMaterial(continueStr).color!.value, 0);
expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0xffffffff); expect(buttonMaterial(continueStr).textStyle!.color!.value, material3Dark ? themeDark.colorScheme.onSurface.value : 0xffffffff);
expect(buttonMaterial('CONTINUE').shape, buttonShape); expect(buttonMaterial(continueStr).shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CONTINUE')), continueButtonRect); expect(tester.getRect(find.widgetWithText(TextButton, continueStr)), continueButtonRect);
expect(buttonMaterial('CANCEL').color!.value, 0); expect(buttonMaterial(cancelStr).color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0xb3ffffff); expect(buttonMaterial(cancelStr).textStyle!.color!.value, 0xb3ffffff);
expect(buttonMaterial('CANCEL').shape, buttonShape); expect(buttonMaterial(cancelStr).shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CANCEL')), cancelButtonRect); expect(tester.getRect(find.widgetWithText(TextButton, cancelStr)), cancelButtonRect);
}); });
testWidgets('Stepper disabled button styles', (WidgetTester tester) async { testWidgets('Stepper disabled button styles', (WidgetTester tester) async {
...@@ -910,22 +919,28 @@ testWidgets('Stepper custom indexed controls test', (WidgetTester tester) async ...@@ -910,22 +919,28 @@ testWidgets('Stepper custom indexed controls test', (WidgetTester tester) async
); );
} }
await tester.pumpWidget(buildFrame(ThemeData.light())); final ThemeData themeLight = ThemeData.light();
final bool material3Light = themeLight.useMaterial3;
await tester.pumpWidget(buildFrame(themeLight));
expect(buttonMaterial('CONTINUE').color!.value, 0); final String continueStr = material3Light ? 'Continue' : 'CONTINUE';
expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0x61000000); final String cancelStr = material3Light ? 'Cancel' : 'CANCEL';
expect(buttonMaterial(continueStr).color!.value, 0);
expect(buttonMaterial(continueStr).textStyle!.color!.value, material3Light ? themeLight.colorScheme.onSurface.withOpacity(0.38).value : 0x61000000);
expect(buttonMaterial('CANCEL').color!.value, 0); expect(buttonMaterial(cancelStr).color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0x61000000); expect(buttonMaterial(cancelStr).textStyle!.color!.value, material3Light ? themeLight.colorScheme.onSurface.withOpacity(0.38).value : 0x61000000);
await tester.pumpWidget(buildFrame(ThemeData.dark())); final ThemeData themeDark = ThemeData.dark();
final bool material3Dark = themeDark.useMaterial3;
await tester.pumpWidget(buildFrame(themeDark));
await tester.pumpAndSettle(); // Complete the theme animation. await tester.pumpAndSettle(); // Complete the theme animation.
expect(buttonMaterial('CONTINUE').color!.value, 0); expect(buttonMaterial(continueStr).color!.value, 0);
expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0x61ffffff); expect(buttonMaterial(continueStr).textStyle!.color!.value, material3Dark ? themeDark.colorScheme.onSurface.withOpacity(0.38).value : 0x61ffffff);
expect(buttonMaterial('CANCEL').color!.value, 0); expect(buttonMaterial(cancelStr).color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0x61ffffff); expect(buttonMaterial(cancelStr).textStyle!.color!.value, material3Dark ? themeDark.colorScheme.onSurface.withOpacity(0.38).value : 0x61ffffff);
}); });
testWidgets('Vertical and Horizontal Stepper physics test', (WidgetTester tester) async { testWidgets('Vertical and Horizontal Stepper physics test', (WidgetTester tester) async {
......
...@@ -358,7 +358,7 @@ void main() { ...@@ -358,7 +358,7 @@ void main() {
? (paints ? (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..rrect(color: defaultOutlineColor, strokeWidth: defaultOutlineWidth) ..rrect(color: defaultOutlineColor, strokeWidth: defaultOutlineWidth)
..rrect(color: defaultThumbColor)..paragraph(offset: const Offset(12, 16))) ..rrect(color: defaultThumbColor)..paragraph(offset: const Offset(12, 12)))
: (paints : (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..rrect(color: defaultOutlineColor, strokeWidth: defaultOutlineWidth) ..rrect(color: defaultOutlineColor, strokeWidth: defaultOutlineWidth)
...@@ -475,6 +475,7 @@ void main() { ...@@ -475,6 +475,7 @@ void main() {
material3 material3
? (paints ? (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)
..rrect()
..rrect(color: selectedThumbColor)) ..rrect(color: selectedThumbColor))
: (paints : (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)
......
...@@ -60,9 +60,11 @@ void main() { ...@@ -60,9 +60,11 @@ void main() {
}); });
testWidgets('Empty textSelectionTheme will use defaults', (WidgetTester tester) async { testWidgets('Empty textSelectionTheme will use defaults', (WidgetTester tester) async {
const Color defaultCursorColor = Color(0xff2196f3); final ThemeData theme = ThemeData();
const Color defaultSelectionColor = Color(0x662196f3); final bool material3 = theme.useMaterial3;
const Color defaultSelectionHandleColor = Color(0xff2196f3); final Color defaultCursorColor = material3 ? theme.colorScheme.primary : const Color(0xff2196f3);
final Color defaultSelectionColor = material3 ? theme.colorScheme.primary.withOpacity(0.40) : const Color(0x662196f3);
final Color defaultSelectionHandleColor = material3 ? theme.colorScheme.primary : const Color(0xff2196f3);
EditableText.debugDeterministicCursor = true; EditableText.debugDeterministicCursor = true;
addTearDown(() { addTearDown(() {
...@@ -70,8 +72,9 @@ void main() { ...@@ -70,8 +72,9 @@ void main() {
}); });
// Test TextField's cursor & selection color. // Test TextField's cursor & selection color.
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( MaterialApp(
home: Material( theme: theme,
home: const Material(
child: TextField(autofocus: true), child: TextField(autofocus: true),
), ),
), ),
...@@ -82,7 +85,7 @@ void main() { ...@@ -82,7 +85,7 @@ void main() {
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText)); final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable; final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, defaultCursorColor); expect(renderEditable.cursorColor, defaultCursorColor);
expect(renderEditable.selectionColor?.value, defaultSelectionColor.value); expect(renderEditable.selectionColor, defaultSelectionColor);
// Test the selection handle color. // Test the selection handle color.
await tester.pumpWidget( await tester.pumpWidget(
......
...@@ -11,12 +11,15 @@ void main() { ...@@ -11,12 +11,15 @@ void main() {
group('FloatingActionButton', () { group('FloatingActionButton', () {
const BoxConstraints defaultFABConstraints = BoxConstraints.tightFor(width: 56.0, height: 56.0); const BoxConstraints defaultFABConstraints = BoxConstraints.tightFor(width: 56.0, height: 56.0);
const ShapeBorder defaultFABShape = CircleBorder(); const ShapeBorder defaultFABShape = CircleBorder();
const ShapeBorder defaultFABShapeM3 = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0)));
const EdgeInsets defaultFABPadding = EdgeInsets.zero; const EdgeInsets defaultFABPadding = EdgeInsets.zero;
testWidgets('theme: ThemeData.light(), enabled: true', (WidgetTester tester) async { testWidgets('theme: ThemeData.light(), enabled: true', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light();
final bool material3 = theme.useMaterial3;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData.light(), theme: theme,
home: Center( home: Center(
child: FloatingActionButton( child: FloatingActionButton(
onPressed: () { }, // button.enabled == true onPressed: () { }, // button.enabled == true
...@@ -28,22 +31,24 @@ void main() { ...@@ -28,22 +31,24 @@ void main() {
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton)); final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
expect(raw.enabled, true); expect(raw.enabled, true);
expect(raw.textStyle!.color, const Color(0xffffffff)); expect(raw.textStyle!.color, material3 ? theme.colorScheme.onPrimaryContainer : const Color(0xffffffff));
expect(raw.fillColor, const Color(0xff2196f3)); expect(raw.fillColor, material3 ? theme.colorScheme.primaryContainer : const Color(0xff2196f3));
expect(raw.elevation, 6.0); expect(raw.elevation, 6.0);
expect(raw.highlightElevation, 12.0); expect(raw.highlightElevation, material3 ? 6.0 : 12.0);
expect(raw.disabledElevation, 6.0); expect(raw.disabledElevation, 6.0);
expect(raw.constraints, defaultFABConstraints); expect(raw.constraints, defaultFABConstraints);
expect(raw.padding, defaultFABPadding); expect(raw.padding, defaultFABPadding);
expect(raw.shape, defaultFABShape); expect(raw.shape, material3 ? defaultFABShapeM3 : defaultFABShape);
expect(raw.animationDuration, defaultButtonDuration); expect(raw.animationDuration, defaultButtonDuration);
expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded); expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded);
}); });
testWidgets('theme: ThemeData.light(), enabled: false', (WidgetTester tester) async { testWidgets('theme: ThemeData.light(), enabled: false', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light();
final bool material3 = theme.useMaterial3;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData.light(), theme: theme,
home: const Center( home: const Center(
child: FloatingActionButton( child: FloatingActionButton(
onPressed: null, // button.enabled == false onPressed: null, // button.enabled == false
...@@ -55,16 +60,16 @@ void main() { ...@@ -55,16 +60,16 @@ void main() {
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton)); final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
expect(raw.enabled, false); expect(raw.enabled, false);
expect(raw.textStyle!.color, const Color(0xffffffff)); expect(raw.textStyle!.color, material3 ? theme.colorScheme.onPrimaryContainer : const Color(0xffffffff));
expect(raw.fillColor, const Color(0xff2196f3)); expect(raw.fillColor, material3 ? theme.colorScheme.primaryContainer : const Color(0xff2196f3));
// highlightColor, disabled button can't be pressed // highlightColor, disabled button can't be pressed
// splashColor, disabled button doesn't splash // splashColor, disabled button doesn't splash
expect(raw.elevation, 6.0); expect(raw.elevation, 6.0);
expect(raw.highlightElevation, 12.0); expect(raw.highlightElevation, material3 ? 6.0 : 12.0);
expect(raw.disabledElevation, 6.0); expect(raw.disabledElevation, 6.0);
expect(raw.constraints, defaultFABConstraints); expect(raw.constraints, defaultFABConstraints);
expect(raw.padding, defaultFABPadding); expect(raw.padding, defaultFABPadding);
expect(raw.shape, defaultFABShape); expect(raw.shape, material3 ? defaultFABShapeM3 : defaultFABShape);
expect(raw.animationDuration, defaultButtonDuration); expect(raw.animationDuration, defaultButtonDuration);
expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded); expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded);
}); });
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
@TestOn('!chrome') @TestOn('!chrome')
library; library;
import 'dart:math' as math;
import 'dart:ui'; import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -710,7 +711,7 @@ void main() { ...@@ -710,7 +711,7 @@ void main() {
testWidgets('OK Cancel button and helpText layout', (WidgetTester tester) async { testWidgets('OK Cancel button and helpText layout', (WidgetTester tester) async {
Widget buildFrame(TextDirection textDirection) { Widget buildFrame(TextDirection textDirection) {
return MaterialApp( return MaterialApp(
theme: ThemeData.light().copyWith(useMaterial3: materialType == MaterialType.material3), theme: ThemeData(useMaterial3: materialType == MaterialType.material3),
home: Material( home: Material(
child: Center( child: Center(
child: Builder( child: Builder(
...@@ -752,8 +753,8 @@ void main() { ...@@ -752,8 +753,8 @@ void main() {
expect(tester.getBottomRight(find.text(cancelString)).dx, 582); expect(tester.getBottomRight(find.text(cancelString)).dx, 582);
case MaterialType.material3: case MaterialType.material3:
expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(138, 129))); expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(138, 129)));
expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(292.0, 143.0))); expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(295.0, 149.0)));
expect(tester.getBottomLeft(find.text(okString)).dx, 616); expect(tester.getBottomLeft(find.text(okString)).dx, 615.5);
expect(tester.getBottomRight(find.text(cancelString)).dx, 578); expect(tester.getBottomRight(find.text(cancelString)).dx, 578);
} }
...@@ -774,10 +775,10 @@ void main() { ...@@ -774,10 +775,10 @@ void main() {
expect(tester.getBottomRight(find.text(okString)).dx, 184); expect(tester.getBottomRight(find.text(okString)).dx, 184);
expect(tester.getBottomLeft(find.text(cancelString)).dx, 218); expect(tester.getBottomLeft(find.text(cancelString)).dx, 218);
case MaterialType.material3: case MaterialType.material3:
expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(508, 129))); expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(505.0, 129.0)));
expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(662, 143))); expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(662, 149)));
expect(tester.getBottomLeft(find.text(okString)).dx, 156); expect(tester.getBottomLeft(find.text(okString)).dx, 155.5);
expect(tester.getBottomRight(find.text(okString)).dx, 184); expect(tester.getBottomRight(find.text(okString)).dx, 184.5);
expect(tester.getBottomLeft(find.text(cancelString)).dx, 222); expect(tester.getBottomLeft(find.text(cancelString)).dx, 222);
} }
...@@ -808,7 +809,7 @@ void main() { ...@@ -808,7 +809,7 @@ void main() {
final double amHeight2x = tester.getSize(find.text(amString)).height; final double amHeight2x = tester.getSize(find.text(amString)).height;
expect(tester.getSize(find.text('41')).height, equals(minutesDisplayHeight)); expect(tester.getSize(find.text('41')).height, equals(minutesDisplayHeight));
expect(amHeight2x, greaterThanOrEqualTo(amHeight * 2)); expect(amHeight2x, math.min(38.0, amHeight * 2));
await tester.tap(find.text(okString)); // dismiss the dialog await tester.tap(find.text(okString)); // dismiss the dialog
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -822,7 +823,7 @@ void main() { ...@@ -822,7 +823,7 @@ void main() {
); );
expect(tester.getSize(find.text('41')).height, equals(minutesDisplayHeight)); expect(tester.getSize(find.text('41')).height, equals(minutesDisplayHeight));
expect(tester.getSize(find.text(amString)).height, equals(amHeight2x)); expect(tester.getSize(find.text(amString)).height, math.min(38.0, amHeight * 2));
}); });
group('showTimePicker avoids overlapping display features', () { group('showTimePicker avoids overlapping display features', () {
...@@ -1694,55 +1695,53 @@ Future<void> mediaQueryBoilerplate( ...@@ -1694,55 +1695,53 @@ Future<void> mediaQueryBoilerplate(
Orientation? orientation, Orientation? orientation,
}) async { }) async {
await tester.pumpWidget( await tester.pumpWidget(
Builder(builder: (BuildContext context) { Theme(
return Theme( data: ThemeData(useMaterial3: materialType == MaterialType.material3),
data: Theme.of(context).copyWith(useMaterial3: materialType == MaterialType.material3), child: Localizations(
child: Localizations( locale: const Locale('en', 'US'),
locale: const Locale('en', 'US'), delegates: const <LocalizationsDelegate<dynamic>>[
delegates: const <LocalizationsDelegate<dynamic>>[ DefaultMaterialLocalizations.delegate,
DefaultMaterialLocalizations.delegate, DefaultWidgetsLocalizations.delegate,
DefaultWidgetsLocalizations.delegate, ],
], child: MediaQuery(
child: MediaQuery( data: MediaQueryData(
data: MediaQueryData( alwaysUse24HourFormat: alwaysUse24HourFormat,
alwaysUse24HourFormat: alwaysUse24HourFormat, textScaleFactor: textScaleFactor,
textScaleFactor: textScaleFactor, accessibleNavigation: accessibleNavigation,
accessibleNavigation: accessibleNavigation, size: tester.view.physicalSize / tester.view.devicePixelRatio,
size: tester.view.physicalSize / tester.view.devicePixelRatio, ),
), child: Material(
child: Material( child: Center(
child: Center( child: Directionality(
child: Directionality( textDirection: TextDirection.ltr,
textDirection: TextDirection.ltr, child: Navigator(
child: Navigator( onGenerateRoute: (RouteSettings settings) {
onGenerateRoute: (RouteSettings settings) { return MaterialPageRoute<void>(builder: (BuildContext context) {
return MaterialPageRoute<void>(builder: (BuildContext context) { return TextButton(
return TextButton( onPressed: () {
onPressed: () { showTimePicker(
showTimePicker( context: context,
context: context, initialTime: initialTime,
initialTime: initialTime, initialEntryMode: entryMode,
initialEntryMode: entryMode, helpText: helpText,
helpText: helpText, hourLabelText: hourLabelText,
hourLabelText: hourLabelText, minuteLabelText: minuteLabelText,
minuteLabelText: minuteLabelText, errorInvalidText: errorInvalidText,
errorInvalidText: errorInvalidText, onEntryModeChanged: onEntryModeChange,
onEntryModeChanged: onEntryModeChange, orientation: orientation,
orientation: orientation, );
); },
}, child: const Text('X'),
child: const Text('X'), );
); });
}); },
},
),
), ),
), ),
), ),
), ),
), ),
); ),
}), ),
); );
if (tapButton) { if (tapButton) {
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment