mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
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.
|
||||
factory ElevatedButton.icon({
|
||||
Key key,
|
||||
required VoidCallback onPressed,
|
||||
VoidCallback onLongPress,
|
||||
ButtonStyle style,
|
||||
FocusNode focusNode,
|
||||
bool autofocus,
|
||||
Clip clipBehavior,
|
||||
Key? key,
|
||||
required VoidCallback? onPressed,
|
||||
VoidCallback? onLongPress,
|
||||
ButtonStyle? style,
|
||||
FocusNode? focusNode,
|
||||
bool? autofocus,
|
||||
Clip? clipBehavior,
|
||||
required Widget icon,
|
||||
required Widget label,
|
||||
}) = _ElevatedButtonWithIcon;
|
||||
|
|
|
@ -79,13 +79,13 @@ class OutlinedButton extends ButtonStyleButton {
|
|||
///
|
||||
/// The [icon] and [label] arguments must not be null.
|
||||
factory OutlinedButton.icon({
|
||||
Key key,
|
||||
required VoidCallback onPressed,
|
||||
VoidCallback onLongPress,
|
||||
ButtonStyle style,
|
||||
FocusNode focusNode,
|
||||
bool autofocus,
|
||||
Clip clipBehavior,
|
||||
Key? key,
|
||||
required VoidCallback? onPressed,
|
||||
VoidCallback? onLongPress,
|
||||
ButtonStyle? style,
|
||||
FocusNode? focusNode,
|
||||
bool? autofocus,
|
||||
Clip? clipBehavior,
|
||||
required Widget icon,
|
||||
required Widget label,
|
||||
}) = _OutlinedButtonWithIcon;
|
||||
|
|
|
@ -86,13 +86,13 @@ class TextButton extends ButtonStyleButton {
|
|||
///
|
||||
/// The [icon] and [label] arguments must not be null.
|
||||
factory TextButton.icon({
|
||||
Key key,
|
||||
required VoidCallback onPressed,
|
||||
VoidCallback onLongPress,
|
||||
ButtonStyle style,
|
||||
FocusNode focusNode,
|
||||
bool autofocus,
|
||||
Clip clipBehavior,
|
||||
Key? key,
|
||||
required VoidCallback? onPressed,
|
||||
VoidCallback? onLongPress,
|
||||
ButtonStyle? style,
|
||||
FocusNode? focusNode,
|
||||
bool? autofocus,
|
||||
Clip? clipBehavior,
|
||||
required Widget icon,
|
||||
required Widget label,
|
||||
}) = _TextButtonWithIcon;
|
||||
|
|
|
@ -11,7 +11,7 @@ import '../rendering/mock_canvas.dart';
|
|||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('ElevatedButton defaults', (WidgetTester tester) async {
|
||||
testWidgets('ElevatedButton, ElevatedButton.icon defaults', (WidgetTester tester) async {
|
||||
const ColorScheme colorScheme = ColorScheme.light();
|
||||
|
||||
// Enabled ElevatedButton
|
||||
|
@ -27,13 +27,13 @@ void main() {
|
|||
),
|
||||
);
|
||||
|
||||
final Finder rawButtonMaterial = find.descendant(
|
||||
final Finder buttonMaterial = find.descendant(
|
||||
of: find.byType(ElevatedButton),
|
||||
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.borderOnForeground, true);
|
||||
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)
|
||||
|
||||
// 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.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
|
@ -74,6 +74,42 @@ void main() {
|
|||
await gesture.up();
|
||||
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
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
|
@ -90,7 +126,7 @@ void main() {
|
|||
// Finish the elevation animation, final background color change.
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
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);
|
||||
|
|
|
@ -11,12 +11,7 @@ import '../rendering/mock_canvas.dart';
|
|||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('OutlinedButton defaults', (WidgetTester tester) async {
|
||||
final Finder rawButtonMaterial = find.descendant(
|
||||
of: find.byType(OutlinedButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
|
||||
testWidgets('OutlinedButton, OutlinedButton.icon defaults', (WidgetTester tester) async {
|
||||
const ColorScheme colorScheme = ColorScheme.light();
|
||||
|
||||
// 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.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
|
@ -63,7 +63,49 @@ void main() {
|
|||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
// 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.borderOnForeground, true);
|
||||
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.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
|
|
|
@ -11,7 +11,7 @@ import '../rendering/mock_canvas.dart';
|
|||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('TextButton defaults', (WidgetTester tester) async {
|
||||
testWidgets('TextButton, TextButton.icon defaults', (WidgetTester tester) async {
|
||||
const ColorScheme colorScheme = ColorScheme.light();
|
||||
|
||||
// Enabled TextButton
|
||||
|
@ -72,6 +72,42 @@ void main() {
|
|||
expect(material.textStyle!.fontWeight, FontWeight.w500);
|
||||
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
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
|
|
Loading…
Reference in a new issue