Updated the button.icon factory constructors for NNBD (#69596)
This commit is contained in:
parent
7d539043ba
commit
23cc1401f0
@ -82,13 +82,13 @@ class ElevatedButton extends ButtonStyleButton {
|
|||||||
///
|
///
|
||||||
/// The [icon] and [label] arguments must not be null.
|
/// The [icon] and [label] arguments must not be null.
|
||||||
factory ElevatedButton.icon({
|
factory ElevatedButton.icon({
|
||||||
Key key,
|
Key? key,
|
||||||
required VoidCallback onPressed,
|
required VoidCallback? onPressed,
|
||||||
VoidCallback onLongPress,
|
VoidCallback? onLongPress,
|
||||||
ButtonStyle style,
|
ButtonStyle? style,
|
||||||
FocusNode focusNode,
|
FocusNode? focusNode,
|
||||||
bool autofocus,
|
bool? autofocus,
|
||||||
Clip clipBehavior,
|
Clip? clipBehavior,
|
||||||
required Widget icon,
|
required Widget icon,
|
||||||
required Widget label,
|
required Widget label,
|
||||||
}) = _ElevatedButtonWithIcon;
|
}) = _ElevatedButtonWithIcon;
|
||||||
|
@ -79,13 +79,13 @@ class OutlinedButton extends ButtonStyleButton {
|
|||||||
///
|
///
|
||||||
/// The [icon] and [label] arguments must not be null.
|
/// The [icon] and [label] arguments must not be null.
|
||||||
factory OutlinedButton.icon({
|
factory OutlinedButton.icon({
|
||||||
Key key,
|
Key? key,
|
||||||
required VoidCallback onPressed,
|
required VoidCallback? onPressed,
|
||||||
VoidCallback onLongPress,
|
VoidCallback? onLongPress,
|
||||||
ButtonStyle style,
|
ButtonStyle? style,
|
||||||
FocusNode focusNode,
|
FocusNode? focusNode,
|
||||||
bool autofocus,
|
bool? autofocus,
|
||||||
Clip clipBehavior,
|
Clip? clipBehavior,
|
||||||
required Widget icon,
|
required Widget icon,
|
||||||
required Widget label,
|
required Widget label,
|
||||||
}) = _OutlinedButtonWithIcon;
|
}) = _OutlinedButtonWithIcon;
|
||||||
|
@ -86,13 +86,13 @@ class TextButton extends ButtonStyleButton {
|
|||||||
///
|
///
|
||||||
/// The [icon] and [label] arguments must not be null.
|
/// The [icon] and [label] arguments must not be null.
|
||||||
factory TextButton.icon({
|
factory TextButton.icon({
|
||||||
Key key,
|
Key? key,
|
||||||
required VoidCallback onPressed,
|
required VoidCallback? onPressed,
|
||||||
VoidCallback onLongPress,
|
VoidCallback? onLongPress,
|
||||||
ButtonStyle style,
|
ButtonStyle? style,
|
||||||
FocusNode focusNode,
|
FocusNode? focusNode,
|
||||||
bool autofocus,
|
bool? autofocus,
|
||||||
Clip clipBehavior,
|
Clip? clipBehavior,
|
||||||
required Widget icon,
|
required Widget icon,
|
||||||
required Widget label,
|
required Widget label,
|
||||||
}) = _TextButtonWithIcon;
|
}) = _TextButtonWithIcon;
|
||||||
|
@ -11,7 +11,7 @@ import '../rendering/mock_canvas.dart';
|
|||||||
import '../widgets/semantics_tester.dart';
|
import '../widgets/semantics_tester.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('ElevatedButton defaults', (WidgetTester tester) async {
|
testWidgets('ElevatedButton, ElevatedButton.icon defaults', (WidgetTester tester) async {
|
||||||
const ColorScheme colorScheme = ColorScheme.light();
|
const ColorScheme colorScheme = ColorScheme.light();
|
||||||
|
|
||||||
// Enabled ElevatedButton
|
// Enabled ElevatedButton
|
||||||
@ -27,13 +27,13 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Finder rawButtonMaterial = find.descendant(
|
final Finder buttonMaterial = find.descendant(
|
||||||
of: find.byType(ElevatedButton),
|
of: find.byType(ElevatedButton),
|
||||||
matching: find.byType(Material),
|
matching: find.byType(Material),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
Material material = tester.widget<Material>(rawButtonMaterial);
|
Material material = tester.widget<Material>(buttonMaterial);
|
||||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
expect(material.borderOnForeground, true);
|
expect(material.borderOnForeground, true);
|
||||||
expect(material.borderRadius, null);
|
expect(material.borderRadius, null);
|
||||||
@ -56,7 +56,7 @@ void main() {
|
|||||||
expect(inkFeatures, paints..circle(color: colorScheme.onPrimary.withAlpha(0x3d))); // splash color is onPrimary(0.24)
|
expect(inkFeatures, paints..circle(color: colorScheme.onPrimary.withAlpha(0x3d))); // splash color is onPrimary(0.24)
|
||||||
|
|
||||||
// Only elevation changes when enabled and pressed.
|
// Only elevation changes when enabled and pressed.
|
||||||
material = tester.widget<Material>(rawButtonMaterial);
|
material = tester.widget<Material>(buttonMaterial);
|
||||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
expect(material.borderOnForeground, true);
|
expect(material.borderOnForeground, true);
|
||||||
expect(material.borderRadius, null);
|
expect(material.borderRadius, null);
|
||||||
@ -74,6 +74,42 @@ void main() {
|
|||||||
await gesture.up();
|
await gesture.up();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// Enabled ElevatedButton.icon
|
||||||
|
final Key iconButtonKey = UniqueKey();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData.from(colorScheme: colorScheme),
|
||||||
|
home: Center(
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
key: iconButtonKey,
|
||||||
|
onPressed: () { },
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
label: const Text('label'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder iconButtonMaterial = find.descendant(
|
||||||
|
of: find.byKey(iconButtonKey),
|
||||||
|
matching: find.byType(Material),
|
||||||
|
);
|
||||||
|
|
||||||
|
material = tester.widget<Material>(iconButtonMaterial);
|
||||||
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
|
expect(material.borderOnForeground, true);
|
||||||
|
expect(material.borderRadius, null);
|
||||||
|
expect(material.clipBehavior, Clip.none);
|
||||||
|
expect(material.color, colorScheme.primary);
|
||||||
|
expect(material.elevation, 2);
|
||||||
|
expect(material.shadowColor, const Color(0xff000000));
|
||||||
|
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));
|
||||||
|
expect(material.textStyle!.color, colorScheme.onPrimary);
|
||||||
|
expect(material.textStyle!.fontFamily, 'Roboto');
|
||||||
|
expect(material.textStyle!.fontSize, 14);
|
||||||
|
expect(material.textStyle!.fontWeight, FontWeight.w500);
|
||||||
|
expect(material.type, MaterialType.button);
|
||||||
|
|
||||||
// Disabled ElevatedButton
|
// Disabled ElevatedButton
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
@ -90,7 +126,7 @@ void main() {
|
|||||||
// Finish the elevation animation, final background color change.
|
// Finish the elevation animation, final background color change.
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
material = tester.widget<Material>(rawButtonMaterial);
|
material = tester.widget<Material>(buttonMaterial);
|
||||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
expect(material.borderOnForeground, true);
|
expect(material.borderOnForeground, true);
|
||||||
expect(material.borderRadius, null);
|
expect(material.borderRadius, null);
|
||||||
|
@ -11,12 +11,7 @@ import '../rendering/mock_canvas.dart';
|
|||||||
import '../widgets/semantics_tester.dart';
|
import '../widgets/semantics_tester.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('OutlinedButton defaults', (WidgetTester tester) async {
|
testWidgets('OutlinedButton, OutlinedButton.icon defaults', (WidgetTester tester) async {
|
||||||
final Finder rawButtonMaterial = find.descendant(
|
|
||||||
of: find.byType(OutlinedButton),
|
|
||||||
matching: find.byType(Material),
|
|
||||||
);
|
|
||||||
|
|
||||||
const ColorScheme colorScheme = ColorScheme.light();
|
const ColorScheme colorScheme = ColorScheme.light();
|
||||||
|
|
||||||
// Enabled OutlinedButton
|
// Enabled OutlinedButton
|
||||||
@ -32,7 +27,12 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Material material = tester.widget<Material>(rawButtonMaterial);
|
final Finder buttonMaterial = find.descendant(
|
||||||
|
of: find.byType(OutlinedButton),
|
||||||
|
matching: find.byType(Material),
|
||||||
|
);
|
||||||
|
|
||||||
|
Material material = tester.widget<Material>(buttonMaterial);
|
||||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
expect(material.borderOnForeground, true);
|
expect(material.borderOnForeground, true);
|
||||||
expect(material.borderRadius, null);
|
expect(material.borderRadius, null);
|
||||||
@ -63,7 +63,49 @@ void main() {
|
|||||||
await gesture.up();
|
await gesture.up();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
// No change vs enabled and not pressed.
|
// No change vs enabled and not pressed.
|
||||||
material = tester.widget<Material>(rawButtonMaterial);
|
material = tester.widget<Material>(buttonMaterial);
|
||||||
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
|
expect(material.borderOnForeground, true);
|
||||||
|
expect(material.borderRadius, null);
|
||||||
|
expect(material.clipBehavior, Clip.none);
|
||||||
|
expect(material.color, Colors.transparent);
|
||||||
|
expect(material.elevation, 0.0);
|
||||||
|
expect(material.shadowColor, const Color(0xff000000));
|
||||||
|
expect(material.shape, RoundedRectangleBorder(
|
||||||
|
side: BorderSide(
|
||||||
|
width: 1,
|
||||||
|
color: colorScheme.onSurface.withOpacity(0.12),
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(4.0),
|
||||||
|
));
|
||||||
|
expect(material.textStyle!.color, colorScheme.primary);
|
||||||
|
expect(material.textStyle!.fontFamily, 'Roboto');
|
||||||
|
expect(material.textStyle!.fontSize, 14);
|
||||||
|
expect(material.textStyle!.fontWeight, FontWeight.w500);
|
||||||
|
expect(material.type, MaterialType.button);
|
||||||
|
|
||||||
|
// Enabled OutlinedButton.icon
|
||||||
|
final Key iconButtonKey = UniqueKey();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData.from(colorScheme: colorScheme),
|
||||||
|
home: Center(
|
||||||
|
child: OutlinedButton.icon(
|
||||||
|
key: iconButtonKey,
|
||||||
|
onPressed: () { },
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
label: const Text('label'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder iconButtonMaterial = find.descendant(
|
||||||
|
of: find.byKey(iconButtonKey),
|
||||||
|
matching: find.byType(Material),
|
||||||
|
);
|
||||||
|
|
||||||
|
material = tester.widget<Material>(iconButtonMaterial);
|
||||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
expect(material.borderOnForeground, true);
|
expect(material.borderOnForeground, true);
|
||||||
expect(material.borderRadius, null);
|
expect(material.borderRadius, null);
|
||||||
@ -97,7 +139,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
material = tester.widget<Material>(rawButtonMaterial);
|
material = tester.widget<Material>(buttonMaterial);
|
||||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
expect(material.borderOnForeground, true);
|
expect(material.borderOnForeground, true);
|
||||||
expect(material.borderRadius, null);
|
expect(material.borderRadius, null);
|
||||||
|
@ -11,7 +11,7 @@ import '../rendering/mock_canvas.dart';
|
|||||||
import '../widgets/semantics_tester.dart';
|
import '../widgets/semantics_tester.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('TextButton defaults', (WidgetTester tester) async {
|
testWidgets('TextButton, TextButton.icon defaults', (WidgetTester tester) async {
|
||||||
const ColorScheme colorScheme = ColorScheme.light();
|
const ColorScheme colorScheme = ColorScheme.light();
|
||||||
|
|
||||||
// Enabled TextButton
|
// Enabled TextButton
|
||||||
@ -72,6 +72,42 @@ void main() {
|
|||||||
expect(material.textStyle!.fontWeight, FontWeight.w500);
|
expect(material.textStyle!.fontWeight, FontWeight.w500);
|
||||||
expect(material.type, MaterialType.button);
|
expect(material.type, MaterialType.button);
|
||||||
|
|
||||||
|
// Enabled TextButton.icon
|
||||||
|
final Key iconButtonKey = UniqueKey();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData.from(colorScheme: colorScheme),
|
||||||
|
home: Center(
|
||||||
|
child: TextButton.icon(
|
||||||
|
key: iconButtonKey,
|
||||||
|
onPressed: () { },
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
label: const Text('label'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder iconButtonMaterial = find.descendant(
|
||||||
|
of: find.byKey(iconButtonKey),
|
||||||
|
matching: find.byType(Material),
|
||||||
|
);
|
||||||
|
|
||||||
|
material = tester.widget<Material>(iconButtonMaterial);
|
||||||
|
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||||
|
expect(material.borderOnForeground, true);
|
||||||
|
expect(material.borderRadius, null);
|
||||||
|
expect(material.clipBehavior, Clip.none);
|
||||||
|
expect(material.color, Colors.transparent);
|
||||||
|
expect(material.elevation, 0.0);
|
||||||
|
expect(material.shadowColor, const Color(0xff000000));
|
||||||
|
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)));
|
||||||
|
expect(material.textStyle!.color, colorScheme.primary);
|
||||||
|
expect(material.textStyle!.fontFamily, 'Roboto');
|
||||||
|
expect(material.textStyle!.fontSize, 14);
|
||||||
|
expect(material.textStyle!.fontWeight, FontWeight.w500);
|
||||||
|
expect(material.type, MaterialType.button);
|
||||||
|
|
||||||
// Disabled TextButton
|
// Disabled TextButton
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user