Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
eac17471
Unverified
Commit
eac17471
authored
Jul 11, 2020
by
Hans Muller
Committed by
GitHub
Jul 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed ContainedButton et al. to ElevatedButton et al. (#61262)
parent
aa012538
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
448 additions
and
153 deletions
+448
-153
material.dart
packages/flutter/lib/material.dart
+2
-2
button_style.dart
packages/flutter/lib/src/material/button_style.dart
+6
-6
button_style_button.dart
packages/flutter/lib/src/material/button_style_button.dart
+2
-2
elevated_button.dart
packages/flutter/lib/src/material/elevated_button.dart
+173
-38
elevated_button_theme.dart
packages/flutter/lib/src/material/elevated_button_theme.dart
+160
-0
outlined_button.dart
packages/flutter/lib/src/material/outlined_button.dart
+1
-1
outlined_button_theme.dart
packages/flutter/lib/src/material/outlined_button_theme.dart
+2
-2
text_button.dart
packages/flutter/lib/src/material/text_button.dart
+1
-1
theme_data.dart
packages/flutter/lib/src/material/theme_data.dart
+14
-14
elevated_button_test.dart
packages/flutter/test/material/elevated_button_test.dart
+69
-69
elevated_button_theme_test.dart
...ges/flutter/test/material/elevated_button_theme_test.dart
+14
-14
theme_data_test.dart
packages/flutter/test/material/theme_data_test.dart
+4
-4
No files found.
packages/flutter/lib/material.dart
View file @
eac17471
...
...
@@ -49,8 +49,6 @@ export 'src/material/circle_avatar.dart';
export
'src/material/color_scheme.dart'
;
export
'src/material/colors.dart'
;
export
'src/material/constants.dart'
;
export
'src/material/contained_button.dart'
;
export
'src/material/contained_button_theme.dart'
;
export
'src/material/data_table.dart'
;
export
'src/material/data_table_source.dart'
;
export
'src/material/debug.dart'
;
...
...
@@ -61,6 +59,8 @@ export 'src/material/divider_theme.dart';
export
'src/material/drawer.dart'
;
export
'src/material/drawer_header.dart'
;
export
'src/material/dropdown.dart'
;
export
'src/material/elevated_button.dart'
;
export
'src/material/elevated_button_theme.dart'
;
export
'src/material/elevation_overlay.dart'
;
export
'src/material/expand_icon.dart'
;
export
'src/material/expansion_panel.dart'
;
...
...
packages/flutter/lib/src/material/button_style.dart
View file @
eac17471
...
...
@@ -29,12 +29,12 @@ import 'theme_data.dart';
/// hovered, focused, disabled, etc.
///
/// These properties can override the default value for just one state or all of
/// them. For example to create a [
Contain
edButton] whose background color is the
/// them. For example to create a [
Elevat
edButton] whose background color is the
/// color scheme’s primary color with 50% opacity, but only when the button is
/// pressed, one could write:
///
/// ```dart
///
Contain
edButton(
///
Elevat
edButton(
/// style: ButtonStyle(
/// backgroundColor: MaterialStateProperty.resolveWith<Color>(
/// (Set<MaterialState> states) {
...
...
@@ -48,11 +48,11 @@ import 'theme_data.dart';
///```
///
/// In this case the background color for all other button states would fallback
/// to the
Contain
edButton’s default values. To unconditionally set the button's
/// to the
Elevat
edButton’s default values. To unconditionally set the button's
/// [backgroundColor] for all states one could write:
///
/// ```dart
///
Contain
edButton(
///
Elevat
edButton(
/// style: ButtonStyle(
/// backgroundColor: MaterialStateProperty.all<Color>(Colors.green),
/// ),
...
...
@@ -66,7 +66,7 @@ import 'theme_data.dart';
/// useful to make relatively sweeping changes based on a few initial
/// parameters with simple values. The button styleFrom() methods
/// enable such sweeping changes. See for example:
/// [TextButton.styleFrom], [
Contain
edButton.styleFrom],
/// [TextButton.styleFrom], [
Elevat
edButton.styleFrom],
/// [OutlinedButton.styleFrom].
///
/// For example, to override the default text and icon colors for a
...
...
@@ -95,7 +95,7 @@ import 'theme_data.dart';
/// See also:
///
/// * [TextButtonTheme], the theme for [TextButton]s.
/// * [
ContainedButtonTheme], the theme for [Contain
edButton]s.
/// * [
ElevatedButtonTheme], the theme for [Elevat
edButton]s.
/// * [OutlinedButtonTheme], the theme for [OutlinedButton]s.
@immutable
class
ButtonStyle
with
Diagnosticable
{
...
...
packages/flutter/lib/src/material/button_style_button.dart
View file @
eac17471
...
...
@@ -27,7 +27,7 @@ import 'theme_data.dart';
/// See also:
///
/// * [TextButton], a simple ButtonStyleButton without a shadow.
/// * [
Contain
edButton], a filled ButtonStyleButton whose material elevates when pressed.
/// * [
Elevat
edButton], a filled ButtonStyleButton whose material elevates when pressed.
/// * [OutlinedButton], similar to [TextButton], but with an outline.
abstract
class
ButtonStyleButton
extends
StatefulWidget
{
/// Create a [ButtonStyleButton].
...
...
@@ -177,7 +177,7 @@ abstract class ButtonStyleButton extends StatefulWidget {
///
/// * [ButtonStyleButton], the [StatefulWidget] subclass for which this class is the [State].
/// * [TextButton], a simple button without a shadow.
/// * [
Contain
edButton], a filled button whose material elevates when pressed.
/// * [
Elevat
edButton], a filled button whose material elevates when pressed.
/// * [OutlinedButton], similar to [TextButton], but with an outline.
class
_ButtonStyleState
extends
State
<
ButtonStyleButton
>
{
final
Set
<
MaterialState
>
_states
=
<
MaterialState
>{};
...
...
packages/flutter/lib/src/material/
contain
ed_button.dart
→
packages/flutter/lib/src/material/
elevat
ed_button.dart
View file @
eac17471
...
...
@@ -16,34 +16,34 @@ import 'button_style_button.dart';
import
'color_scheme.dart'
;
import
'colors.dart'
;
import
'constants.dart'
;
import
'
contain
ed_button_theme.dart'
;
import
'
elevat
ed_button_theme.dart'
;
import
'material_state.dart'
;
import
'theme.dart'
;
import
'theme_data.dart'
;
/// A Material Design "
contain
ed button".
/// A Material Design "
elevat
ed button".
///
/// Use
contain
ed buttons to add dimension to otherwise mostly flat
/// Use
elevat
ed buttons to add dimension to otherwise mostly flat
/// layouts, e.g. in long busy lists of content, or in wide
/// spaces. Avoid using
contained buttons on already-contain
ed content
/// spaces. Avoid using
elevated buttons on already-elevat
ed content
/// such as dialogs or cards.
///
/// A
contain
ed button is a label [child] displayed on a [Material]
/// A
n elevat
ed button is a label [child] displayed on a [Material]
/// widget whose [Material.elevation] increases when the button is
/// pressed. The label's [Text] and [Icon] widgets are displayed in
/// [style]'s [ButtonStyle.onForegroundColor] and the button's filled
/// background is the [ButtonStyle.backgroundColor].
///
/// The
contain
ed button's default style is defined by
/// [defaultStyleOf]. The style of this
contain
ed button can be
/// The
elevat
ed button's default style is defined by
/// [defaultStyleOf]. The style of this
elevat
ed button can be
/// overridden with its [style] parameter. The style of all contained
/// buttons in a subtree can be overridden with the
/// [
Contain
edButtonTheme], and the style of all of the contained
/// [
Elevat
edButtonTheme], and the style of all of the contained
/// buttons in an app can be overridden with the [Theme]'s
/// [ThemeData.
contain
edButtonTheme] property.
/// [ThemeData.
Elevat
edButtonTheme] property.
///
/// The static [styleFrom] method is a convenient way to create a
///
contain
ed button [ButtonStyle] from simple values.
///
elevat
ed button [ButtonStyle] from simple values.
///
/// If [onPressed] and [onLongPress] callbacks are null, then the
/// button will be disabled.
...
...
@@ -53,11 +53,11 @@ import 'theme_data.dart';
/// * [TextButton], a simple flat button without a shadow.
/// * [OutlinedButton], a [TextButton] with a border outline.
/// * <https://material.io/design/components/buttons.html>
class
Contain
edButton
extends
ButtonStyleButton
{
/// Create a
Contain
edButton.
class
Elevat
edButton
extends
ButtonStyleButton
{
/// Create a
n Elevat
edButton.
///
/// The [autofocus] and [clipBehavior] arguments must not be null.
const
Contain
edButton
({
const
Elevat
edButton
({
Key
key
,
@required
VoidCallback
onPressed
,
VoidCallback
onLongPress
,
...
...
@@ -77,14 +77,14 @@ class ContainedButton extends ButtonStyleButton {
child:
child
,
);
/// Create a
contain
ed button from a pair of widgets that serve as the button's
/// Create a
n elevat
ed button from a pair of widgets that serve as the button's
/// [icon] and [label].
///
/// The icon and label are arranged in a row and padded by 12 logical pixels
/// at the start, and 16 at the end, with an 8 pixel gap in between.
///
/// The [icon] and [label] arguments must not be null.
factory
Contain
edButton
.
icon
({
factory
Elevat
edButton
.
icon
({
Key
key
,
@required
VoidCallback
onPressed
,
VoidCallback
onLongPress
,
...
...
@@ -94,9 +94,9 @@ class ContainedButton extends ButtonStyleButton {
Clip
clipBehavior
,
@required
Widget
icon
,
@required
Widget
label
,
})
=
_
Contain
edButtonWithIcon
;
})
=
_
Elevat
edButtonWithIcon
;
/// A static convenience method that constructs a
contain
ed button
/// A static convenience method that constructs a
n elevat
ed button
/// [ButtonStyle] given simple values.
///
/// The [onPrimary], and [onSurface] colors are used to to create a
...
...
@@ -124,12 +124,12 @@ class ContainedButton extends ButtonStyleButton {
/// a [ButtonStyle] that doesn't override anything.
///
/// For example, to override the default text and icon colors for a
/// [
Contain
edButton], as well as its overlay color, with all of the
/// [
Elevat
edButton], as well as its overlay color, with all of the
/// standard opacity adjustments for the pressed, focused, and
/// hovered states, one could write:
///
/// ```dart
///
Contain
edButton(
///
Elevat
edButton(
/// style: TextButton.styleFrom(primary: Colors.green),
/// )
/// ```
...
...
@@ -153,19 +153,19 @@ class ContainedButton extends ButtonStyleButton {
})
{
final
MaterialStateProperty
<
Color
>
backgroundColor
=
(
onSurface
==
null
&&
primary
==
null
)
?
null
:
_
Contain
edButtonDefaultBackground
(
primary
,
onSurface
);
:
_
Elevat
edButtonDefaultBackground
(
primary
,
onSurface
);
final
MaterialStateProperty
<
Color
>
foregroundColor
=
(
onSurface
==
null
&&
onPrimary
==
null
)
?
null
:
_
Contain
edButtonDefaultForeground
(
onPrimary
,
onSurface
);
:
_
Elevat
edButtonDefaultForeground
(
onPrimary
,
onSurface
);
final
MaterialStateProperty
<
Color
>
overlayColor
=
(
onPrimary
==
null
)
?
null
:
_
Contain
edButtonDefaultOverlay
(
onPrimary
);
:
_
Elevat
edButtonDefaultOverlay
(
onPrimary
);
final
MaterialStateProperty
<
double
>
elevationValue
=
(
elevation
==
null
)
?
null
:
_
Contain
edButtonDefaultElevation
(
elevation
);
:
_
Elevat
edButtonDefaultElevation
(
elevation
);
final
MaterialStateProperty
<
MouseCursor
>
mouseCursor
=
(
enabledMouseCursor
==
null
&&
disabledMouseCursor
==
null
)
?
null
:
_
Contain
edButtonDefaultMouseCursor
(
enabledMouseCursor
,
disabledMouseCursor
);
:
_
Elevat
edButtonDefaultMouseCursor
(
enabledMouseCursor
,
disabledMouseCursor
);
return
ButtonStyle
(
textStyle:
MaterialStateProperty
.
all
<
TextStyle
>(
textStyle
),
...
...
@@ -241,7 +241,7 @@ class ContainedButton extends ButtonStyleButton {
/// * `animationDuration` - kThemeChangeDuration
/// * `enableFeedback` - true
///
/// The default padding values for the [
Contain
edButton.icon] factory are slightly different:
/// The default padding values for the [
Elevat
edButton.icon] factory are slightly different:
///
/// * `padding`
/// * `textScaleFactor <= 1` - start(12) end(16)
...
...
@@ -280,17 +280,17 @@ class ContainedButton extends ButtonStyleButton {
);
}
/// Returns the [
Contain
edButtonThemeData.style] of the closest
/// [
Contain
edButtonTheme] ancestor.
/// Returns the [
Elevat
edButtonThemeData.style] of the closest
/// [
Elevat
edButtonTheme] ancestor.
@override
ButtonStyle
themeStyleOf
(
BuildContext
context
)
{
return
Contain
edButtonTheme
.
of
(
context
)?.
style
;
return
Elevat
edButtonTheme
.
of
(
context
)?.
style
;
}
}
@immutable
class
_
Contain
edButtonDefaultBackground
extends
MaterialStateProperty
<
Color
>
with
Diagnosticable
{
_
Contain
edButtonDefaultBackground
(
this
.
primary
,
this
.
onSurface
);
class
_
Elevat
edButtonDefaultBackground
extends
MaterialStateProperty
<
Color
>
with
Diagnosticable
{
_
Elevat
edButtonDefaultBackground
(
this
.
primary
,
this
.
onSurface
);
final
Color
primary
;
final
Color
onSurface
;
...
...
@@ -304,8 +304,8 @@ class _ContainedButtonDefaultBackground extends MaterialStateProperty<Color> wit
}
@immutable
class
_
Contain
edButtonDefaultForeground
extends
MaterialStateProperty
<
Color
>
with
Diagnosticable
{
_
Contain
edButtonDefaultForeground
(
this
.
onPrimary
,
this
.
onSurface
);
class
_
Elevat
edButtonDefaultForeground
extends
MaterialStateProperty
<
Color
>
with
Diagnosticable
{
_
Elevat
edButtonDefaultForeground
(
this
.
onPrimary
,
this
.
onSurface
);
final
Color
onPrimary
;
final
Color
onSurface
;
...
...
@@ -319,8 +319,8 @@ class _ContainedButtonDefaultForeground extends MaterialStateProperty<Color> wit
}
@immutable
class
_
Contain
edButtonDefaultOverlay
extends
MaterialStateProperty
<
Color
>
with
Diagnosticable
{
_
Contain
edButtonDefaultOverlay
(
this
.
onPrimary
);
class
_
Elevat
edButtonDefaultOverlay
extends
MaterialStateProperty
<
Color
>
with
Diagnosticable
{
_
Elevat
edButtonDefaultOverlay
(
this
.
onPrimary
);
final
Color
onPrimary
;
...
...
@@ -335,8 +335,8 @@ class _ContainedButtonDefaultOverlay extends MaterialStateProperty<Color> with D
}
@immutable
class
_
Contain
edButtonDefaultElevation
extends
MaterialStateProperty
<
double
>
with
Diagnosticable
{
_
Contain
edButtonDefaultElevation
(
this
.
elevation
);
class
_
Elevat
edButtonDefaultElevation
extends
MaterialStateProperty
<
double
>
with
Diagnosticable
{
_
Elevat
edButtonDefaultElevation
(
this
.
elevation
);
final
double
elevation
;
...
...
@@ -355,8 +355,8 @@ class _ContainedButtonDefaultElevation extends MaterialStateProperty<double> wit
}
@immutable
class
_
Contain
edButtonDefaultMouseCursor
extends
MaterialStateProperty
<
MouseCursor
>
with
Diagnosticable
{
_
Contain
edButtonDefaultMouseCursor
(
this
.
enabledCursor
,
this
.
disabledCursor
);
class
_
Elevat
edButtonDefaultMouseCursor
extends
MaterialStateProperty
<
MouseCursor
>
with
Diagnosticable
{
_
Elevat
edButtonDefaultMouseCursor
(
this
.
enabledCursor
,
this
.
disabledCursor
);
final
MouseCursor
enabledCursor
;
final
MouseCursor
disabledCursor
;
...
...
@@ -369,6 +369,141 @@ class _ContainedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCurs
}
}
class
_ElevatedButtonWithIcon
extends
ElevatedButton
{
_ElevatedButtonWithIcon
({
Key
key
,
@required
VoidCallback
onPressed
,
VoidCallback
onLongPress
,
ButtonStyle
style
,
FocusNode
focusNode
,
bool
autofocus
,
Clip
clipBehavior
,
@required
Widget
icon
,
@required
Widget
label
,
})
:
assert
(
icon
!=
null
),
assert
(
label
!=
null
),
super
(
key:
key
,
onPressed:
onPressed
,
onLongPress:
onLongPress
,
style:
style
,
focusNode:
focusNode
,
autofocus:
autofocus
??
false
,
clipBehavior:
clipBehavior
??
Clip
.
none
,
child:
_ElevatedButtonWithIconChild
(
icon:
icon
,
label:
label
),
);
@override
ButtonStyle
defaultStyleOf
(
BuildContext
context
)
{
final
EdgeInsetsGeometry
scaledPadding
=
ButtonStyleButton
.
scaledPadding
(
const
EdgeInsetsDirectional
.
fromSTEB
(
12
,
0
,
16
,
0
),
const
EdgeInsets
.
symmetric
(
horizontal:
8
),
const
EdgeInsetsDirectional
.
fromSTEB
(
8
,
0
,
4
,
0
),
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1
,
);
return
super
.
defaultStyleOf
(
context
).
copyWith
(
padding:
MaterialStateProperty
.
all
<
EdgeInsetsGeometry
>(
scaledPadding
)
);
}
}
class
_ElevatedButtonWithIconChild
extends
StatelessWidget
{
const
_ElevatedButtonWithIconChild
({
Key
key
,
this
.
label
,
this
.
icon
})
:
super
(
key:
key
);
final
Widget
label
;
final
Widget
icon
;
@override
Widget
build
(
BuildContext
context
)
{
final
double
scale
=
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1
;
final
double
gap
=
scale
<=
1
?
8
:
lerpDouble
(
8
,
4
,
math
.
min
(
scale
-
1
,
1
));
return
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
icon
,
SizedBox
(
width:
gap
),
label
],
);
}
}
/// Please use [ElevatedButton].
@Deprecated
(
'This class was briefly released with the wrong name. The correct name is ElevatedButton. '
'This feature was deprecated after v1.20.0-2.0.pre.'
)
class
ContainedButton
extends
ElevatedButton
{
/// Please use [new ElevatedButton].
const
ContainedButton
({
Key
key
,
@required
VoidCallback
onPressed
,
VoidCallback
onLongPress
,
ButtonStyle
style
,
FocusNode
focusNode
,
bool
autofocus
=
false
,
Clip
clipBehavior
=
Clip
.
none
,
@required
Widget
child
,
})
:
super
(
key:
key
,
onPressed:
onPressed
,
onLongPress:
onLongPress
,
style:
style
,
focusNode:
focusNode
,
autofocus:
autofocus
,
clipBehavior:
clipBehavior
,
child:
child
,
);
/// Please use [new ElevatedButton.icon].
factory
ContainedButton
.
icon
({
Key
key
,
@required
VoidCallback
onPressed
,
VoidCallback
onLongPress
,
ButtonStyle
style
,
FocusNode
focusNode
,
bool
autofocus
,
Clip
clipBehavior
,
@required
Widget
icon
,
@required
Widget
label
,
})
=
_ContainedButtonWithIcon
;
/// Please use [ElevatedButton.styleFrom].
static
ButtonStyle
styleFrom
({
Color
primary
,
Color
onPrimary
,
Color
onSurface
,
Color
shadowColor
,
double
elevation
,
TextStyle
textStyle
,
EdgeInsetsGeometry
padding
,
Size
minimumSize
,
BorderSide
side
,
OutlinedBorder
shape
,
MouseCursor
enabledMouseCursor
,
MouseCursor
disabledMouseCursor
,
VisualDensity
visualDensity
,
MaterialTapTargetSize
tapTargetSize
,
Duration
animationDuration
,
bool
enableFeedback
,
})
{
return
ElevatedButton
.
styleFrom
(
primary:
primary
,
onPrimary:
onPrimary
,
onSurface:
onSurface
,
shadowColor:
shadowColor
,
elevation:
elevation
,
textStyle:
textStyle
,
padding:
padding
,
minimumSize:
minimumSize
,
side:
side
,
shape:
shape
,
enabledMouseCursor:
enabledMouseCursor
,
disabledMouseCursor:
disabledMouseCursor
,
visualDensity:
visualDensity
,
tapTargetSize:
tapTargetSize
,
animationDuration:
animationDuration
,
enableFeedback:
enableFeedback
,
);
}
}
class
_ContainedButtonWithIcon
extends
ContainedButton
{
_ContainedButtonWithIcon
({
Key
key
,
...
...
packages/flutter/lib/src/material/
contain
ed_button_theme.dart
→
packages/flutter/lib/src/material/
elevat
ed_button_theme.dart
View file @
eac17471
...
...
@@ -11,47 +11,47 @@ import 'button_style.dart';
import
'theme.dart'
;
/// A [ButtonStyle] that overrides the default appearance of
/// [
ContainedButton]s when it's used with [Contain
edButtonTheme] or with the
/// overall [Theme]'s [ThemeData.
contain
edButtonTheme].
/// [
ElevatedButton]s when it's used with [Elevat
edButtonTheme] or with the
/// overall [Theme]'s [ThemeData.
Elevat
edButtonTheme].
///
/// The [style]'s properties override [
Contain
edButton]'s default style,
/// i.e. the [ButtonStyle] returned by [
Contain
edButton.defaultStyleOf]. Only
/// The [style]'s properties override [
Elevat
edButton]'s default style,
/// i.e. the [ButtonStyle] returned by [
Elevat
edButton.defaultStyleOf]. Only
/// the style's non-null property values or resolved non-null
/// [MaterialStateProperty] values are used.
///
/// See also:
///
/// * [
Contain
edButtonTheme], the theme which is configured with this class.
/// * [
Contain
edButton.defaultStyleOf], which returns the default [ButtonStyle]
/// * [
Elevat
edButtonTheme], the theme which is configured with this class.
/// * [
Elevat
edButton.defaultStyleOf], which returns the default [ButtonStyle]
/// for text buttons.
/// * [
Contain
edButton.styleOf], which converts simple values into a
/// [ButtonStyle] that's consistent with [
Contain
edButton]'s defaults.
/// * [
Elevat
edButton.styleOf], which converts simple values into a
/// [ButtonStyle] that's consistent with [
Elevat
edButton]'s defaults.
/// * [MaterialStateProperty.resolve], "resolve" a material state property
/// to a simple value based on a set of [MaterialState]s.
/// * [ThemeData.
contain
edButtonTheme], which can be used to override the default
/// [ButtonStyle] for [
Contain
edButton]s below the overall [Theme].
/// * [ThemeData.
Elevat
edButtonTheme], which can be used to override the default
/// [ButtonStyle] for [
Elevat
edButton]s below the overall [Theme].
@immutable
class
Contain
edButtonThemeData
with
Diagnosticable
{
/// Creates a
[Contain
edButtonThemeData].
class
Elevat
edButtonThemeData
with
Diagnosticable
{
/// Creates a
n [Elevat
edButtonThemeData].
///
/// The [style] may be null.
const
Contain
edButtonThemeData
({
this
.
style
});
const
Elevat
edButtonThemeData
({
this
.
style
});
/// Overrides for [
Contain
edButton]'s default style.
/// Overrides for [
Elevat
edButton]'s default style.
///
/// Non-null properties or non-null resolved [MaterialStateProperty]
/// values override the [ButtonStyle] returned by
/// [
Contain
edButton.defaultStyleOf].
/// [
Elevat
edButton.defaultStyleOf].
///
/// If [style] is null, then this theme doesn't override anything.
final
ButtonStyle
style
;
/// Linearly interpolate between two
contain
ed button themes.
static
ContainedButtonThemeData
lerp
(
ContainedButtonThemeData
a
,
Contain
edButtonThemeData
b
,
double
t
)
{
/// Linearly interpolate between two
elevat
ed button themes.
static
ElevatedButtonThemeData
lerp
(
ElevatedButtonThemeData
a
,
Elevat
edButtonThemeData
b
,
double
t
)
{
assert
(
t
!=
null
);
if
(
a
==
null
&&
b
==
null
)
return
null
;
return
Contain
edButtonThemeData
(
return
Elevat
edButtonThemeData
(
style:
ButtonStyle
.
lerp
(
a
?.
style
,
b
?.
style
,
t
),
);
}
...
...
@@ -67,7 +67,7 @@ class ContainedButtonThemeData with Diagnosticable {
return
true
;
if
(
other
.
runtimeType
!=
runtimeType
)
return
false
;
return
other
is
Contain
edButtonThemeData
&&
other
.
style
==
style
;
return
other
is
Elevat
edButtonThemeData
&&
other
.
style
==
style
;
}
@override
...
...
@@ -77,51 +77,84 @@ class ContainedButtonThemeData with Diagnosticable {
}
}
/// Overrides the default [ButtonStyle] of its [
Contain
edButton] descendants.
/// Overrides the default [ButtonStyle] of its [
Elevat
edButton] descendants.
///
/// See also:
///
/// * [
Contain
edButtonThemeData], which is used to configure this theme.
/// * [
Contain
edButton.defaultStyleOf], which returns the default [ButtonStyle]
/// for
text
buttons.
/// * [
Contain
edButton.styleOf], which converts simple values into a
/// [ButtonStyle] that's consistent with [
Contain
edButton]'s defaults.
/// * [ThemeData.
contain
edButtonTheme], which can be used to override the default
/// [ButtonStyle] for [
Contain
edButton]s below the overall [Theme].
class
Contain
edButtonTheme
extends
InheritedTheme
{
/// Create a [
Contain
edButtonTheme].
/// * [
Elevat
edButtonThemeData], which is used to configure this theme.
/// * [
Elevat
edButton.defaultStyleOf], which returns the default [ButtonStyle]
/// for
elevated
buttons.
/// * [
Elevat
edButton.styleOf], which converts simple values into a
/// [ButtonStyle] that's consistent with [
Elevat
edButton]'s defaults.
/// * [ThemeData.
Elevat
edButtonTheme], which can be used to override the default
/// [ButtonStyle] for [
Elevat
edButton]s below the overall [Theme].
class
Elevat
edButtonTheme
extends
InheritedTheme
{
/// Create a [
Elevat
edButtonTheme].
///
/// The [data] parameter must not be null.
const
Contain
edButtonTheme
({
const
Elevat
edButtonTheme
({
Key
key
,
@required
this
.
data
,
Widget
child
,
})
:
assert
(
data
!=
null
),
super
(
key:
key
,
child:
child
);
/// The configuration of this theme.
final
Contain
edButtonThemeData
data
;
final
Elevat
edButtonThemeData
data
;
/// The closest instance of this class that encloses the given context.
///
/// If there is no enclosing [
Contain
edButtonsTheme] widget, then
/// [ThemeData.
contain
edButtonTheme] is used.
/// If there is no enclosing [
Elevat
edButtonsTheme] widget, then
/// [ThemeData.
Elevat
edButtonTheme] is used.
///
/// Typical usage is as follows:
///
/// ```dart
///
ContainedButtonTheme theme = Contain
edButtonTheme.of(context);
///
ElevatedButtonTheme theme = Elevat
edButtonTheme.of(context);
/// ```
static
Contain
edButtonThemeData
of
(
BuildContext
context
)
{
final
ContainedButtonTheme
buttonTheme
=
context
.
dependOnInheritedWidgetOfExactType
<
Contain
edButtonTheme
>();
return
buttonTheme
?.
data
??
Theme
.
of
(
context
).
contain
edButtonTheme
;
static
Elevat
edButtonThemeData
of
(
BuildContext
context
)
{
final
ElevatedButtonTheme
buttonTheme
=
context
.
dependOnInheritedWidgetOfExactType
<
Elevat
edButtonTheme
>();
return
buttonTheme
?.
data
??
Theme
.
of
(
context
).
elevat
edButtonTheme
;
}
@override
Widget
wrap
(
BuildContext
context
,
Widget
child
)
{
final
ContainedButtonTheme
ancestorTheme
=
context
.
findAncestorWidgetOfExactType
<
Contain
edButtonTheme
>();
return
identical
(
this
,
ancestorTheme
)
?
child
:
Contain
edButtonTheme
(
data:
data
,
child:
child
);
final
ElevatedButtonTheme
ancestorTheme
=
context
.
findAncestorWidgetOfExactType
<
Elevat
edButtonTheme
>();
return
identical
(
this
,
ancestorTheme
)
?
child
:
Elevat
edButtonTheme
(
data:
data
,
child:
child
);
}
@override
bool
updateShouldNotify
(
ContainedButtonTheme
oldWidget
)
=>
data
!=
oldWidget
.
data
;
bool
updateShouldNotify
(
ElevatedButtonTheme
oldWidget
)
=>
data
!=
oldWidget
.
data
;
}
/// Please use [ElevatedButtonTheme].
@Deprecated
(
'This class was briefly released with the wrong name. '
'The correct name is ElevatedButtonThemeData. '
'This feature was deprecated after v1.20.0-2.0.pre.'
)
@immutable
class
ContainedButtonThemeData
extends
ElevatedButtonThemeData
{
/// Please use [new ElevatedButtonTheme].
const
ContainedButtonThemeData
({
ButtonStyle
style
})
:
super
(
style:
style
);
/// Please use [ElevatedButtonTheme.lerp()].
static
ContainedButtonThemeData
lerp
(
ContainedButtonThemeData
a
,
ContainedButtonThemeData
b
,
double
t
)
{
return
ElevatedButtonThemeData
.
lerp
(
a
,
b
,
t
)
as
ContainedButtonThemeData
;
}
}
/// Please use [ElevatedButtonThemeData].
@Deprecated
(
'This class was briefly released with the wrong name. '
'The correct name is ElevatedButtonTheme. '
'This feature was deprecated after v1.20.0-2.0.pre.'
)
class
ContainedButtonTheme
extends
ElevatedButtonTheme
{
/// Please use [new ElevatedButtonThemeData].
const
ContainedButtonTheme
({
Key
key
,
@required
ContainedButtonThemeData
data
,
Widget
child
,
})
:
assert
(
data
!=
null
),
super
(
key:
key
,
data:
data
,
child:
child
);
}
packages/flutter/lib/src/material/outlined_button.dart
View file @
eac17471
...
...
@@ -46,7 +46,7 @@ import 'theme_data.dart';
///
/// See also:
///
/// * [
Contain
edButton], a filled material design button with a shadow.
/// * [
Elevat
edButton], a filled material design button with a shadow.
/// * [TextButton], a material design button without a shadow.
/// * <https://material.io/design/components/buttons.html>
class
OutlinedButton
extends
ButtonStyleButton
{
...
...
packages/flutter/lib/src/material/outlined_button_theme.dart
View file @
eac17471
...
...
@@ -23,7 +23,7 @@ import 'theme.dart';
///
/// * [OutlinedButtonTheme], the theme which is configured with this class.
/// * [OutlinedButton.defaultStyleOf], which returns the default [ButtonStyle]
/// for
text
buttons.
/// for
outlined
buttons.
/// * [OutlinedButton.styleOf], which converts simple values into a
/// [ButtonStyle] that's consistent with [OutlinedButton]'s defaults.
/// * [MaterialStateProperty.resolve], "resolve" a material state property
...
...
@@ -83,7 +83,7 @@ class OutlinedButtonThemeData with Diagnosticable {
///
/// * [OutlinedButtonThemeData], which is used to configure this theme.
/// * [OutlinedButton.defaultStyleOf], which returns the default [ButtonStyle]
/// for
text
buttons.
/// for
outlined
buttons.
/// * [OutlinedButton.styleOf], which converts simple values into a
/// [ButtonStyle] that's consistent with [OutlinedButton]'s defaults.
/// * [ThemeData.outlinedButtonTheme], which can be used to override the default
...
...
packages/flutter/lib/src/material/text_button.dart
View file @
eac17471
...
...
@@ -54,7 +54,7 @@ import 'theme_data.dart';
/// See also:
///
/// * [OutlinedButton], a [TextButton] with a border outline.
/// * [
Contain
edButton], a filled button whose material elevates when pressed.
/// * [
Elevat
edButton], a filled button whose material elevates when pressed.
/// * <https://material.io/design/components/buttons.html>
class
TextButton
extends
ButtonStyleButton
{
/// Create a TextButton.
...
...
packages/flutter/lib/src/material/theme_data.dart
View file @
eac17471
...
...
@@ -22,9 +22,9 @@ import 'card_theme.dart';
import
'chip_theme.dart'
;
import
'color_scheme.dart'
;
import
'colors.dart'
;
import
'contained_button_theme.dart'
;
import
'dialog_theme.dart'
;
import
'divider_theme.dart'
;
import
'elevated_button_theme.dart'
;
import
'floating_action_button_theme.dart'
;
import
'ink_splash.dart'
;
import
'ink_well.dart'
show
InteractiveInkFeatureFactory
;
...
...
@@ -276,7 +276,7 @@ class ThemeData with Diagnosticable {
BottomNavigationBarThemeData
bottomNavigationBarTheme
,
TimePickerThemeData
timePickerTheme
,
TextButtonThemeData
textButtonTheme
,
ContainedButtonThemeData
contain
edButtonTheme
,
ElevatedButtonThemeData
elevat
edButtonTheme
,
OutlinedButtonThemeData
outlinedButtonTheme
,
bool
fixTextFieldOutlineLabel
,
})
{
...
...
@@ -392,7 +392,7 @@ class ThemeData with Diagnosticable {
bottomNavigationBarTheme
??=
const
BottomNavigationBarThemeData
();
timePickerTheme
??=
const
TimePickerThemeData
();
textButtonTheme
??=
const
TextButtonThemeData
();
containedButtonTheme
??=
const
Contain
edButtonThemeData
();
elevatedButtonTheme
??=
const
Elevat
edButtonThemeData
();
outlinedButtonTheme
??=
const
OutlinedButtonThemeData
();
fixTextFieldOutlineLabel
??=
false
;
...
...
@@ -464,7 +464,7 @@ class ThemeData with Diagnosticable {
bottomNavigationBarTheme:
bottomNavigationBarTheme
,
timePickerTheme:
timePickerTheme
,
textButtonTheme:
textButtonTheme
,
containedButtonTheme:
contain
edButtonTheme
,
elevatedButtonTheme:
elevat
edButtonTheme
,
outlinedButtonTheme:
outlinedButtonTheme
,
fixTextFieldOutlineLabel:
fixTextFieldOutlineLabel
,
);
...
...
@@ -548,7 +548,7 @@ class ThemeData with Diagnosticable {
@required
this
.
bottomNavigationBarTheme
,
@required
this
.
timePickerTheme
,
@required
this
.
textButtonTheme
,
@required
this
.
contain
edButtonTheme
,
@required
this
.
elevat
edButtonTheme
,
@required
this
.
outlinedButtonTheme
,
@required
this
.
fixTextFieldOutlineLabel
,
})
:
assert
(
visualDensity
!=
null
),
...
...
@@ -615,7 +615,7 @@ class ThemeData with Diagnosticable {
assert
(
bottomNavigationBarTheme
!=
null
),
assert
(
timePickerTheme
!=
null
),
assert
(
textButtonTheme
!=
null
),
assert
(
contain
edButtonTheme
!=
null
),
assert
(
elevat
edButtonTheme
!=
null
),
assert
(
outlinedButtonTheme
!=
null
),
assert
(
fixTextFieldOutlineLabel
!=
null
);
...
...
@@ -1086,8 +1086,8 @@ class ThemeData with Diagnosticable {
final
TextButtonThemeData
textButtonTheme
;
/// A theme for customizing the appearance and internal layout of
/// [
Contain
edButton]s
final
ContainedButtonThemeData
contain
edButtonTheme
;
/// [
Elevat
edButton]s
final
ElevatedButtonThemeData
elevat
edButtonTheme
;
/// A theme for customizing the appearance and internal layout of
/// [OutlinedButton]s.
...
...
@@ -1177,7 +1177,7 @@ class ThemeData with Diagnosticable {
BottomNavigationBarThemeData
bottomNavigationBarTheme
,
TimePickerThemeData
timePickerTheme
,
TextButtonThemeData
textButtonTheme
,
ContainedButtonThemeData
contain
edButtonTheme
,
ElevatedButtonThemeData
elevat
edButtonTheme
,
OutlinedButtonThemeData
outlinedButtonTheme
,
bool
fixTextFieldOutlineLabel
,
})
{
...
...
@@ -1250,7 +1250,7 @@ class ThemeData with Diagnosticable {
bottomNavigationBarTheme:
bottomNavigationBarTheme
??
this
.
bottomNavigationBarTheme
,
timePickerTheme:
timePickerTheme
??
this
.
timePickerTheme
,
textButtonTheme:
textButtonTheme
??
this
.
textButtonTheme
,
containedButtonTheme:
containedButtonTheme
??
this
.
contain
edButtonTheme
,
elevatedButtonTheme:
elevatedButtonTheme
??
this
.
elevat
edButtonTheme
,
outlinedButtonTheme:
outlinedButtonTheme
??
this
.
outlinedButtonTheme
,
fixTextFieldOutlineLabel:
fixTextFieldOutlineLabel
??
this
.
fixTextFieldOutlineLabel
,
);
...
...
@@ -1401,7 +1401,7 @@ class ThemeData with Diagnosticable {
bottomNavigationBarTheme:
BottomNavigationBarThemeData
.
lerp
(
a
.
bottomNavigationBarTheme
,
b
.
bottomNavigationBarTheme
,
t
),
timePickerTheme:
TimePickerThemeData
.
lerp
(
a
.
timePickerTheme
,
b
.
timePickerTheme
,
t
),
textButtonTheme:
TextButtonThemeData
.
lerp
(
a
.
textButtonTheme
,
b
.
textButtonTheme
,
t
),
containedButtonTheme:
ContainedButtonThemeData
.
lerp
(
a
.
containedButtonTheme
,
b
.
contain
edButtonTheme
,
t
),
elevatedButtonTheme:
ElevatedButtonThemeData
.
lerp
(
a
.
elevatedButtonTheme
,
b
.
elevat
edButtonTheme
,
t
),
outlinedButtonTheme:
OutlinedButtonThemeData
.
lerp
(
a
.
outlinedButtonTheme
,
b
.
outlinedButtonTheme
,
t
),
fixTextFieldOutlineLabel:
t
<
0.5
?
a
.
fixTextFieldOutlineLabel
:
b
.
fixTextFieldOutlineLabel
,
);
...
...
@@ -1480,7 +1480,7 @@ class ThemeData with Diagnosticable {
&&
other
.
bottomNavigationBarTheme
==
bottomNavigationBarTheme
&&
other
.
timePickerTheme
==
timePickerTheme
&&
other
.
textButtonTheme
==
textButtonTheme
&&
other
.
containedButtonTheme
==
contain
edButtonTheme
&&
other
.
elevatedButtonTheme
==
elevat
edButtonTheme
&&
other
.
outlinedButtonTheme
==
outlinedButtonTheme
&&
other
.
fixTextFieldOutlineLabel
==
fixTextFieldOutlineLabel
;
}
...
...
@@ -1558,7 +1558,7 @@ class ThemeData with Diagnosticable {
bottomNavigationBarTheme
,
timePickerTheme
,
textButtonTheme
,
contain
edButtonTheme
,
elevat
edButtonTheme
,
outlinedButtonTheme
,
fixTextFieldOutlineLabel
,
];
...
...
@@ -1633,7 +1633,7 @@ class ThemeData with Diagnosticable {
properties
.
add
(
DiagnosticsProperty
<
TimePickerThemeData
>(
'timePickerTheme'
,
timePickerTheme
,
defaultValue:
defaultData
.
timePickerTheme
,
level:
DiagnosticLevel
.
debug
));
properties
.
add
(
DiagnosticsProperty
<
BottomNavigationBarThemeData
>(
'bottomNavigationBarTheme'
,
bottomNavigationBarTheme
,
defaultValue:
defaultData
.
bottomNavigationBarTheme
,
level:
DiagnosticLevel
.
debug
));
properties
.
add
(
DiagnosticsProperty
<
TextButtonThemeData
>(
'textButtonTheme'
,
textButtonTheme
,
defaultValue:
defaultData
.
textButtonTheme
,
level:
DiagnosticLevel
.
debug
));
properties
.
add
(
DiagnosticsProperty
<
ContainedButtonThemeData
>(
'containedButtonTheme'
,
containedButtonTheme
,
defaultValue:
defaultData
.
contain
edButtonTheme
,
level:
DiagnosticLevel
.
debug
));
properties
.
add
(
DiagnosticsProperty
<
ElevatedButtonThemeData
>(
'elevatedButtonTheme'
,
elevatedButtonTheme
,
defaultValue:
defaultData
.
elevat
edButtonTheme
,
level:
DiagnosticLevel
.
debug
));
properties
.
add
(
DiagnosticsProperty
<
OutlinedButtonThemeData
>(
'outlinedButtonTheme'
,
outlinedButtonTheme
,
defaultValue:
defaultData
.
outlinedButtonTheme
,
level:
DiagnosticLevel
.
debug
));
}
}
...
...
packages/flutter/test/material/
contain
ed_button_test.dart
→
packages/flutter/test/material/
elevat
ed_button_test.dart
View file @
eac17471
...
...
@@ -13,20 +13,20 @@ import '../rendering/mock_canvas.dart';
import
'../widgets/semantics_tester.dart'
;
void
main
(
)
{
testWidgets
(
'
Contain
edButton defaults'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton defaults'
,
(
WidgetTester
tester
)
async
{
final
Finder
rawButtonMaterial
=
find
.
descendant
(
of:
find
.
byType
(
Contain
edButton
),
of:
find
.
byType
(
Elevat
edButton
),
matching:
find
.
byType
(
Material
),
);
const
ColorScheme
colorScheme
=
ColorScheme
.
light
();
// Enabled
Contain
edButton
// Enabled
Elevat
edButton
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
from
(
colorScheme:
colorScheme
),
home:
Center
(
child:
Contain
edButton
(
child:
Elevat
edButton
(
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
...
...
@@ -49,7 +49,7 @@ void main() {
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
Contain
edButton
));
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
Elevat
edButton
));
await
tester
.
startGesture
(
center
);
await
tester
.
pumpAndSettle
();
...
...
@@ -69,12 +69,12 @@ void main() {
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
// Disabled
Contain
edButton
// Disabled
Elevat
edButton
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
from
(
colorScheme:
colorScheme
),
home:
const
Center
(
child:
Contain
edButton
(
child:
Elevat
edButton
(
onPressed:
null
,
child:
Text
(
'button'
),
),
...
...
@@ -98,7 +98,7 @@ void main() {
expect
(
material
.
type
,
MaterialType
.
button
);
});
testWidgets
(
'Default
Contain
edButton meets a11y contrast guidelines'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Default
Elevat
edButton meets a11y contrast guidelines'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
await
tester
.
pumpWidget
(
...
...
@@ -106,8 +106,8 @@ void main() {
theme:
ThemeData
.
from
(
colorScheme:
const
ColorScheme
.
light
()),
home:
Scaffold
(
body:
Center
(
child:
Contain
edButton
(
child:
const
Text
(
'
Contain
edButton'
),
child:
Elevat
edButton
(
child:
const
Text
(
'
Elevat
edButton'
),
onPressed:
()
{
},
focusNode:
focusNode
,
),
...
...
@@ -125,7 +125,7 @@ void main() {
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
// Hovered.
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
Contain
edButton
));
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
Elevat
edButton
));
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
);
...
...
@@ -140,7 +140,7 @@ void main() {
);
testWidgets
(
'
Contain
edButton uses stateful color for text color in different states'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton uses stateful color for text color in different states'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
const
Color
pressedColor
=
Color
(
0x00000001
);
...
...
@@ -165,16 +165,16 @@ void main() {
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
Contain
edButtonTheme
(
data:
Contain
edButtonThemeData
(
child:
Elevat
edButtonTheme
(
data:
Elevat
edButtonThemeData
(
style:
ButtonStyle
(
foregroundColor:
MaterialStateProperty
.
resolveWith
<
Color
>(
getTextColor
),
),
),
child:
Builder
(
builder:
(
BuildContext
context
)
{
return
Contain
edButton
(
child:
const
Text
(
'
Contain
edButton'
),
return
Elevat
edButton
(
child:
const
Text
(
'
Elevat
edButton'
),
onPressed:
()
{},
focusNode:
focusNode
,
);
...
...
@@ -187,7 +187,7 @@ void main() {
);
Color
textColor
()
{
return
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'
Contain
edButton'
)).
text
.
style
.
color
;
return
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'
Elevat
edButton'
)).
text
.
style
.
color
;
}
// Default, not disabled.
...
...
@@ -199,7 +199,7 @@ void main() {
expect
(
textColor
(),
focusedColor
);
// Hovered.
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
Contain
edButton
));
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
Elevat
edButton
));
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
);
...
...
@@ -217,7 +217,7 @@ void main() {
});
testWidgets
(
'
Contain
edButton uses stateful color for icon color in different states'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton uses stateful color for icon color in different states'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
final
Key
buttonKey
=
UniqueKey
();
...
...
@@ -243,18 +243,18 @@ void main() {
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
Contain
edButtonTheme
(
data:
Contain
edButtonThemeData
(
child:
Elevat
edButtonTheme
(
data:
Elevat
edButtonThemeData
(
style:
ButtonStyle
(
foregroundColor:
MaterialStateProperty
.
resolveWith
<
Color
>(
getTextColor
),
),
),
child:
Builder
(
builder:
(
BuildContext
context
)
{
return
Contain
edButton
.
icon
(
return
Elevat
edButton
.
icon
(
key:
buttonKey
,
icon:
const
Icon
(
Icons
.
add
),
label:
const
Text
(
'
Contain
edButton'
),
label:
const
Text
(
'
Elevat
edButton'
),
onPressed:
()
{},
focusNode:
focusNode
,
);
...
...
@@ -293,14 +293,14 @@ void main() {
expect
(
iconColor
(),
pressedColor
);
});
testWidgets
(
'
Contain
edButton onPressed and onLongPress callbacks are correctly called when non-null'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton onPressed and onLongPress callbacks are correctly called when non-null'
,
(
WidgetTester
tester
)
async
{
bool
wasPressed
;
Finder
contain
edButton
;
Finder
elevat
edButton
;
Widget
buildFrame
({
VoidCallback
onPressed
,
VoidCallback
onLongPress
})
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Contain
edButton
(
child:
Elevat
edButton
(
child:
const
Text
(
'button'
),
onPressed:
onPressed
,
onLongPress:
onLongPress
,
...
...
@@ -313,9 +313,9 @@ void main() {
await
tester
.
pumpWidget
(
buildFrame
(
onPressed:
()
{
wasPressed
=
true
;
},
onLongPress:
null
),
);
containedButton
=
find
.
byType
(
Contain
edButton
);
expect
(
tester
.
widget
<
ContainedButton
>(
contain
edButton
).
enabled
,
true
);
await
tester
.
tap
(
contain
edButton
);
elevatedButton
=
find
.
byType
(
Elevat
edButton
);
expect
(
tester
.
widget
<
ElevatedButton
>(
elevat
edButton
).
enabled
,
true
);
await
tester
.
tap
(
elevat
edButton
);
expect
(
wasPressed
,
true
);
// onPressed null, onLongPress not null.
...
...
@@ -323,27 +323,27 @@ void main() {
await
tester
.
pumpWidget
(
buildFrame
(
onPressed:
null
,
onLongPress:
()
{
wasPressed
=
true
;
}),
);
containedButton
=
find
.
byType
(
Contain
edButton
);
expect
(
tester
.
widget
<
ContainedButton
>(
contain
edButton
).
enabled
,
true
);
await
tester
.
longPress
(
contain
edButton
);
elevatedButton
=
find
.
byType
(
Elevat
edButton
);
expect
(
tester
.
widget
<
ElevatedButton
>(
elevat
edButton
).
enabled
,
true
);
await
tester
.
longPress
(
elevat
edButton
);
expect
(
wasPressed
,
true
);
// onPressed null, onLongPress null.
await
tester
.
pumpWidget
(
buildFrame
(
onPressed:
null
,
onLongPress:
null
),
);
containedButton
=
find
.
byType
(
Contain
edButton
);
expect
(
tester
.
widget
<
ContainedButton
>(
contain
edButton
).
enabled
,
false
);
elevatedButton
=
find
.
byType
(
Elevat
edButton
);
expect
(
tester
.
widget
<
ElevatedButton
>(
elevat
edButton
).
enabled
,
false
);
});
testWidgets
(
'
Contain
edButton onPressed and onLongPress callbacks are distinctly recognized'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton onPressed and onLongPress callbacks are distinctly recognized'
,
(
WidgetTester
tester
)
async
{
bool
didPressButton
=
false
;
bool
didLongPressButton
=
false
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Contain
edButton
(
child:
Elevat
edButton
(
onPressed:
()
{
didPressButton
=
true
;
},
...
...
@@ -355,25 +355,25 @@ void main() {
),
);
final
Finder
containedButton
=
find
.
byType
(
Contain
edButton
);
expect
(
tester
.
widget
<
ContainedButton
>(
contain
edButton
).
enabled
,
true
);
final
Finder
elevatedButton
=
find
.
byType
(
Elevat
edButton
);
expect
(
tester
.
widget
<
ElevatedButton
>(
elevat
edButton
).
enabled
,
true
);
expect
(
didPressButton
,
isFalse
);
await
tester
.
tap
(
contain
edButton
);
await
tester
.
tap
(
elevat
edButton
);
expect
(
didPressButton
,
isTrue
);
expect
(
didLongPressButton
,
isFalse
);
await
tester
.
longPress
(
contain
edButton
);
await
tester
.
longPress
(
elevat
edButton
);
expect
(
didLongPressButton
,
isTrue
);
});
testWidgets
(
'Does
Contain
edButton work with hover'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Does
Elevat
edButton work with hover'
,
(
WidgetTester
tester
)
async
{
const
Color
hoverColor
=
Color
(
0xff001122
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Contain
edButton
(
child:
Elevat
edButton
(
style:
ButtonStyle
(
overlayColor:
MaterialStateProperty
.
resolveWith
<
Color
>((
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
hovered
)
?
hoverColor
:
null
;
...
...
@@ -387,7 +387,7 @@ void main() {
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
);
await
gesture
.
addPointer
();
await
gesture
.
moveTo
(
tester
.
getCenter
(
find
.
byType
(
Contain
edButton
)));
await
gesture
.
moveTo
(
tester
.
getCenter
(
find
.
byType
(
Elevat
edButton
)));
await
tester
.
pumpAndSettle
();
final
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
...
...
@@ -396,14 +396,14 @@ void main() {
await
gesture
.
removePointer
();
});
testWidgets
(
'Does
Contain
edButton work with focus'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Does
Elevat
edButton work with focus'
,
(
WidgetTester
tester
)
async
{
const
Color
focusColor
=
Color
(
0xff001122
);
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'
Contain
edButton Node'
);
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'
Elevat
edButton Node'
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Contain
edButton
(
child:
Elevat
edButton
(
style:
ButtonStyle
(
overlayColor:
MaterialStateProperty
.
resolveWith
<
Color
>((
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
focused
)
?
focusColor
:
null
;
...
...
@@ -424,18 +424,18 @@ void main() {
expect
(
inkFeatures
,
paints
..
rect
(
color:
focusColor
));
});
testWidgets
(
'Does
Contain
edButton work with autofocus'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Does
Elevat
edButton work with autofocus'
,
(
WidgetTester
tester
)
async
{
const
Color
focusColor
=
Color
(
0xff001122
);
Color
getOverlayColor
(
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
focused
)
?
focusColor
:
null
;
}
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'
Contain
edButton Node'
);
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'
Elevat
edButton Node'
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Contain
edButton
(
child:
Elevat
edButton
(
autofocus:
true
,
style:
ButtonStyle
(
overlayColor:
MaterialStateProperty
.
resolveWith
<
Color
>(
getOverlayColor
),
...
...
@@ -454,14 +454,14 @@ void main() {
expect
(
inkFeatures
,
paints
..
rect
(
color:
focusColor
));
});
testWidgets
(
'Does
Contain
edButton contribute semantics'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Does
Elevat
edButton contribute semantics'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
Contain
edButton
(
child:
Elevat
edButton
(
style:
ButtonStyle
(
// Specifying minimumSize to mimic the original minimumSize for
// RaisedButton so that the semantics tree's rect and transform
...
...
@@ -501,7 +501,7 @@ void main() {
semantics
.
dispose
();
});
testWidgets
(
'
Contain
edButton size is configurable by ThemeData.materialTapTargetSize'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton size is configurable by ThemeData.materialTapTargetSize'
,
(
WidgetTester
tester
)
async
{
final
ButtonStyle
style
=
ButtonStyle
(
// Specifying minimumSize to mimic the original minimumSize for
// RaisedButton so that the corresponding button size matches
...
...
@@ -516,7 +516,7 @@ void main() {
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
Contain
edButton
(
child:
Elevat
edButton
(
key:
key
,
style:
style
,
child:
const
SizedBox
(
width:
50.0
,
height:
8.0
),
...
...
@@ -537,12 +537,12 @@ void main() {
expect
(
tester
.
getSize
(
find
.
byKey
(
key2
)),
const
Size
(
88.0
,
36.0
));
});
testWidgets
(
'
Contain
edButton has no clip by default'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton has no clip by default'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Contain
edButton
(
child:
Elevat
edButton
(
onPressed:
()
{
/* to make sure the button is enabled */
},
child:
const
Text
(
'button'
),
),
...
...
@@ -551,12 +551,12 @@ void main() {
);
expect
(
tester
.
renderObject
(
find
.
byType
(
Contain
edButton
)),
tester
.
renderObject
(
find
.
byType
(
Elevat
edButton
)),
paintsExactlyCountTimes
(
#clipPath
,
0
),
);
});
testWidgets
(
'
Contain
edButton responds to density changes.'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton responds to density changes.'
,
(
WidgetTester
tester
)
async
{
const
Key
key
=
Key
(
'test'
);
const
Key
childKey
=
Key
(
'test child'
);
...
...
@@ -566,7 +566,7 @@ void main() {
home:
Directionality
(
textDirection:
TextDirection
.
rtl
,
child:
Center
(
child:
Contain
edButton
(
child:
Elevat
edButton
(
style:
ButtonStyle
(
visualDensity:
visualDensity
,
// Specifying minimumSize to mimic the original minimumSize for
...
...
@@ -624,7 +624,7 @@ void main() {
expect
(
childRect
,
equals
(
const
Rect
.
fromLTRB
(
372.0
,
293.0
,
428.0
,
307.0
)));
});
testWidgets
(
'
Contain
edButton.icon responds to applied padding'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Elevat
edButton.icon responds to applied padding'
,
(
WidgetTester
tester
)
async
{
const
Key
buttonKey
=
Key
(
'test'
);
const
Key
labelKey
=
Key
(
'label'
);
await
tester
.
pumpWidget
(
...
...
@@ -635,7 +635,7 @@ void main() {
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
Contain
edButton
.
icon
(
child:
Elevat
edButton
.
icon
(
key:
buttonKey
,
style:
ButtonStyle
(
padding:
MaterialStateProperty
.
all
<
EdgeInsets
>(
const
EdgeInsets
.
fromLTRB
(
16
,
5
,
10
,
12
)),
...
...
@@ -666,7 +666,7 @@ void main() {
expect
(
paddingRect
.
bottom
,
tallerWidget
.
bottom
+
12
);
});
group
(
'Default
Contain
edButton padding for textScaleFactor, textDirection'
,
()
{
group
(
'Default
Elevat
edButton padding for textScaleFactor, textDirection'
,
()
{
const
ValueKey
<
String
>
buttonKey
=
ValueKey
<
String
>(
'button'
);
const
ValueKey
<
String
>
labelKey
=
ValueKey
<
String
>(
'label'
);
const
ValueKey
<
String
>
iconKey
=
ValueKey
<
String
>(
'icon'
);
...
...
@@ -746,7 +746,7 @@ void main() {
for
(
final
double
textScaleFactor
in
textScaleFactorOptions
)
{
for
(
final
TextDirection
textDirection
in
textDirectionOptions
)
{
for
(
final
Widget
icon
in
iconOptions
)
{
final
String
testName
=
'
Contain
edButton'
final
String
testName
=
'
Elevat
edButton'
', text scale
$textScaleFactor
'
'
${icon != null ? ", with icon" : ""}
'
'
${textDirection == TextDirection.rtl ? ", RTL" : ""}
'
;
...
...
@@ -766,12 +766,12 @@ void main() {
child:
Scaffold
(
body:
Center
(
child:
icon
==
null
?
Contain
edButton
(
?
Elevat
edButton
(
key:
buttonKey
,
onPressed:
()
{},
child:
const
Text
(
'button'
,
key:
labelKey
),
)
:
Contain
edButton
.
icon
(
:
Elevat
edButton
.
icon
(
key:
buttonKey
,
onPressed:
()
{},
icon:
icon
,
...
...
@@ -887,7 +887,7 @@ void main() {
}
});
testWidgets
(
'Override
Contain
edButton default padding'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Override
Elevat
edButton default padding'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
from
(
colorScheme:
const
ColorScheme
.
light
()),
...
...
@@ -899,10 +899,10 @@ void main() {
),
child:
Scaffold
(
body:
Center
(
child:
Contain
edButton
(
style:
Contain
edButton
.
styleFrom
(
padding:
const
EdgeInsets
.
all
(
22
)),
child:
Elevat
edButton
(
style:
Elevat
edButton
.
styleFrom
(
padding:
const
EdgeInsets
.
all
(
22
)),
onPressed:
()
{},
child:
const
Text
(
'
Contain
edButton'
)
child:
const
Text
(
'
Elevat
edButton'
)
),
),
),
...
...
@@ -914,7 +914,7 @@ void main() {
final
Padding
paddingWidget
=
tester
.
widget
<
Padding
>(
find
.
descendant
(
of:
find
.
byType
(
Contain
edButton
),
of:
find
.
byType
(
Elevat
edButton
),
matching:
find
.
byType
(
Padding
),
),
);
...
...
packages/flutter/test/material/
contain
ed_button_theme_test.dart
→
packages/flutter/test/material/
elevat
ed_button_theme_test.dart
View file @
eac17471
...
...
@@ -9,14 +9,14 @@ import 'package:flutter/rendering.dart';
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'Passing no
Contain
edButtonTheme returns defaults'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Passing no
Elevat
edButtonTheme returns defaults'
,
(
WidgetTester
tester
)
async
{
const
ColorScheme
colorScheme
=
ColorScheme
.
light
();
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
from
(
colorScheme:
colorScheme
),
home:
Scaffold
(
body:
Center
(
child:
Contain
edButton
(
child:
Elevat
edButton
(
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
...
...
@@ -26,7 +26,7 @@ void main() {
);
final
Finder
buttonMaterial
=
find
.
descendant
(
of:
find
.
byType
(
Contain
edButton
),
of:
find
.
byType
(
Elevat
edButton
),
matching:
find
.
byType
(
Material
),
);
...
...
@@ -43,7 +43,7 @@ void main() {
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
});
group
(
'[Theme, TextTheme,
Contain
edButton style overrides]'
,
()
{
group
(
'[Theme, TextTheme,
Elevat
edButton style overrides]'
,
()
{
const
Color
primaryColor
=
Color
(
0xff000001
);
const
Color
onSurfaceColor
=
Color
(
0xff000002
);
const
Color
shadowColor
=
Color
(
0xff000004
);
...
...
@@ -60,7 +60,7 @@ void main() {
const
Duration
animationDuration
=
Duration
(
milliseconds:
25
);
const
bool
enableFeedback
=
false
;
final
ButtonStyle
style
=
Contain
edButton
.
styleFrom
(
final
ButtonStyle
style
=
Elevat
edButton
.
styleFrom
(
primary:
primaryColor
,
onPrimary:
onPrimaryColor
,
onSurface:
onSurfaceColor
,
...
...
@@ -81,7 +81,7 @@ void main() {
Widget
buildFrame
({
ButtonStyle
buttonStyle
,
ButtonStyle
themeStyle
,
ButtonStyle
overallStyle
})
{
final
Widget
child
=
Builder
(
builder:
(
BuildContext
context
)
{
return
Contain
edButton
(
return
Elevat
edButton
(
style:
buttonStyle
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
...
...
@@ -90,14 +90,14 @@ void main() {
);
return
MaterialApp
(
theme:
ThemeData
.
from
(
colorScheme:
const
ColorScheme
.
light
()).
copyWith
(
containedButtonTheme:
Contain
edButtonThemeData
(
style:
overallStyle
),
elevatedButtonTheme:
Elevat
edButtonThemeData
(
style:
overallStyle
),
),
home:
Scaffold
(
body:
Center
(
// If the
Contain
edButtonTheme widget is present, it's used
// instead of the Theme's ThemeData.
contain
edButtonTheme.
child:
themeStyle
==
null
?
child
:
Contain
edButtonTheme
(
data:
Contain
edButtonThemeData
(
style:
themeStyle
),
// If the
Elevat
edButtonTheme widget is present, it's used
// instead of the Theme's ThemeData.
Elevat
edButtonTheme.
child:
themeStyle
==
null
?
child
:
Elevat
edButtonTheme
(
data:
Elevat
edButtonThemeData
(
style:
themeStyle
),
child:
child
,
),
),
...
...
@@ -106,12 +106,12 @@ void main() {
}
final
Finder
findMaterial
=
find
.
descendant
(
of:
find
.
byType
(
Contain
edButton
),
of:
find
.
byType
(
Elevat
edButton
),
matching:
find
.
byType
(
Material
),
);
final
Finder
findInkWell
=
find
.
descendant
(
of:
find
.
byType
(
Contain
edButton
),
of:
find
.
byType
(
Elevat
edButton
),
matching:
find
.
byType
(
InkWell
),
);
...
...
@@ -138,7 +138,7 @@ void main() {
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
shape
,
shape
);
expect
(
material
.
animationDuration
,
animationDuration
);
expect
(
tester
.
getSize
(
find
.
byType
(
Contain
edButton
)),
const
Size
(
200
,
200
));
expect
(
tester
.
getSize
(
find
.
byType
(
Elevat
edButton
)),
const
Size
(
200
,
200
));
}
testWidgets
(
'Button style overrides defaults'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/material/theme_data_test.dart
View file @
eac17471
...
...
@@ -285,7 +285,7 @@ void main() {
bottomNavigationBarTheme:
const
BottomNavigationBarThemeData
(
type:
BottomNavigationBarType
.
fixed
),
timePickerTheme:
const
TimePickerThemeData
(
backgroundColor:
Colors
.
black
),
textButtonTheme:
TextButtonThemeData
(
style:
TextButton
.
styleFrom
(
primary:
Colors
.
red
)),
containedButtonTheme:
ContainedButtonThemeData
(
style:
Contain
edButton
.
styleFrom
(
primary:
Colors
.
green
)),
elevatedButtonTheme:
ElevatedButtonThemeData
(
style:
Elevat
edButton
.
styleFrom
(
primary:
Colors
.
green
)),
outlinedButtonTheme:
OutlinedButtonThemeData
(
style:
OutlinedButton
.
styleFrom
(
primary:
Colors
.
blue
)),
fixTextFieldOutlineLabel:
false
,
);
...
...
@@ -371,7 +371,7 @@ void main() {
bottomNavigationBarTheme:
const
BottomNavigationBarThemeData
(
type:
BottomNavigationBarType
.
shifting
),
timePickerTheme:
const
TimePickerThemeData
(
backgroundColor:
Colors
.
white
),
textButtonTheme:
const
TextButtonThemeData
(),
containedButtonTheme:
const
Contain
edButtonThemeData
(),
elevatedButtonTheme:
const
Elevat
edButtonThemeData
(),
outlinedButtonTheme:
const
OutlinedButtonThemeData
(),
fixTextFieldOutlineLabel:
true
,
);
...
...
@@ -443,7 +443,7 @@ void main() {
bottomNavigationBarTheme:
otherTheme
.
bottomNavigationBarTheme
,
timePickerTheme:
otherTheme
.
timePickerTheme
,
textButtonTheme:
otherTheme
.
textButtonTheme
,
containedButtonTheme:
otherTheme
.
contain
edButtonTheme
,
elevatedButtonTheme:
otherTheme
.
elevat
edButtonTheme
,
outlinedButtonTheme:
otherTheme
.
outlinedButtonTheme
,
fixTextFieldOutlineLabel:
otherTheme
.
fixTextFieldOutlineLabel
,
);
...
...
@@ -514,7 +514,7 @@ void main() {
expect
(
themeDataCopy
.
bottomNavigationBarTheme
,
equals
(
otherTheme
.
bottomNavigationBarTheme
));
expect
(
themeDataCopy
.
timePickerTheme
,
equals
(
otherTheme
.
timePickerTheme
));
expect
(
themeDataCopy
.
textButtonTheme
,
equals
(
otherTheme
.
textButtonTheme
));
expect
(
themeDataCopy
.
containedButtonTheme
,
equals
(
otherTheme
.
contain
edButtonTheme
));
expect
(
themeDataCopy
.
elevatedButtonTheme
,
equals
(
otherTheme
.
elevat
edButtonTheme
));
expect
(
themeDataCopy
.
outlinedButtonTheme
,
equals
(
otherTheme
.
outlinedButtonTheme
));
expect
(
themeDataCopy
.
fixTextFieldOutlineLabel
,
equals
(
otherTheme
.
fixTextFieldOutlineLabel
));
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment