Update button tests for Material 3 by default (#128628)

This commit is contained in:
Hans Muller 2023-06-12 09:11:34 -07:00 committed by GitHub
parent 353b8bc87d
commit c5a81d1b35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 693 additions and 756 deletions

View File

@ -738,7 +738,9 @@ void main() {
testWidgets('Does ElevatedButton contribute semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: ElevatedButton(
@ -753,6 +755,7 @@ void main() {
),
),
),
),
);
expect(semantics, hasSemantics(
@ -790,7 +793,7 @@ void main() {
Widget buildFrame(MaterialTapTargetSize tapTargetSize, Key key) {
return Theme(
data: ThemeData(materialTapTargetSize: tapTargetSize),
data: ThemeData(useMaterial3: false, materialTapTargetSize: tapTargetSize),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
@ -838,9 +841,7 @@ void main() {
Future<void> buildTest(VisualDensity visualDensity, {bool useText = false}) async {
return tester.pumpWidget(
MaterialApp(
// Test was setup using fonts from Material 2, so make sure we always
// test against englishLike2014.
theme: ThemeData(textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Directionality(
textDirection: TextDirection.rtl,
child: Center(
@ -1033,10 +1034,8 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
useMaterial3: false,
colorScheme: const ColorScheme.light(),
// Force Material 2 defaults for the typography and size
// default values as the test was designed against these settings.
textTheme: Typography.englishLike2014,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(minimumSize: const Size(64, 36)),
),

View File

@ -14,7 +14,7 @@ import '../widgets/semantics_tester.dart';
void main() {
testWidgets('FilledButton, FilledButton.icon defaults', (WidgetTester tester) async {
const ColorScheme colorScheme = ColorScheme.light();
final ThemeData theme = ThemeData.from(colorScheme: colorScheme);
final ThemeData theme = ThemeData.from(useMaterial3: false, colorScheme: colorScheme);
// Enabled FilledButton
await tester.pumpWidget(
@ -884,7 +884,9 @@ void main() {
testWidgets('Does FilledButton contribute semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: FilledButton(
@ -899,6 +901,7 @@ void main() {
),
),
),
),
);
expect(semantics, hasSemantics(
@ -936,7 +939,7 @@ void main() {
Widget buildFrame(MaterialTapTargetSize tapTargetSize, Key key) {
return Theme(
data: ThemeData(materialTapTargetSize: tapTargetSize),
data: ThemeData(useMaterial3: false, materialTapTargetSize: tapTargetSize),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
@ -984,9 +987,7 @@ void main() {
Future<void> buildTest(VisualDensity visualDensity, {bool useText = false}) async {
return tester.pumpWidget(
MaterialApp(
// Test was setup using fonts from Material 2, so make sure we always
// test against englishLike2014.
theme: ThemeData(textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Directionality(
textDirection: TextDirection.rtl,
child: Center(
@ -1179,10 +1180,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
colorScheme: const ColorScheme.light(),
// Force Material 2 defaults for the typography and size
// default values as the test was designed against these settings.
textTheme: Typography.englishLike2014,
useMaterial3: false,
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(minimumSize: const Size(64, 36)),
),
@ -1410,7 +1408,7 @@ void main() {
const Color borderColor = Color(0xff4caf50);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(colorScheme: const ColorScheme.light(), textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Center(
child: FilledButton(
style: FilledButton.styleFrom(
@ -1599,7 +1597,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Center(
child: Column(

View File

@ -693,6 +693,7 @@ void main() {
bool resizeToAvoidBottomInset = true,
}) {
return MaterialApp(
theme: ThemeData(useMaterial3: false),
home: MediaQuery(
data: data,
child: Scaffold(
@ -1640,15 +1641,14 @@ const double _dockedOffsetY = 544.0;
const double _containedOffsetY = 544.0 + 56.0 / 2;
const double _miniFloatOffsetY = _floatOffsetY + kMiniButtonOffsetAdjustment;
Widget _singleFabScaffold(
FloatingActionButtonLocation location,
{
Widget _singleFabScaffold(FloatingActionButtonLocation location, {
bool useMaterial3 = false,
FloatingActionButtonAnimator? animator,
bool mini = false,
TextDirection textDirection = TextDirection.ltr,
}
) {
}) {
return MaterialApp(
theme: ThemeData(useMaterial3: useMaterial3),
home: Directionality(
textDirection: textDirection,
child: Scaffold(

View File

@ -19,9 +19,8 @@ import '../widgets/semantics_tester.dart';
import 'feedback_tester.dart';
void main() {
final ThemeData material3Theme = ThemeData.light().copyWith(useMaterial3: true);
final ThemeData material2Theme = ThemeData.light().copyWith(useMaterial3: false);
final ThemeData material3Theme = ThemeData(useMaterial3: true);
final ThemeData material2Theme = ThemeData(useMaterial3: false);
testWidgets('Floating Action Button control test', (WidgetTester tester) async {
bool didPressButton = false;
@ -950,6 +949,7 @@ void main() {
const Color splashColor = Color(0xcafefeed);
await tester.pumpWidget(MaterialApp(
theme: material2Theme,
home: FloatingActionButton(
onPressed: () {},
splashColor: splashColor,
@ -1051,6 +1051,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: material2Theme,
home: Scaffold(
floatingActionButton: FloatingActionButton.extended(
label: const Text('', key: labelKey),

View File

@ -23,13 +23,16 @@ void main() {
// Enabled MaterialButton
await tester.pumpWidget(
Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: MaterialButton(
onPressed: () { },
child: const Text('button'),
),
),
),
);
Material material = tester.widget<Material>(rawButtonMaterial);
expect(material.animationDuration, const Duration(milliseconds: 200));
@ -68,13 +71,16 @@ void main() {
// Disabled MaterialButton
await tester.pumpWidget(
const Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: const Directionality(
textDirection: TextDirection.ltr,
child: MaterialButton(
onPressed: null,
child: Text('button'),
),
),
),
);
material = tester.widget<Material>(rawButtonMaterial);
expect(material.animationDuration, const Duration(milliseconds: 200));
@ -442,6 +448,7 @@ void main() {
textDirection: TextDirection.ltr,
child: Theme(
data: ThemeData(
useMaterial3: false,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: buttonWidget,
@ -488,6 +495,7 @@ void main() {
textDirection: TextDirection.ltr,
child: Theme(
data: ThemeData(
useMaterial3: false,
highlightColor: themeHighlightColor1,
splashColor: themeSplashColor1,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
@ -516,6 +524,7 @@ void main() {
textDirection: TextDirection.ltr,
child: Theme(
data: ThemeData(
useMaterial3: false,
highlightColor: themeHighlightColor2,
splashColor: themeSplashColor2,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
@ -574,7 +583,10 @@ void main() {
);
// enabled button
await tester.pumpWidget(Directionality(
await tester.pumpWidget(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: MaterialButton(
@ -582,7 +594,9 @@ void main() {
onPressed: () { /* to make sure the button is enabled */ },
),
),
));
),
),
);
expect(semantics, hasSemantics(
TestSemantics.root(
@ -607,7 +621,10 @@ void main() {
));
// disabled button
await tester.pumpWidget(const Directionality(
await tester.pumpWidget(
Theme(
data: ThemeData(useMaterial3: false),
child: const Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: MaterialButton(
@ -615,7 +632,9 @@ void main() {
child: Text('Button'),
),
),
));
),
),
);
expect(semantics, hasSemantics(
TestSemantics.root(
@ -773,6 +792,7 @@ void main() {
Future<void> buildTest(VisualDensity visualDensity, {bool useText = false}) async {
return tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Directionality(
textDirection: TextDirection.rtl,
child: Center(

View File

@ -42,7 +42,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? StadiumBorder(side: BorderSide(color: colorScheme.outline))
@ -82,7 +82,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? StadiumBorder(side: BorderSide(color: colorScheme.outline))
@ -125,7 +125,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? StadiumBorder(side: BorderSide(color: colorScheme.outline))
@ -160,7 +160,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? StadiumBorder(side: BorderSide(color: colorScheme.onSurface.withOpacity(0.12)))
@ -966,7 +966,9 @@ void main() {
testWidgets('OutlinedButton contributes semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: OutlinedButton(
@ -981,6 +983,7 @@ void main() {
),
),
),
),
);
expect(semantics, hasSemantics(
@ -1011,8 +1014,7 @@ void main() {
testWidgets('OutlinedButton scales textScaleFactor', (WidgetTester tester) async {
await tester.pumpWidget(
Theme(
// Force Material 2 typography.
data: ThemeData(textTheme: Typography.englishLike2014),
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
@ -1041,7 +1043,7 @@ void main() {
await tester.pumpWidget(
Theme(
// Force Material 2 typography.
data: ThemeData(textTheme: Typography.englishLike2014),
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
@ -1072,8 +1074,7 @@ void main() {
// Set text scale large enough to expand text and button.
await tester.pumpWidget(
Theme(
// Force Material 2 typography.
data: ThemeData(textTheme: Typography.englishLike2014),
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
@ -1131,7 +1132,7 @@ void main() {
Future<void> buildTest(VisualDensity visualDensity, {bool useText = false}) async {
return tester.pumpWidget(
MaterialApp(
theme: ThemeData(textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Directionality(
textDirection: TextDirection.rtl,
child: Center(
@ -1261,10 +1262,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
colorScheme: const ColorScheme.light(),
// Force Material 2 defaults for the typography and size
// default values as the test was designed against these settings.
textTheme: Typography.englishLike2014,
useMaterial3: false,
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(minimumSize: const Size(64, 36)),
),
@ -1407,7 +1405,7 @@ void main() {
testWidgets('Override OutlinedButton default padding', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.from(colorScheme: const ColorScheme.light()),
theme: ThemeData(useMaterial3: false),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
@ -1677,7 +1675,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Center(
child: Column(

View File

@ -17,7 +17,9 @@ void main() {
bool pressed = false;
const Color splashColor = Color(0xff00ff00);
await tester.pumpWidget(
Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: RawMaterialButton(
@ -27,6 +29,7 @@ void main() {
),
),
),
),
);
await tester.tap(find.text('BUTTON'));
@ -45,7 +48,9 @@ void main() {
final FocusNode focusNode = FocusNode(debugLabel: 'Test Button');
const Color splashColor = Color(0xff00ff00);
await tester.pumpWidget(
Shortcuts(
Theme(
data: ThemeData(useMaterial3: false),
child: Shortcuts(
shortcuts: const <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.enter): ActivateIntent(),
SingleActivator(LogicalKeyboardKey.space): ActivateIntent(),
@ -62,6 +67,7 @@ void main() {
),
),
),
),
);
focusNode.requestFocus();
@ -175,7 +181,9 @@ void main() {
const Color fillColor = Color(0xFFEF5350);
await tester.pumpWidget(
Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: RawMaterialButton(
@ -188,6 +196,7 @@ void main() {
),
),
),
),
);
final Offset center = tester.getCenter(find.byType(InkWell));
@ -207,7 +216,9 @@ void main() {
const Color fillColor = Color(0xFFEF5350);
await tester.pumpWidget(
Directionality(
Theme(
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: RawMaterialButton(
@ -220,6 +231,7 @@ void main() {
),
),
),
),
);
final Offset top = tester.getRect(find.byType(InkWell)).topCenter;
@ -520,6 +532,7 @@ void main() {
Future<void> buildTest(VisualDensity visualDensity, {bool useText = false}) async {
return tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Directionality(
textDirection: TextDirection.rtl,
child: Center(

View File

@ -42,7 +42,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? const StadiumBorder()
: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))));
@ -77,7 +77,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? const StadiumBorder()
: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))));
@ -115,7 +115,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? const StadiumBorder()
: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))));
@ -145,7 +145,7 @@ void main() {
expect(material.clipBehavior, Clip.none);
expect(material.color, Colors.transparent);
expect(material.elevation, 0.0);
expect(material.shadowColor, material3 ? null : const Color(0xff000000));
expect(material.shadowColor, material3 ? Colors.transparent : const Color(0xff000000));
expect(material.shape, material3
? const StadiumBorder()
: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))));
@ -580,8 +580,7 @@ void main() {
testWidgets('Does TextButton scale with font scale changes', (WidgetTester tester) async {
await tester.pumpWidget(
Theme(
// Force Material 2 typography.
data: ThemeData(textTheme: Typography.englishLike2014),
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
@ -603,8 +602,7 @@ void main() {
// textScaleFactor expands text, but not button.
await tester.pumpWidget(
Theme(
// Force Material 2 typography.
data: ThemeData(textTheme: Typography.englishLike2014),
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
@ -632,8 +630,7 @@ void main() {
// Set text scale large enough to expand text and button.
await tester.pumpWidget(
Theme(
// Force Material 2 typography.
data: ThemeData(textTheme: Typography.englishLike2014),
data: ThemeData(useMaterial3: false),
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
@ -656,7 +653,7 @@ void main() {
testWidgets('TextButton size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
Widget buildFrame(MaterialTapTargetSize tapTargetSize, Key key) {
return Theme(
data: ThemeData(materialTapTargetSize: tapTargetSize),
data: ThemeData(useMaterial3: false, materialTapTargetSize: tapTargetSize),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
@ -925,7 +922,7 @@ void main() {
Future<void> buildTest(VisualDensity visualDensity, { bool useText = false }) async {
return tester.pumpWidget(
MaterialApp(
theme: ThemeData(textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Directionality(
textDirection: TextDirection.rtl,
child: Center(
@ -1065,10 +1062,8 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
useMaterial3: false,
colorScheme: const ColorScheme.light(),
// Force Material 2 defaults for the typography and size
// default values as the test was designed against these settings.
textTheme: Typography.englishLike2014,
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(minimumSize: const Size(64, 36)),
),
@ -1484,7 +1479,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(textTheme: Typography.englishLike2014),
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Center(
child: Column(

View File

@ -17,10 +17,22 @@ import '../widgets/semantics_tester.dart';
const double _defaultBorderWidth = 1.0;
Widget boilerplate({required Widget child}) {
return Directionality(
Widget boilerplate({
bool? useMaterial3,
MaterialTapTargetSize? tapTargetSize,
required Widget child,
}) {
return Theme(
data: ThemeData(
useMaterial3: useMaterial3,
materialTapTargetSize: tapTargetSize,
),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(child: child),
child: Center(
child: Material(child: child),
),
),
);
}
@ -34,8 +46,7 @@ void main() {
}
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
onPressed: (int index) {},
isSelected: const <bool>[false, true],
@ -45,7 +56,6 @@ void main() {
],
),
),
),
);
expect(
@ -70,8 +80,7 @@ void main() {
final List<bool> isSelected = <bool>[false, true];
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: StatefulBuilder(
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return boilerplate(
child: ToggleButtons(
@ -89,7 +98,6 @@ void main() {
);
},
),
),
);
expect(isSelected[0], isFalse);
@ -132,8 +140,7 @@ void main() {
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: isSelected,
children: const <Widget>[
@ -142,7 +149,6 @@ void main() {
],
),
),
),
);
expect(isSelected[0], isFalse);
@ -178,8 +184,7 @@ void main() {
(WidgetTester tester) async {
await expectLater(
() => tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false],
children: const <Widget>[
@ -189,7 +194,6 @@ void main() {
),
),
),
),
throwsA(isAssertionError.having(
(AssertionError error) => error.toString(),
'.toString()',
@ -205,8 +209,7 @@ void main() {
testWidgets('Default text style is applied', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, true],
onPressed: (int index) {},
@ -216,7 +219,6 @@ void main() {
],
),
),
),
);
TextStyle textStyle;
@ -237,8 +239,7 @@ void main() {
testWidgets('Custom text style except color is applied', (WidgetTester tester) async {
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, true],
onPressed: (int index) {},
@ -253,7 +254,6 @@ void main() {
],
),
),
),
);
TextStyle textStyle;
@ -276,8 +276,7 @@ void main() {
testWidgets('Default BoxConstraints', (WidgetTester tester) async {
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, false, false],
onPressed: (int index) {},
@ -288,7 +287,6 @@ void main() {
],
),
),
),
);
final Rect firstRect = tester.getRect(find.byType(TextButton).at(0));
@ -305,8 +303,7 @@ void main() {
testWidgets('Custom BoxConstraints', (WidgetTester tester) async {
// Test for minimum constraints
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
constraints: const BoxConstraints(
minWidth: 50.0,
@ -321,7 +318,6 @@ void main() {
],
),
),
),
);
Rect firstRect = tester.getRect(find.byType(TextButton).at(0));
@ -336,8 +332,7 @@ void main() {
// Test for maximum constraints
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
constraints: const BoxConstraints(
@ -353,7 +348,6 @@ void main() {
],
),
),
),
);
firstRect = tester.getRect(find.byType(TextButton).at(0));
@ -384,8 +378,7 @@ void main() {
}
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false],
onPressed: (int index) {},
@ -397,7 +390,6 @@ void main() {
],
),
),
),
);
// Default enabled color
@ -411,8 +403,7 @@ void main() {
);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true],
onPressed: (int index) {},
@ -424,7 +415,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
// Default selected color
@ -438,8 +428,7 @@ void main() {
);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true],
children: const <Widget>[
@ -450,7 +439,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
// Default disabled color
@ -491,8 +479,7 @@ void main() {
expect(theme.colorScheme.onSurface.withOpacity(0.38), isNot(disabledColor));
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
color: enabledColor,
isSelected: const <bool>[false],
@ -505,7 +492,6 @@ void main() {
],
),
),
),
);
// Custom enabled color
@ -513,8 +499,7 @@ void main() {
expect(iconTheme(Icons.check).data.color, enabledColor);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
selectedColor: selectedColor,
isSelected: const <bool>[true],
@ -527,7 +512,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
// Custom selected color
@ -535,8 +519,7 @@ void main() {
expect(iconTheme(Icons.check).data.color, selectedColor);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
disabledColor: disabledColor,
isSelected: const <bool>[true],
@ -548,7 +531,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
// Custom disabled color
@ -560,8 +542,7 @@ void main() {
testWidgets('Default button fillColor - unselected', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false],
onPressed: (int index) {},
@ -572,7 +553,6 @@ void main() {
],
),
),
),
);
final Material material = tester.widget<Material>(find.descendant(
@ -589,8 +569,7 @@ void main() {
testWidgets('Default button fillColor - selected', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true],
onPressed: (int index) {},
@ -601,7 +580,6 @@ void main() {
],
),
),
),
);
final Material material = tester.widget<Material>(find.descendant(
@ -618,8 +596,7 @@ void main() {
testWidgets('Default button fillColor - disabled', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true],
children: const <Widget>[
@ -629,7 +606,6 @@ void main() {
],
),
),
),
);
final Material material = tester.widget<Material>(find.descendant(
@ -646,8 +622,7 @@ void main() {
testWidgets('Custom button fillColor', (WidgetTester tester) async {
const Color customFillColor = Colors.green;
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
fillColor: customFillColor,
isSelected: const <bool>[true],
@ -659,7 +634,6 @@ void main() {
],
),
),
),
);
final Material material = tester.widget<Material>(find.descendant(
@ -684,8 +658,7 @@ void main() {
const Color selectedFillColor = Colors.yellow;
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
fillColor: selectedFillColor,
isSelected: const <bool>[false, true],
@ -696,7 +669,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
@ -705,8 +677,7 @@ void main() {
expect(buttonColor('Second child').color, selectedFillColor);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
fillColor: selectedFillColor,
isSelected: const <bool>[false, true],
@ -716,7 +687,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
@ -746,8 +716,7 @@ void main() {
}
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
fillColor: MaterialStateColor.resolveWith(getFillColor),
isSelected: const <bool>[false, true],
@ -758,7 +727,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
@ -768,8 +736,7 @@ void main() {
// disabled
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
fillColor: MaterialStateColor.resolveWith(getFillColor),
isSelected: const <bool>[false, true],
@ -779,7 +746,6 @@ void main() {
],
),
),
),
);
await tester.pumpAndSettle();
@ -792,8 +758,7 @@ void main() {
final ThemeData theme = ThemeData();
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false],
onPressed: (int index) {},
@ -803,7 +768,6 @@ void main() {
],
),
),
),
);
final Offset center = tester.getCenter(find.text('First child'));
@ -859,8 +823,7 @@ void main() {
final ThemeData theme = ThemeData();
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true],
onPressed: (int index) {},
@ -870,7 +833,6 @@ void main() {
],
),
),
),
);
final Offset center = tester.getCenter(find.text('First child'));
@ -930,8 +892,7 @@ void main() {
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
splashColor: splashColor,
highlightColor: highlightColor,
@ -945,7 +906,6 @@ void main() {
],
),
),
),
);
final Offset center = tester.getCenter(find.text('First child'));
@ -999,8 +959,7 @@ void main() {
final ThemeData theme = ThemeData();
const double defaultBorderWidth = 1.0;
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false],
onPressed: (int index) {},
@ -1009,7 +968,6 @@ void main() {
],
),
),
),
);
RenderObject toggleButtonRenderObject;
@ -1029,8 +987,7 @@ void main() {
);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true],
onPressed: (int index) {},
@ -1039,7 +996,6 @@ void main() {
],
),
),
),
);
toggleButtonRenderObject = tester.allRenderObjects.firstWhere((RenderObject object) {
@ -1058,8 +1014,7 @@ void main() {
);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false],
children: const <Widget>[
@ -1067,7 +1022,6 @@ void main() {
],
),
),
),
);
toggleButtonRenderObject = tester.allRenderObjects.firstWhere((RenderObject object) {
@ -1096,8 +1050,7 @@ void main() {
const double customWidth = 2.0;
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
borderColor: borderColor,
borderWidth: customWidth,
@ -1108,7 +1061,6 @@ void main() {
],
),
),
),
);
RenderObject toggleButtonRenderObject;
@ -1128,8 +1080,7 @@ void main() {
);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
selectedBorderColor: selectedBorderColor,
borderWidth: customWidth,
@ -1140,7 +1091,6 @@ void main() {
],
),
),
),
);
toggleButtonRenderObject = tester.allRenderObjects.firstWhere((RenderObject object) {
@ -1159,8 +1109,7 @@ void main() {
);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
disabledBorderColor: disabledBorderColor,
borderWidth: customWidth,
@ -1170,7 +1119,6 @@ void main() {
],
),
),
),
);
toggleButtonRenderObject = tester.allRenderObjects.firstWhere((RenderObject object) {
@ -1204,14 +1152,12 @@ void main() {
];
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, true, false],
children: children,
),
),
),
);
final List<Widget> toggleButtons = tester.allWidgets.where((Widget widget) {
@ -1247,14 +1193,12 @@ void main() {
];
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, true, false],
children: children,
),
),
),
);
List<Widget> toggleButtons;
@ -1299,15 +1243,13 @@ void main() {
// Update border width and widget sized to verify layout updates correctly
const double customBorderWidth = 5.0;
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
borderWidth: customBorderWidth,
isSelected: const <bool>[false, true, false],
children: childrenRebuilt,
),
),
),
);
toggleButtons = tester.allWidgets.where((Widget widget) {
@ -1331,8 +1273,8 @@ void main() {
// The point size of the fonts must be a multiple of 4 until
// https://github.com/flutter/flutter/issues/122066 is resolved.
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
useMaterial3: false,
child: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
@ -1357,7 +1299,6 @@ void main() {
],
),
),
),
);
// The test font extends 0.25 * fontSize below the baseline.
@ -1431,8 +1372,7 @@ void main() {
(WidgetTester tester) async {
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, true, false],
onPressed: (int index) {},
@ -1443,7 +1383,6 @@ void main() {
],
),
),
),
);
final List<RenderObject> toggleButtonRenderObject = tester.allRenderObjects.where((RenderObject object) {
@ -1513,8 +1452,7 @@ void main() {
(WidgetTester tester) async {
final ThemeData theme = ThemeData();
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
direction: Axis.vertical,
isSelected: const <bool>[false, true, false],
@ -1526,7 +1464,6 @@ void main() {
],
),
),
),
);
// The children should be laid out along vertical and the first child at top.
@ -1601,8 +1538,7 @@ void main() {
'VerticalDirection test when direction is vertical.',
(WidgetTester tester) async {
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
direction: Axis.vertical,
verticalDirection: VerticalDirection.up,
@ -1615,7 +1551,6 @@ void main() {
],
),
),
),
);
// The children should be laid out along vertical and the last child at top.
@ -1627,10 +1562,9 @@ void main() {
testWidgets('Tap target size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
Widget buildFrame(MaterialTapTargetSize tapTargetSize, Key key) {
return Theme(
data: ThemeData(materialTapTargetSize: tapTargetSize),
child: Material(
child: boilerplate(
return boilerplate(
useMaterial3: false,
tapTargetSize: tapTargetSize,
child: ToggleButtons(
key: key,
constraints: const BoxConstraints(minWidth: 32.0, minHeight: 32.0),
@ -1642,8 +1576,6 @@ void main() {
Text('Third'),
],
),
),
),
);
}
@ -1658,8 +1590,8 @@ void main() {
testWidgets('Tap target size is configurable', (WidgetTester tester) async {
Widget buildFrame(MaterialTapTargetSize tapTargetSize, Key key) {
return Material(
child: boilerplate(
return boilerplate(
useMaterial3: false,
child: ToggleButtons(
key: key,
tapTargetSize: tapTargetSize,
@ -1672,7 +1604,6 @@ void main() {
Text('Third'),
],
),
),
);
}
@ -1687,8 +1618,7 @@ void main() {
testWidgets('Tap target size is configurable for vertical axis', (WidgetTester tester) async {
Widget buildFrame(MaterialTapTargetSize tapTargetSize, Key key) {
return Material(
child: boilerplate(
return boilerplate(
child: ToggleButtons(
key: key,
tapTargetSize: tapTargetSize,
@ -1702,7 +1632,6 @@ void main() {
Text('3'),
],
),
),
);
}
@ -1717,10 +1646,10 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/73725
testWidgets('Border radius paint test when there is only one button', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
final ThemeData theme = ThemeData(useMaterial3: false);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
useMaterial3: false,
child: RepaintBoundary(
child: ToggleButtons(
borderRadius: const BorderRadius.all(Radius.circular(7.0)),
@ -1732,7 +1661,6 @@ void main() {
),
),
),
),
);
// The only button should be laid out at the center of the screen.
@ -1764,8 +1692,8 @@ void main() {
testWidgets('Border radius paint test when Radius.x or Radius.y equal 0.0', (WidgetTester tester) async {
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
useMaterial3: false,
child: RepaintBoundary(
child: ToggleButtons(
borderRadius: const BorderRadius.only(
@ -1782,7 +1710,6 @@ void main() {
),
),
),
),
);
await expectLater(
@ -1831,8 +1758,7 @@ void main() {
testWidgets('ToggleButtons changes mouse cursor when the button is hovered', (WidgetTester tester) async {
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: ToggleButtons(
@ -1846,7 +1772,6 @@ void main() {
),
),
),
),
);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
@ -1858,8 +1783,7 @@ void main() {
// Test default cursor
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: ToggleButtons(
@ -1872,15 +1796,13 @@ void main() {
),
),
),
),
);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
// Test default cursor when disabled
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: ToggleButtons(
@ -1892,7 +1814,6 @@ void main() {
),
),
),
),
);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
@ -1901,8 +1822,7 @@ void main() {
testWidgets('ToggleButtons focus, hover, and highlight elevations are 0', (WidgetTester tester) async {
final List<FocusNode> focusNodes = <FocusNode>[FocusNode(), FocusNode()];
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true, false],
onPressed: (int index) { },
@ -1910,7 +1830,6 @@ void main() {
children: const <Widget>[Text('one'), Text('two')],
),
),
),
);
double toggleButtonElevation(String text) {
@ -1948,8 +1867,7 @@ void main() {
testWidgets('Toggle buttons height matches MaterialTapTargetSize.padded height', (WidgetTester tester) async {
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, false, false],
onPressed: (int index) {},
@ -1960,7 +1878,6 @@ void main() {
],
),
),
),
);
final Rect firstRect = tester.getRect(find.byType(TextButton).at(0));
@ -1976,8 +1893,7 @@ void main() {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, false, false],
onPressed: (int index) {},
@ -1992,7 +1908,6 @@ void main() {
],
),
),
),
);
// Button's height is constrained to `32.0`.
@ -2064,8 +1979,7 @@ void main() {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
Material(
child: boilerplate(
boilerplate(
child: ToggleButtons(
isSelected: const <bool>[false, true],
onPressed: (int index) {},
@ -2075,7 +1989,6 @@ void main() {
],
),
),
),
);
expect(