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
afe6c2e7
Unverified
Commit
afe6c2e7
authored
Apr 06, 2022
by
Kate Lovett
Committed by
GitHub
Apr 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deprecated RaisedButton (#98547)
parent
94fefaa4
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
39 additions
and
1317 deletions
+39
-1317
material.dart
packages/flutter/lib/material.dart
+0
-1
button.dart
packages/flutter/lib/src/material/button.dart
+2
-5
button_theme.dart
packages/flutter/lib/src/material/button_theme.dart
+24
-33
flat_button.dart
packages/flutter/lib/src/material/flat_button.dart
+2
-5
material_button.dart
packages/flutter/lib/src/material/material_button.dart
+7
-10
raised_button.dart
packages/flutter/lib/src/material/raised_button.dart
+0
-272
theme_data.dart
packages/flutter/lib/src/material/theme_data.dart
+2
-5
button_theme_test.dart
packages/flutter/test/material/button_theme_test.dart
+0
-106
inherited_theme_test.dart
packages/flutter/test/material/inherited_theme_test.dart
+0
-94
raised_button_test.dart
packages/flutter/test/material/raised_button_test.dart
+0
-726
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+2
-2
theme_defaults_test.dart
packages/flutter/test/material/theme_defaults_test.dart
+0
-58
No files found.
packages/flutter/lib/material.dart
View file @
afe6c2e7
...
...
@@ -118,7 +118,6 @@ export 'src/material/progress_indicator_theme.dart';
export
'src/material/radio.dart'
;
export
'src/material/radio_list_tile.dart'
;
export
'src/material/radio_theme.dart'
;
export
'src/material/raised_button.dart'
;
export
'src/material/range_slider.dart'
;
export
'src/material/refresh_indicator.dart'
;
export
'src/material/reorderable_list.dart'
;
...
...
packages/flutter/lib/src/material/button.dart
View file @
afe6c2e7
...
...
@@ -26,11 +26,8 @@ import 'theme_data.dart';
/// [ButtonStyle] of a [TextButton], [ElevatedButton] or an
/// [OutlinedButton].
///
/// FlatButton and RaisedButton have been replaced by
/// TextButton and ElevatedButton respectively.
/// ButtonTheme has been replaced by TextButtonTheme and
/// ElevatedButtonTheme. The original classes
/// have been deprecated, please migrate code that uses them.
/// FlatButton has been replaced by TextButton and ButtonTheme has been
/// replaced by TextButtonTheme. Please migrate code that uses them.
/// There's a detailed migration guide for the new button and button
/// theme classes in
/// [flutter.dev/go/material-button-migration-guide](https://flutter.dev/go/material-button-migration-guide).
...
...
packages/flutter/lib/src/material/button_theme.dart
View file @
afe6c2e7
...
...
@@ -11,7 +11,6 @@ import 'constants.dart';
import
'flat_button.dart'
;
import
'material_button.dart'
;
import
'material_state.dart'
;
import
'raised_button.dart'
;
import
'theme.dart'
;
import
'theme_data.dart'
show
MaterialTapTargetSize
;
...
...
@@ -21,8 +20,7 @@ import 'theme_data.dart' show MaterialTapTargetSize;
///
/// See also:
///
/// * [RaisedButton] and [FlatButton] which are configured
/// based on the ambient [ButtonTheme].
/// * [FlatButton] which is configured based on the ambient [ButtonTheme].
enum
ButtonTextTheme
{
/// Button text is black or white depending on [ThemeData.brightness].
normal
,
...
...
@@ -68,8 +66,7 @@ enum ButtonBarLayoutBehavior {
///
/// See also:
///
/// * [FlatButton] and [RaisedButton] which are styled
/// based on the ambient button theme.
/// * [FlatButton] which is styled based on the ambient button theme.
/// * [RawMaterialButton], which can be used to configure a button that doesn't
/// depend on any inherited themes.
class
ButtonTheme
extends
InheritedTheme
{
...
...
@@ -174,11 +171,9 @@ class ButtonTheme extends InheritedTheme {
/// * [ElevatedButton], [ElevatedButtonTheme], [ElevatedButtonThemeData],
/// * [OutlinedButton], [OutlinedButtonTheme], [OutlinedButtonThemeData]
///
/// FlatButton and RaisedButton have been replaced by
/// TextButton and ElevatedButton respectively.
/// ButtonTheme has been replaced by TextButtonTheme and
/// ElevatedButtonTheme. The original classes
/// have been deprecated, please migrate code that uses them.
/// FlatButton has been replaced by TextButton and ButtonTheme has been replaced
/// by TextButtonTheme. Please migrate code that uses them.
///
/// There's a detailed migration guide for the new button and button
/// theme classes in
/// [flutter.dev/go/material-button-migration-guide](https://flutter.dev/go/material-button-migration-guide).
...
...
@@ -196,8 +191,8 @@ class ButtonThemeData with Diagnosticable {
/// [height] parameters must greater than or equal to zero.
///
/// The ButtonTheme's methods that have a [MaterialButton] parameter and
/// have a name with a `get` prefix are used by [
RaisedButton]
///
and [FlatButton] to configure a
[RawMaterialButton].
/// have a name with a `get` prefix are used by [
FlatButton] to configure a
/// [RawMaterialButton].
const
ButtonThemeData
({
this
.
textTheme
=
ButtonTextTheme
.
normal
,
this
.
minWidth
=
88.0
,
...
...
@@ -278,7 +273,7 @@ class ButtonThemeData with Diagnosticable {
///
/// See also:
///
/// * [getPadding], which is used by [
RaisedButton] and [
FlatButton].
/// * [getPadding], which is used by [FlatButton].
EdgeInsetsGeometry
get
padding
{
if
(
_padding
!=
null
)
return
_padding
!;
...
...
@@ -304,7 +299,7 @@ class ButtonThemeData with Diagnosticable {
///
/// See also:
///
/// * [getShape], which is used by [
RaisedButton] and [
FlatButton].
/// * [getShape], which is used by [FlatButton].
ShapeBorder
get
shape
{
if
(
_shape
!=
null
)
return
_shape
!;
...
...
@@ -333,7 +328,7 @@ class ButtonThemeData with Diagnosticable {
/// This property only affects [DropdownButton] and its menu.
final
bool
alignedDropdown
;
/// The background fill color
for [RaisedButton]s
.
/// The background fill color.
///
/// This property is null by default.
///
...
...
@@ -343,18 +338,17 @@ class ButtonThemeData with Diagnosticable {
///
/// See also:
///
/// * [getFillColor], which is used by [RaisedButton] to compute its
/// background fill color.
/// * [getFillColor], which is used to compute the background fill color.
final
Color
?
_buttonColor
;
/// The background fill color
for disabled [RaisedButton]s
.
/// The background fill color
when disabled
.
///
/// This property is null by default.
///
/// See also:
///
/// * [getDisabledFillColor], which is
used by [RaisedButton] to compute its
///
background fill color
.
/// * [getDisabledFillColor], which is
to compute background fill color for
///
disabled state
.
final
Color
?
_disabledColor
;
/// The fill color of the button when it has the input focus.
...
...
@@ -366,7 +360,7 @@ class ButtonThemeData with Diagnosticable {
///
/// See also:
///
/// * [getFocusColor], which is used by [
RaisedButton] and [
FlatButton].
/// * [getFocusColor], which is used by [FlatButton].
final
Color
?
_focusColor
;
/// The fill color of the button when a pointer is hovering over it.
...
...
@@ -378,7 +372,7 @@ class ButtonThemeData with Diagnosticable {
///
/// See also:
///
/// * [getHoverColor], which is used by [
RaisedButton] and [
FlatButton].
/// * [getHoverColor], which is used by [FlatButton].
final
Color
?
_hoverColor
;
/// The color of the overlay that appears when a button is pressed.
...
...
@@ -387,7 +381,7 @@ class ButtonThemeData with Diagnosticable {
///
/// See also:
///
/// * [getHighlightColor], which is used by [
RaisedButton] and [
FlatButton].
/// * [getHighlightColor], which is used by [FlatButton].
final
Color
?
_highlightColor
;
/// The color of the ink "splash" overlay that appears when a button is tapped.
...
...
@@ -396,7 +390,7 @@ class ButtonThemeData with Diagnosticable {
///
/// See also:
///
/// * [getSplashColor], which is used by [
RaisedButton] and [
FlatButton].
/// * [getSplashColor], which is used by [FlatButton].
final
Color
?
_splashColor
;
/// A set of thirteen colors that can be used to derive the button theme's
...
...
@@ -417,7 +411,7 @@ class ButtonThemeData with Diagnosticable {
//
// See also:
//
// * [getMaterialTargetTapSize], which is used by [
RaisedButton] and [
FlatButton].
// * [getMaterialTargetTapSize], which is used by [FlatButton].
final
MaterialTapTargetSize
?
_materialTapTargetSize
;
/// The [button]'s overall brightness.
...
...
@@ -484,9 +478,6 @@ class ButtonThemeData with Diagnosticable {
/// Otherwise, if button is a [FlatButton] then null is
/// returned.
///
/// Otherwise, if button is a [RaisedButton], returns the `buttonColor`
/// constructor parameter if it was non-null and the button is enabled.
///
/// Otherwise the fill color depends on the value of [getTextTheme].
///
/// * [ButtonTextTheme.normal] or [ButtonTextTheme.accent], the
...
...
@@ -505,7 +496,7 @@ class ButtonThemeData with Diagnosticable {
if
(
button
is
FlatButton
||
button
.
runtimeType
==
MaterialButton
)
return
null
;
if
(
button
.
enabled
&&
button
is
RaisedButton
&&
_buttonColor
!=
null
)
if
(
button
.
enabled
&&
_buttonColor
!=
null
)
return
_buttonColor
;
switch
(
getTextTheme
(
button
))
{
...
...
@@ -569,7 +560,7 @@ class ButtonThemeData with Diagnosticable {
/// Returns the button's [MaterialButton.splashColor] if it is non-null.
///
/// Otherwise, returns the value of the `splashColor` constructor parameter
/// it is non-null
and [button] is a [RaisedButton]
.
/// it is non-null.
///
/// Otherwise, returns the value of the `splashColor` constructor parameter
/// if it is non-null and [button] is a [FlatButton] and
...
...
@@ -580,7 +571,7 @@ class ButtonThemeData with Diagnosticable {
if
(
button
.
splashColor
!=
null
)
return
button
.
splashColor
!;
if
(
_splashColor
!=
null
&&
button
is
RaisedButton
)
if
(
_splashColor
!=
null
)
return
_splashColor
!;
if
(
_splashColor
!=
null
&&
button
is
FlatButton
)
{
...
...
@@ -715,8 +706,8 @@ class ButtonThemeData with Diagnosticable {
///
/// Returns the button's [MaterialButton.padding] if it is non-null.
///
/// If this is a button constructed with [
RaisedButton.icon] or
///
[FlatButton.icon] then the padding
is:
/// If this is a button constructed with [
FlatButton.icon] then the padding
/// is:
/// `EdgeInsetsDirectional.only(start: 12.0, end: 16.0)`.
///
/// Otherwise, returns [padding] if it is non-null.
...
...
packages/flutter/lib/src/material/flat_button.dart
View file @
afe6c2e7
...
...
@@ -14,11 +14,8 @@ import 'theme_data.dart';
///
/// ### This class is deprecated, please use [TextButton] instead.
///
/// FlatButton and RaisedButton have been replaced by
/// [TextButton] and [ElevatedButton] respectively.
/// ButtonTheme has been replaced by [TextButtonTheme] and
/// [ElevatedButtonTheme]. The original classes
/// will eventually be removed, please migrate code that uses them.
/// FlatButton have been replaced by [TextButton] and ButtonTheme has been
/// replaced by [TextButtonTheme]. Please migrate code that uses them.
/// There's a detailed migration guide for the new button and button
/// theme classes in
/// [flutter.dev/go/material-button-migration-guide](https://flutter.dev/go/material-button-migration-guide).
...
...
packages/flutter/lib/src/material/material_button.dart
View file @
afe6c2e7
...
...
@@ -21,10 +21,8 @@ import 'theme_data.dart';
///
/// ### This class is obsolete.
///
/// FlatButton and RaisedButton have been replaced by
/// TextButton and ElevatedButton respectively.
/// ButtonTheme has been replaced by TextButtonTheme and
/// ElevatedButtonTheme. The appearance of the
/// FlatButton has been replaced by TextButton and ButtonTheme has been replaced
/// by TextButtonTheme. The appearance of the
/// new widgets can be customized by specifying a [ButtonStyle]
/// or by creating a one-off style using a `styleFrom` method like
/// [TextButton.styleFrom]. The original button classes
...
...
@@ -38,9 +36,9 @@ import 'theme_data.dart';
/// MaterialButtons whose [onPressed] and [onLongPress] callbacks are null will be disabled. To have
/// an enabled button, make sure to pass a non-null value for [onPressed] or [onLongPress].
///
/// Rather than using this class directly, consider using [FlatButton]
///
or [RaisedButton], which configure this class with
///
appropriate defaults that match the material
design specification.
/// Rather than using this class directly, consider using [FlatButton]
, which
///
configure this class with appropriate defaults that match the material
/// design specification.
///
/// To create a button directly, without inheriting theme defaults, use
/// [RawMaterialButton].
...
...
@@ -55,7 +53,7 @@ class MaterialButton extends StatelessWidget {
/// Creates a material button.
///
/// Rather than creating a material button directly, consider using
/// [FlatButton]
or [RaisedButton]
. To create a custom Material button
/// [FlatButton]. To create a custom Material button
/// consider using [RawMaterialButton].
///
/// The [autofocus] and [clipBehavior] arguments must not be null.
...
...
@@ -457,8 +455,7 @@ class MaterialButton extends StatelessWidget {
}
}
/// The type of [MaterialButton]s created with RaisedButton.icon] and
/// FlatButton.icon.
/// The type of [MaterialButton]s created with FlatButton.icon.
///
/// This mixin only exists to give the "label and icon" button widgets a distinct
/// type for the sake of [ButtonTheme].
...
...
packages/flutter/lib/src/material/raised_button.dart
deleted
100644 → 0
View file @
94fefaa4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'button.dart'
;
import
'button_theme.dart'
;
import
'material_button.dart'
;
import
'theme.dart'
;
import
'theme_data.dart'
;
/// A Material Design "raised button".
///
/// ### This class is deprecated, please use [ElevatedButton] instead.
///
/// FlatButton and RaisedButton have been replaced by
/// [TextButton] and [ElevatedButton] respectively.
/// ButtonTheme has been replaced by [TextButtonTheme] and
/// [ElevatedButtonTheme]. The original classes
/// will eventually be removed, please migrate code that uses them.
/// There's a detailed migration guide for the new button and button
/// theme classes in
/// [flutter.dev/go/material-button-migration-guide](https://flutter.dev/go/material-button-migration-guide).
@Deprecated
(
'Use ElevatedButton instead. See the migration guide in flutter.dev/go/material-button-migration-guide). '
'This feature was deprecated after v1.26.0-18.0.pre.'
,
)
class
RaisedButton
extends
MaterialButton
{
/// Create a filled button.
///
/// The [autofocus] and [clipBehavior] arguments must not be null.
/// Additionally, [elevation], [hoverElevation], [focusElevation],
/// [highlightElevation], and [disabledElevation] must be non-negative, if
/// specified.
@Deprecated
(
'Use ElevatedButton instead. See the migration guide in flutter.dev/go/material-button-migration-guide). '
'This feature was deprecated after v1.26.0-18.0.pre.'
,
)
const
RaisedButton
({
Key
?
key
,
required
VoidCallback
?
onPressed
,
VoidCallback
?
onLongPress
,
ValueChanged
<
bool
>?
onHighlightChanged
,
MouseCursor
?
mouseCursor
,
ButtonTextTheme
?
textTheme
,
Color
?
textColor
,
Color
?
disabledTextColor
,
Color
?
color
,
Color
?
disabledColor
,
Color
?
focusColor
,
Color
?
hoverColor
,
Color
?
highlightColor
,
Color
?
splashColor
,
Brightness
?
colorBrightness
,
double
?
elevation
,
double
?
focusElevation
,
double
?
hoverElevation
,
double
?
highlightElevation
,
double
?
disabledElevation
,
EdgeInsetsGeometry
?
padding
,
VisualDensity
?
visualDensity
,
ShapeBorder
?
shape
,
Clip
clipBehavior
=
Clip
.
none
,
FocusNode
?
focusNode
,
bool
autofocus
=
false
,
MaterialTapTargetSize
?
materialTapTargetSize
,
Duration
?
animationDuration
,
Widget
?
child
,
})
:
assert
(
autofocus
!=
null
),
assert
(
elevation
==
null
||
elevation
>=
0.0
),
assert
(
focusElevation
==
null
||
focusElevation
>=
0.0
),
assert
(
hoverElevation
==
null
||
hoverElevation
>=
0.0
),
assert
(
highlightElevation
==
null
||
highlightElevation
>=
0.0
),
assert
(
disabledElevation
==
null
||
disabledElevation
>=
0.0
),
assert
(
clipBehavior
!=
null
),
super
(
key:
key
,
onPressed:
onPressed
,
onLongPress:
onLongPress
,
onHighlightChanged:
onHighlightChanged
,
mouseCursor:
mouseCursor
,
textTheme:
textTheme
,
textColor:
textColor
,
disabledTextColor:
disabledTextColor
,
color:
color
,
disabledColor:
disabledColor
,
focusColor:
focusColor
,
hoverColor:
hoverColor
,
highlightColor:
highlightColor
,
splashColor:
splashColor
,
colorBrightness:
colorBrightness
,
elevation:
elevation
,
focusElevation:
focusElevation
,
hoverElevation:
hoverElevation
,
highlightElevation:
highlightElevation
,
disabledElevation:
disabledElevation
,
padding:
padding
,
visualDensity:
visualDensity
,
shape:
shape
,
clipBehavior:
clipBehavior
,
focusNode:
focusNode
,
autofocus:
autofocus
,
materialTapTargetSize:
materialTapTargetSize
,
animationDuration:
animationDuration
,
child:
child
,
);
/// Create a filled 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 [elevation], [highlightElevation], [disabledElevation], [icon],
/// [label], and [clipBehavior] arguments must not be null.
@Deprecated
(
'Use ElevatedButton instead. See the migration guide in flutter.dev/go/material-button-migration-guide). '
'This feature was deprecated after v1.26.0-18.0.pre.'
,
)
factory
RaisedButton
.
icon
({
Key
?
key
,
required
VoidCallback
?
onPressed
,
VoidCallback
?
onLongPress
,
ValueChanged
<
bool
>?
onHighlightChanged
,
MouseCursor
?
mouseCursor
,
ButtonTextTheme
?
textTheme
,
Color
?
textColor
,
Color
?
disabledTextColor
,
Color
?
color
,
Color
?
disabledColor
,
Color
?
focusColor
,
Color
?
hoverColor
,
Color
?
highlightColor
,
Color
?
splashColor
,
Brightness
?
colorBrightness
,
double
?
elevation
,
double
?
highlightElevation
,
double
?
disabledElevation
,
ShapeBorder
?
shape
,
Clip
clipBehavior
,
FocusNode
?
focusNode
,
bool
autofocus
,
EdgeInsetsGeometry
?
padding
,
MaterialTapTargetSize
?
materialTapTargetSize
,
Duration
?
animationDuration
,
required
Widget
icon
,
required
Widget
label
,
})
=
_RaisedButtonWithIcon
;
@override
Widget
build
(
BuildContext
context
)
{
final
ThemeData
theme
=
Theme
.
of
(
context
);
final
ButtonThemeData
buttonTheme
=
ButtonTheme
.
of
(
context
);
return
RawMaterialButton
(
onPressed:
onPressed
,
onLongPress:
onLongPress
,
onHighlightChanged:
onHighlightChanged
,
mouseCursor:
mouseCursor
,
clipBehavior:
clipBehavior
,
fillColor:
buttonTheme
.
getFillColor
(
this
),
textStyle:
theme
.
textTheme
.
button
!.
copyWith
(
color:
buttonTheme
.
getTextColor
(
this
)),
focusColor:
buttonTheme
.
getFocusColor
(
this
),
hoverColor:
buttonTheme
.
getHoverColor
(
this
),
highlightColor:
buttonTheme
.
getHighlightColor
(
this
),
splashColor:
buttonTheme
.
getSplashColor
(
this
),
elevation:
buttonTheme
.
getElevation
(
this
),
focusElevation:
buttonTheme
.
getFocusElevation
(
this
),
hoverElevation:
buttonTheme
.
getHoverElevation
(
this
),
highlightElevation:
buttonTheme
.
getHighlightElevation
(
this
),
disabledElevation:
buttonTheme
.
getDisabledElevation
(
this
),
padding:
buttonTheme
.
getPadding
(
this
),
visualDensity:
visualDensity
??
theme
.
visualDensity
,
constraints:
buttonTheme
.
getConstraints
(
this
),
shape:
buttonTheme
.
getShape
(
this
),
focusNode:
focusNode
,
autofocus:
autofocus
,
animationDuration:
buttonTheme
.
getAnimationDuration
(
this
),
materialTapTargetSize:
buttonTheme
.
getMaterialTapTargetSize
(
this
),
child:
child
,
);
}
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
properties
.
add
(
DiagnosticsProperty
<
double
>(
'elevation'
,
elevation
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
double
>(
'focusElevation'
,
focusElevation
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
double
>(
'hoverElevation'
,
hoverElevation
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
double
>(
'highlightElevation'
,
highlightElevation
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
double
>(
'disabledElevation'
,
disabledElevation
,
defaultValue:
null
));
}
}
/// The type of RaisedButtons created with [RaisedButton.icon].
///
/// This class only exists to give RaisedButtons created with [RaisedButton.icon]
/// a distinct class for the sake of [ButtonTheme]. It can not be instantiated.
class
_RaisedButtonWithIcon
extends
RaisedButton
with
MaterialButtonWithIconMixin
{
_RaisedButtonWithIcon
({
Key
?
key
,
required
VoidCallback
?
onPressed
,
VoidCallback
?
onLongPress
,
ValueChanged
<
bool
>?
onHighlightChanged
,
MouseCursor
?
mouseCursor
,
ButtonTextTheme
?
textTheme
,
Color
?
textColor
,
Color
?
disabledTextColor
,
Color
?
color
,
Color
?
disabledColor
,
Color
?
focusColor
,
Color
?
hoverColor
,
Color
?
highlightColor
,
Color
?
splashColor
,
Brightness
?
colorBrightness
,
double
?
elevation
,
double
?
highlightElevation
,
double
?
disabledElevation
,
ShapeBorder
?
shape
,
Clip
clipBehavior
=
Clip
.
none
,
FocusNode
?
focusNode
,
bool
autofocus
=
false
,
EdgeInsetsGeometry
?
padding
,
MaterialTapTargetSize
?
materialTapTargetSize
,
Duration
?
animationDuration
,
required
Widget
icon
,
required
Widget
label
,
})
:
assert
(
elevation
==
null
||
elevation
>=
0.0
),
assert
(
highlightElevation
==
null
||
highlightElevation
>=
0.0
),
assert
(
disabledElevation
==
null
||
disabledElevation
>=
0.0
),
assert
(
clipBehavior
!=
null
),
assert
(
icon
!=
null
),
assert
(
label
!=
null
),
assert
(
autofocus
!=
null
),
super
(
key:
key
,
onPressed:
onPressed
,
onLongPress:
onLongPress
,
onHighlightChanged:
onHighlightChanged
,
mouseCursor:
mouseCursor
,
textTheme:
textTheme
,
textColor:
textColor
,
disabledTextColor:
disabledTextColor
,
color:
color
,
disabledColor:
disabledColor
,
focusColor:
focusColor
,
hoverColor:
hoverColor
,
highlightColor:
highlightColor
,
splashColor:
splashColor
,
colorBrightness:
colorBrightness
,
elevation:
elevation
,
highlightElevation:
highlightElevation
,
disabledElevation:
disabledElevation
,
shape:
shape
,
clipBehavior:
clipBehavior
,
focusNode:
focusNode
,
autofocus:
autofocus
,
padding:
padding
,
materialTapTargetSize:
materialTapTargetSize
,
animationDuration:
animationDuration
,
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
icon
,
const
SizedBox
(
width:
8.0
),
label
,
],
),
);
}
packages/flutter/lib/src/material/theme_data.dart
View file @
afe6c2e7
...
...
@@ -115,7 +115,6 @@ const Color _kDarkThemeSplashColor = Color(0x40CCCCCC);
/// * [TextButton]
/// * [ElevatedButton]
/// * [FlatButton]
/// * [RaisedButton]
/// * The time picker widget ([showTimePicker])
/// * [SnackBar]
/// * [Chip]
...
...
@@ -524,7 +523,6 @@ class ThemeData with Diagnosticable {
// [disabledColor], [highlightColor], and [splashColor].
buttonTheme
??=
ButtonThemeData
(
colorScheme:
colorScheme
,
// Defaults to the fill color for RaisedButtons for backwards compatibility.
buttonColor:
buttonColor
??
(
isDark
?
primarySwatch
[
600
]!
:
Colors
.
grey
[
300
]!),
disabledColor:
disabledColor
,
focusColor:
focusColor
,
...
...
@@ -1423,8 +1421,7 @@ class ThemeData with Diagnosticable {
/// A theme for customizing the appearance and layout of [ButtonBar] widgets.
final
ButtonBarThemeData
buttonBarTheme
;
/// Defines the default configuration of button widgets, like [RaisedButton]
/// and [FlatButton].
/// Defines the default configuration of button widgets, like [FlatButton].
final
ButtonThemeData
buttonTheme
;
/// The colors and styles used to render [Card].
...
...
@@ -1627,7 +1624,7 @@ class ThemeData with Diagnosticable {
)
final
IconThemeData
accentIconTheme
;
/// The default fill color of the [Material]
used in [RaisedButton]s
.
/// The default fill color of the [Material].
@Deprecated
(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v2.3.0-0.2.pre.'
,
...
...
packages/flutter/test/material/button_theme_test.dart
View file @
afe6c2e7
...
...
@@ -117,112 +117,6 @@ void main() {
expect
(
theme
.
colorScheme
,
const
ColorScheme
.
dark
());
});
testWidgets
(
'Theme buttonTheme defaults'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
lightTheme
=
ThemeData
.
light
();
late
ButtonTextTheme
textTheme
;
late
BoxConstraints
constraints
;
late
EdgeInsets
padding
;
late
ShapeBorder
shape
;
const
Color
disabledColor
=
Color
(
0xFF00FF00
);
await
tester
.
pumpWidget
(
Theme
(
data:
lightTheme
.
copyWith
(
disabledColor:
disabledColor
,
// disabled RaisedButton fill color
buttonTheme:
const
ButtonThemeData
(
disabledColor:
disabledColor
),
textTheme:
lightTheme
.
textTheme
.
copyWith
(
button:
lightTheme
.
textTheme
.
button
!.
copyWith
(
// The button's height will match because there's no
// vertical padding by default
fontSize:
48.0
,
),
),
),
child:
Builder
(
builder:
(
BuildContext
context
)
{
final
ButtonThemeData
theme
=
ButtonTheme
.
of
(
context
);
textTheme
=
theme
.
textTheme
;
constraints
=
theme
.
constraints
;
padding
=
theme
.
padding
as
EdgeInsets
;
shape
=
theme
.
shape
;
return
Container
(
alignment:
Alignment
.
topLeft
,
child:
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
null
,
child:
Text
(
'b'
),
// intrinsic width < minimum width
),
),
);
},
),
),
);
expect
(
textTheme
,
ButtonTextTheme
.
normal
);
expect
(
constraints
,
const
BoxConstraints
(
minWidth:
88.0
,
minHeight:
36.0
));
expect
(
padding
,
const
EdgeInsets
.
symmetric
(
horizontal:
16.0
));
expect
(
shape
,
const
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
)),
));
expect
(
tester
.
widget
<
Material
>(
find
.
byType
(
Material
)).
shape
,
shape
);
expect
(
tester
.
widget
<
Material
>(
find
.
byType
(
Material
)).
color
,
disabledColor
);
expect
(
tester
.
getSize
(
find
.
byType
(
Material
)),
const
Size
(
88.0
,
48.0
));
});
testWidgets
(
'Theme buttonTheme ButtonTheme overrides'
,
(
WidgetTester
tester
)
async
{
late
ButtonTextTheme
textTheme
;
late
BoxConstraints
constraints
;
late
EdgeInsets
padding
;
late
ShapeBorder
shape
;
await
tester
.
pumpWidget
(
Theme
(
data:
ThemeData
.
light
().
copyWith
(
buttonColor:
const
Color
(
0xFF00FF00
),
// enabled RaisedButton fill color
),
child:
ButtonTheme
(
textTheme:
ButtonTextTheme
.
primary
,
minWidth:
100.0
,
height:
200.0
,
padding:
EdgeInsets
.
zero
,
buttonColor:
const
Color
(
0xFF00FF00
),
// enabled RaisedButton fill color
shape:
const
RoundedRectangleBorder
(),
child:
Builder
(
builder:
(
BuildContext
context
)
{
final
ButtonThemeData
theme
=
ButtonTheme
.
of
(
context
);
textTheme
=
theme
.
textTheme
;
constraints
=
theme
.
constraints
;
padding
=
theme
.
padding
as
EdgeInsets
;
shape
=
theme
.
shape
;
return
Container
(
alignment:
Alignment
.
topLeft
,
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
()
{
},
child:
const
Text
(
'b'
),
// intrinsic width < minimum width
),
),
);
},
),
),
),
);
expect
(
textTheme
,
ButtonTextTheme
.
primary
);
expect
(
constraints
,
const
BoxConstraints
(
minWidth:
100.0
,
minHeight:
200.0
));
expect
(
padding
,
EdgeInsets
.
zero
);
expect
(
shape
,
const
RoundedRectangleBorder
());
expect
(
tester
.
widget
<
Material
>(
find
.
byType
(
Material
)).
shape
,
shape
);
expect
(
tester
.
widget
<
Material
>(
find
.
byType
(
Material
)).
color
,
const
Color
(
0xFF00FF00
));
expect
(
tester
.
getSize
(
find
.
byType
(
Material
)),
const
Size
(
100.0
,
200.0
));
});
testWidgets
(
'ButtonTheme alignedDropdown'
,
(
WidgetTester
tester
)
async
{
final
Key
dropdownKey
=
UniqueKey
();
...
...
packages/flutter/test/material/inherited_theme_test.dart
View file @
afe6c2e7
...
...
@@ -607,99 +607,5 @@ void main() {
await
tester
.
pumpAndSettle
();
// route animation
expect
(
getTextColor
(
'selected'
),
isNot
(
selectedButtonColor
));
expect
(
getTextColor
(
'unselected'
),
isNot
(
buttonColor
));
});
testWidgets
(
'ButtonTheme.wrap()'
,
(
WidgetTester
tester
)
async
{
const
Color
buttonColor
=
Color
(
0xFF00FF00
);
const
Color
disabledButtonColor
=
Color
(
0xFFFF0000
);
final
Widget
buttons
=
Scaffold
(
body:
Center
(
child:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
const
RaisedButton
(
onPressed:
null
,
child:
Text
(
'disabled'
)),
RaisedButton
(
child:
const
Text
(
'enabled'
),
onPressed:
()
{
}),
],
),
),
);
late
BuildContext
navigatorContext
;
Widget
buildFrame
()
{
return
MaterialApp
(
home:
Scaffold
(
body:
ButtonTheme
.
fromButtonThemeData
(
data:
const
ButtonThemeData
(
buttonColor:
buttonColor
,
disabledColor:
disabledButtonColor
,
),
child:
Builder
(
// Introduce a context so the shadow ButtonTheme is visible to captureAll().
builder:
(
BuildContext
context
)
{
navigatorContext
=
context
;
return
Center
(
child:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
RaisedButton
(
child:
const
Text
(
'push unwrapped'
),
onPressed:
()
{
Navigator
.
of
(
context
).
push
<
void
>(
MaterialPageRoute
<
void
>(
// The slider will see the default ButtonTheme when built.
builder:
(
BuildContext
_
)
=>
buttons
,
),
);
},
),
RaisedButton
(
child:
const
Text
(
'push wrapped'
),
onPressed:
()
{
Navigator
.
of
(
context
).
push
<
void
>(
MaterialPageRoute
<
void
>(
// Capture the shadow toggleButtons.
builder:
(
BuildContext
_
)
=>
InheritedTheme
.
captureAll
(
context
,
buttons
),
),
);
},
),
],
),
);
},
),
),
),
);
}
Color
getButtonColor
(
String
text
)
{
return
tester
.
widget
<
Material
>(
find
.
descendant
(
of:
find
.
widgetWithText
(
RawMaterialButton
,
text
),
matching:
find
.
byType
(
Material
),
),
).
color
!;
}
await
tester
.
pumpWidget
(
buildFrame
());
// Show a route which contains toggleButtons.
await
tester
.
tap
(
find
.
text
(
'push wrapped'
));
await
tester
.
pumpAndSettle
();
// route animation
expect
(
getButtonColor
(
'disabled'
),
disabledButtonColor
);
expect
(
getButtonColor
(
'enabled'
),
buttonColor
);
Navigator
.
of
(
navigatorContext
).
pop
();
await
tester
.
pumpAndSettle
();
// route animation
await
tester
.
tap
(
find
.
text
(
'push unwrapped'
));
await
tester
.
pumpAndSettle
();
// route animation
expect
(
getButtonColor
(
'disabled'
),
isNot
(
disabledButtonColor
));
expect
(
getButtonColor
(
'enabled'
),
isNot
(
buttonColor
));
});
}
packages/flutter/test/material/raised_button_test.dart
deleted
100644 → 0
View file @
94fefaa4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../rendering/mock_canvas.dart'
;
import
'../widgets/semantics_tester.dart'
;
void
main
(
)
{
testWidgets
(
'RaisedButton defaults'
,
(
WidgetTester
tester
)
async
{
final
Finder
rawButtonMaterial
=
find
.
descendant
(
of:
find
.
byType
(
RaisedButton
),
matching:
find
.
byType
(
Material
),
);
// Enabled RaisedButton
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
Material
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0xffe0e0e0
));
expect
(
material
.
elevation
,
2.0
);
expect
(
material
.
shadowColor
,
null
);
expect
(
material
.
shape
,
const
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
))));
expect
(
material
.
textStyle
!.
color
,
const
Color
(
0xdd000000
));
expect
(
material
.
textStyle
!.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
!.
fontSize
,
14
);
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
RaisedButton
));
await
tester
.
startGesture
(
center
);
await
tester
.
pumpAndSettle
();
// Only elevation changes when enabled and pressed.
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0xffe0e0e0
));
expect
(
material
.
elevation
,
8.0
);
expect
(
material
.
shadowColor
,
null
);
expect
(
material
.
shape
,
const
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
))));
expect
(
material
.
textStyle
!.
color
,
const
Color
(
0xdd000000
));
expect
(
material
.
textStyle
!.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
!.
fontSize
,
14
);
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
// Disabled RaisedButton
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
null
,
child:
Text
(
'button'
),
),
),
);
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0x61000000
));
expect
(
material
.
elevation
,
0.0
);
expect
(
material
.
shadowColor
,
null
);
expect
(
material
.
shape
,
const
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
))));
expect
(
material
.
textStyle
!.
color
,
const
Color
(
0x61000000
));
expect
(
material
.
textStyle
!.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
!.
fontSize
,
14
);
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
});
testWidgets
(
'RaisedButton implements debugFillProperties'
,
(
WidgetTester
tester
)
async
{
final
DiagnosticPropertiesBuilder
builder
=
DiagnosticPropertiesBuilder
();
RaisedButton
(
onPressed:
()
{
},
textColor:
const
Color
(
0xFF00FF00
),
disabledTextColor:
const
Color
(
0xFFFF0000
),
color:
const
Color
(
0xFF000000
),
highlightColor:
const
Color
(
0xFF1565C0
),
splashColor:
const
Color
(
0xFF9E9E9E
),
child:
const
Text
(
'Hello'
),
).
debugFillProperties
(
builder
);
final
List
<
String
>
description
=
builder
.
properties
.
where
((
DiagnosticsNode
node
)
=>
!
node
.
isFiltered
(
DiagnosticLevel
.
info
))
.
map
((
DiagnosticsNode
node
)
=>
node
.
toString
()).
toList
();
expect
(
description
,
<
String
>[
'textColor: Color(0xff00ff00)'
,
'disabledTextColor: Color(0xffff0000)'
,
'color: Color(0xff000000)'
,
'highlightColor: Color(0xff1565c0)'
,
'splashColor: Color(0xff9e9e9e)'
,
]);
});
testWidgets
(
'Default RaisedButton meets a11y contrast guidelines'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
RaisedButton
(
onPressed:
()
{
},
focusNode:
focusNode
,
child:
const
Text
(
'RaisedButton'
),
),
),
),
),
);
// Default, not disabled.
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
// Focused.
focusNode
.
requestFocus
();
await
tester
.
pumpAndSettle
();
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
// Hovered.
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
RaisedButton
));
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
);
await
gesture
.
addPointer
();
addTearDown
(
gesture
.
removePointer
);
await
gesture
.
moveTo
(
center
);
await
tester
.
pumpAndSettle
();
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
// Highlighted (pressed).
await
gesture
.
down
(
center
);
await
tester
.
pump
();
// Start the splash and highlight animations.
await
tester
.
pump
(
const
Duration
(
milliseconds:
800
));
// Wait for splash and highlight to be well under way.
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
},
skip:
isBrowser
,
// https://github.com/flutter/flutter/issues/44115
);
testWidgets
(
'RaisedButton uses stateful color for text color in different states'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
const
Color
pressedColor
=
Color
(
0x00000001
);
const
Color
hoverColor
=
Color
(
0x00000002
);
const
Color
focusedColor
=
Color
(
0x00000003
);
const
Color
defaultColor
=
Color
(
0x00000004
);
Color
getTextColor
(
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
pressed
))
{
return
pressedColor
;
}
if
(
states
.
contains
(
MaterialState
.
hovered
))
{
return
hoverColor
;
}
if
(
states
.
contains
(
MaterialState
.
focused
))
{
return
focusedColor
;
}
return
defaultColor
;
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
RaisedButton
(
onPressed:
()
{},
focusNode:
focusNode
,
textColor:
MaterialStateColor
.
resolveWith
(
getTextColor
),
child:
const
Text
(
'RaisedButton'
),
),
),
),
),
);
Color
textColor
()
{
return
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'RaisedButton'
)).
text
.
style
!.
color
!;
}
// Default, not disabled.
expect
(
textColor
(),
equals
(
defaultColor
));
// Focused.
focusNode
.
requestFocus
();
await
tester
.
pumpAndSettle
();
expect
(
textColor
(),
focusedColor
);
// Hovered.
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
RaisedButton
));
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
);
await
gesture
.
addPointer
();
addTearDown
(
gesture
.
removePointer
);
await
gesture
.
moveTo
(
center
);
await
tester
.
pumpAndSettle
();
expect
(
textColor
(),
hoverColor
);
// Highlighted (pressed).
await
gesture
.
down
(
center
);
await
tester
.
pump
();
// Start the splash and highlight animations.
await
tester
.
pump
(
const
Duration
(
milliseconds:
800
));
// Wait for splash and highlight to be well under way.
expect
(
textColor
(),
pressedColor
);
});
testWidgets
(
'RaisedButton uses stateful color for icon color in different states'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
final
Key
buttonKey
=
UniqueKey
();
const
Color
pressedColor
=
Color
(
0x00000001
);
const
Color
hoverColor
=
Color
(
0x00000002
);
const
Color
focusedColor
=
Color
(
0x00000003
);
const
Color
defaultColor
=
Color
(
0x00000004
);
Color
getTextColor
(
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
pressed
))
{
return
pressedColor
;
}
if
(
states
.
contains
(
MaterialState
.
hovered
))
{
return
hoverColor
;
}
if
(
states
.
contains
(
MaterialState
.
focused
))
{
return
focusedColor
;
}
return
defaultColor
;
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
RaisedButton
.
icon
(
key:
buttonKey
,
icon:
const
Icon
(
Icons
.
add
),
label:
const
Text
(
'RaisedButton'
),
onPressed:
()
{},
focusNode:
focusNode
,
textColor:
MaterialStateColor
.
resolveWith
(
getTextColor
),
),
),
),
),
);
Color
iconColor
()
=>
_iconStyle
(
tester
,
Icons
.
add
).
color
!;
// Default, not disabled.
expect
(
iconColor
(),
equals
(
defaultColor
));
// Focused.
focusNode
.
requestFocus
();
await
tester
.
pumpAndSettle
();
expect
(
iconColor
(),
focusedColor
);
// Hovered.
final
Offset
center
=
tester
.
getCenter
(
find
.
byKey
(
buttonKey
));
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
);
await
gesture
.
addPointer
();
addTearDown
(
gesture
.
removePointer
);
await
gesture
.
moveTo
(
center
);
await
tester
.
pumpAndSettle
();
expect
(
iconColor
(),
hoverColor
);
// Highlighted (pressed).
await
gesture
.
down
(
center
);
await
tester
.
pump
();
// Start the splash and highlight animations.
await
tester
.
pump
(
const
Duration
(
milliseconds:
800
));
// Wait for splash and highlight to be well under way.
expect
(
iconColor
(),
pressedColor
);
});
testWidgets
(
'RaisedButton ignores disabled text color if text color is stateful'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
const
Color
disabledColor
=
Color
(
0x00000001
);
const
Color
defaultColor
=
Color
(
0x00000002
);
const
Color
unusedDisabledTextColor
=
Color
(
0x00000003
);
Color
getTextColor
(
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
disabled
))
{
return
disabledColor
;
}
return
defaultColor
;
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
RaisedButton
(
onPressed:
null
,
focusNode:
focusNode
,
textColor:
MaterialStateColor
.
resolveWith
(
getTextColor
),
disabledTextColor:
unusedDisabledTextColor
,
child:
const
Text
(
'RaisedButton'
),
),
),
),
),
);
Color
textColor
()
{
return
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'RaisedButton'
)).
text
.
style
!.
color
!;
}
// Disabled.
expect
(
textColor
(),
equals
(
disabledColor
));
expect
(
textColor
(),
isNot
(
unusedDisabledTextColor
));
});
testWidgets
(
'RaisedButton onPressed and onLongPress callbacks are correctly called when non-null'
,
(
WidgetTester
tester
)
async
{
bool
wasPressed
;
Finder
raisedButton
;
Widget
buildFrame
({
VoidCallback
?
onPressed
,
VoidCallback
?
onLongPress
})
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
onPressed
,
onLongPress:
onLongPress
,
child:
const
Text
(
'button'
),
),
);
}
// onPressed not null, onLongPress null.
wasPressed
=
false
;
await
tester
.
pumpWidget
(
buildFrame
(
onPressed:
()
{
wasPressed
=
true
;
}),
);
raisedButton
=
find
.
byType
(
RaisedButton
);
expect
(
tester
.
widget
<
RaisedButton
>(
raisedButton
).
enabled
,
true
);
await
tester
.
tap
(
raisedButton
);
expect
(
wasPressed
,
true
);
// onPressed null, onLongPress not null.
wasPressed
=
false
;
await
tester
.
pumpWidget
(
buildFrame
(
onLongPress:
()
{
wasPressed
=
true
;
}),
);
raisedButton
=
find
.
byType
(
RaisedButton
);
expect
(
tester
.
widget
<
RaisedButton
>(
raisedButton
).
enabled
,
true
);
await
tester
.
longPress
(
raisedButton
);
expect
(
wasPressed
,
true
);
// onPressed null, onLongPress null.
await
tester
.
pumpWidget
(
buildFrame
(),
);
raisedButton
=
find
.
byType
(
RaisedButton
);
expect
(
tester
.
widget
<
RaisedButton
>(
raisedButton
).
enabled
,
false
);
});
testWidgets
(
'RaisedButton onPressed and onLongPress callbacks are distinctly recognized'
,
(
WidgetTester
tester
)
async
{
bool
didPressButton
=
false
;
bool
didLongPressButton
=
false
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
()
{
didPressButton
=
true
;
},
onLongPress:
()
{
didLongPressButton
=
true
;
},
child:
const
Text
(
'button'
),
),
),
);
final
Finder
raisedButton
=
find
.
byType
(
RaisedButton
);
expect
(
tester
.
widget
<
RaisedButton
>(
raisedButton
).
enabled
,
true
);
expect
(
didPressButton
,
isFalse
);
await
tester
.
tap
(
raisedButton
);
expect
(
didPressButton
,
isTrue
);
expect
(
didLongPressButton
,
isFalse
);
await
tester
.
longPress
(
raisedButton
);
expect
(
didLongPressButton
,
isTrue
);
});
testWidgets
(
'Does RaisedButton work with hover'
,
(
WidgetTester
tester
)
async
{
const
Color
hoverColor
=
Color
(
0xff001122
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
hoverColor:
hoverColor
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
);
await
gesture
.
addPointer
();
await
gesture
.
moveTo
(
tester
.
getCenter
(
find
.
byType
(
RaisedButton
)));
await
tester
.
pumpAndSettle
();
final
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
hoverColor
));
await
gesture
.
removePointer
();
});
testWidgets
(
'RaisedButton changes mouse cursor when hovered'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MouseRegion
(
cursor:
SystemMouseCursors
.
forbidden
,
child:
RaisedButton
.
icon
(
icon:
const
Icon
(
Icons
.
add
),
label:
const
Text
(
'Hello'
),
onPressed:
()
{},
mouseCursor:
SystemMouseCursors
.
text
,
),
),
),
);
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
pointer:
1
);
await
gesture
.
addPointer
(
location:
const
Offset
(
1
,
1
));
addTearDown
(
gesture
.
removePointer
);
await
tester
.
pump
();
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
text
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MouseRegion
(
cursor:
SystemMouseCursors
.
forbidden
,
child:
RaisedButton
(
onPressed:
()
{},
mouseCursor:
SystemMouseCursors
.
text
,
),
),
),
);
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
text
);
// Test default cursor
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MouseRegion
(
cursor:
SystemMouseCursors
.
forbidden
,
child:
RaisedButton
(
onPressed:
()
{},
),
),
),
);
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
click
);
// Test default cursor when disabled
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MouseRegion
(
cursor:
SystemMouseCursors
.
forbidden
,
child:
RaisedButton
(
onPressed:
null
,
),
),
),
);
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
});
testWidgets
(
'Does RaisedButton work with focus'
,
(
WidgetTester
tester
)
async
{
const
Color
focusColor
=
Color
(
0xff001122
);
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'RaisedButton Node'
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
focusColor:
focusColor
,
focusNode:
focusNode
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
FocusManager
.
instance
.
highlightStrategy
=
FocusHighlightStrategy
.
alwaysTraditional
;
focusNode
.
requestFocus
();
await
tester
.
pumpAndSettle
();
final
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
focusColor
));
});
testWidgets
(
'Does RaisedButton contribute semantics'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
RaisedButton
(
onPressed:
()
{
},
child:
const
Text
(
'ABC'
),
),
),
),
);
expect
(
semantics
,
hasSemantics
(
TestSemantics
.
root
(
children:
<
TestSemantics
>[
TestSemantics
.
rootChild
(
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
,
],
label:
'ABC'
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
88.0
,
48.0
),
transform:
Matrix4
.
translationValues
(
356.0
,
276.0
,
0.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
hasEnabledState
,
SemanticsFlag
.
isButton
,
SemanticsFlag
.
isEnabled
,
SemanticsFlag
.
isFocusable
,
],
),
],
),
ignoreId:
true
,
));
semantics
.
dispose
();
});
testWidgets
(
'RaisedButton size is configurable by ThemeData.materialTapTargetSize'
,
(
WidgetTester
tester
)
async
{
final
Key
key1
=
UniqueKey
();
await
tester
.
pumpWidget
(
Theme
(
data:
ThemeData
(
materialTapTargetSize:
MaterialTapTargetSize
.
padded
),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
RaisedButton
(
key:
key1
,
child:
const
SizedBox
(
width:
50.0
,
height:
8.0
),
onPressed:
()
{
},
),
),
),
),
);
expect
(
tester
.
getSize
(
find
.
byKey
(
key1
)),
const
Size
(
88.0
,
48.0
));
final
Key
key2
=
UniqueKey
();
await
tester
.
pumpWidget
(
Theme
(
data:
ThemeData
(
materialTapTargetSize:
MaterialTapTargetSize
.
shrinkWrap
),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
RaisedButton
(
key:
key2
,
child:
const
SizedBox
(
width:
50.0
,
height:
8.0
),
onPressed:
()
{
},
),
),
),
),
);
expect
(
tester
.
getSize
(
find
.
byKey
(
key2
)),
const
Size
(
88.0
,
36.0
));
});
testWidgets
(
'RaisedButton has no clip by default'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
()
{
/* to make sure the button is enabled */
},
),
),
);
expect
(
tester
.
renderObject
(
find
.
byType
(
RaisedButton
)),
paintsExactlyCountTimes
(
#clipPath
,
0
),
);
});
testWidgets
(
'RaisedButton responds to density changes.'
,
(
WidgetTester
tester
)
async
{
const
Key
key
=
Key
(
'test'
);
const
Key
childKey
=
Key
(
'test child'
);
Future
<
void
>
buildTest
(
VisualDensity
visualDensity
,
{
bool
useText
=
false
})
async
{
return
tester
.
pumpWidget
(
MaterialApp
(
home:
Directionality
(
textDirection:
TextDirection
.
rtl
,
child:
Center
(
child:
RaisedButton
(
visualDensity:
visualDensity
,
key:
key
,
onPressed:
()
{},
child:
useText
?
const
Text
(
'Text'
,
key:
childKey
)
:
Container
(
key:
childKey
,
width:
100
,
height:
100
,
color:
const
Color
(
0xffff0000
)),
),
),
),
),
);
}
await
buildTest
(
VisualDensity
.
standard
);
final
RenderBox
box
=
tester
.
renderObject
(
find
.
byKey
(
key
));
Rect
childRect
=
tester
.
getRect
(
find
.
byKey
(
childKey
));
await
tester
.
pumpAndSettle
();
expect
(
box
.
size
,
equals
(
const
Size
(
132
,
100
)));
expect
(
childRect
,
equals
(
const
Rect
.
fromLTRB
(
350
,
250
,
450
,
350
)));
await
buildTest
(
const
VisualDensity
(
horizontal:
3.0
,
vertical:
3.0
));
await
tester
.
pumpAndSettle
();
childRect
=
tester
.
getRect
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
156
,
124
)));
expect
(
childRect
,
equals
(
const
Rect
.
fromLTRB
(
350
,
250
,
450
,
350
)));
await
buildTest
(
const
VisualDensity
(
horizontal:
-
3.0
,
vertical:
-
3.0
));
await
tester
.
pumpAndSettle
();
childRect
=
tester
.
getRect
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
108
,
100
)));
expect
(
childRect
,
equals
(
const
Rect
.
fromLTRB
(
350
,
250
,
450
,
350
)));
await
buildTest
(
VisualDensity
.
standard
,
useText:
true
);
await
tester
.
pumpAndSettle
();
childRect
=
tester
.
getRect
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
88
,
48
)));
expect
(
childRect
,
equals
(
const
Rect
.
fromLTRB
(
372.0
,
293.0
,
428.0
,
307.0
)));
await
buildTest
(
const
VisualDensity
(
horizontal:
3.0
,
vertical:
3.0
),
useText:
true
);
await
tester
.
pumpAndSettle
();
childRect
=
tester
.
getRect
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
112
,
60
)));
expect
(
childRect
,
equals
(
const
Rect
.
fromLTRB
(
372.0
,
293.0
,
428.0
,
307.0
)));
await
buildTest
(
const
VisualDensity
(
horizontal:
-
3.0
,
vertical:
-
3.0
),
useText:
true
);
await
tester
.
pumpAndSettle
();
childRect
=
tester
.
getRect
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
76
,
36
)));
expect
(
childRect
,
equals
(
const
Rect
.
fromLTRB
(
372.0
,
293.0
,
428.0
,
307.0
)));
});
testWidgets
(
'RaisedButton.icon responds to applied padding'
,
(
WidgetTester
tester
)
async
{
const
Key
buttonKey
=
Key
(
'test'
);
const
Key
labelKey
=
Key
(
'label'
);
await
tester
.
pumpWidget
(
// When textDirection is set to TextDirection.ltr, the label appears on the
// right side of the icon. This is important in determining whether the
// horizontal padding is applied correctly later on
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
RaisedButton
.
icon
(
icon:
const
Icon
(
Icons
.
add
),
padding:
const
EdgeInsets
.
fromLTRB
(
16
,
5
,
10
,
12
),
key:
buttonKey
,
onPressed:
()
{},
label:
const
Text
(
'Hello'
,
key:
labelKey
,
),
),
),
),
);
final
Rect
paddingRect
=
tester
.
getRect
(
find
.
byType
(
Padding
));
final
Rect
labelRect
=
tester
.
getRect
(
find
.
byKey
(
labelKey
));
final
Rect
iconRect
=
tester
.
getRect
(
find
.
byType
(
Icon
));
// The right padding should be applied on the right of the label, whereas the
// left padding should be applied on the left side of the icon.
expect
(
paddingRect
.
right
,
labelRect
.
right
+
10
);
expect
(
paddingRect
.
left
,
iconRect
.
left
-
16
);
// Use the taller widget to check the top and bottom padding.
final
Rect
tallerWidget
=
iconRect
.
height
>
labelRect
.
height
?
iconRect
:
labelRect
;
expect
(
paddingRect
.
top
,
tallerWidget
.
top
-
5
);
expect
(
paddingRect
.
bottom
,
tallerWidget
.
bottom
+
12
);
});
}
TextStyle
_iconStyle
(
WidgetTester
tester
,
IconData
icon
)
{
final
RichText
iconRichText
=
tester
.
widget
<
RichText
>(
find
.
descendant
(
of:
find
.
byIcon
(
icon
),
matching:
find
.
byType
(
RichText
)),
);
return
iconRichText
.
text
.
style
!;
}
packages/flutter/test/material/text_field_test.dart
View file @
afe6c2e7
...
...
@@ -10364,11 +10364,11 @@ void main() {
onTap:
()
{
textFieldTapCount
+=
1
;
},
decoration:
InputDecoration
(
labelText:
'Label'
,
prefix:
Rais
edButton
(
prefix:
Elevat
edButton
(
onPressed:
()
{
prefixTapCount
+=
1
;
},
child:
const
Text
(
'prefix'
),
),
suffix:
Rais
edButton
(
suffix:
Elevat
edButton
(
onPressed:
()
{
suffixTapCount
+=
1
;
},
child:
const
Text
(
'suffix'
),
),
...
...
packages/flutter/test/material/theme_defaults_test.dart
View file @
afe6c2e7
...
...
@@ -11,64 +11,6 @@ const BoxConstraints defaultButtonConstraints = BoxConstraints(minWidth: 88.0, m
const
Duration
defaultButtonDuration
=
Duration
(
milliseconds:
200
);
void
main
(
)
{
group
(
'RaisedButton'
,
()
{
testWidgets
(
'theme: ThemeData.light(), enabled: true'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
light
(),
home:
Center
(
child:
RaisedButton
(
onPressed:
()
{
},
// button.enabled == true
child:
const
Text
(
'button'
),
),
),
),
);
final
RawMaterialButton
raw
=
tester
.
widget
<
RawMaterialButton
>(
find
.
byType
(
RawMaterialButton
));
expect
(
raw
.
textStyle
!.
color
,
const
Color
(
0xdd000000
));
expect
(
raw
.
fillColor
,
const
Color
(
0xffe0e0e0
));
expect
(
raw
.
highlightColor
,
const
Color
(
0x29000000
));
// Was Color(0x66bcbcbc)
expect
(
raw
.
splashColor
,
const
Color
(
0x1f000000
));
// Was Color(0x66c8c8c8)
expect
(
raw
.
elevation
,
2.0
);
expect
(
raw
.
highlightElevation
,
8.0
);
expect
(
raw
.
disabledElevation
,
0.0
);
expect
(
raw
.
constraints
,
defaultButtonConstraints
);
expect
(
raw
.
padding
,
defaultButtonPadding
);
expect
(
raw
.
shape
,
defaultButtonShape
);
expect
(
raw
.
animationDuration
,
defaultButtonDuration
);
expect
(
raw
.
materialTapTargetSize
,
MaterialTapTargetSize
.
padded
);
});
testWidgets
(
'theme: ThemeData.light(), enabled: false'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
light
(),
home:
const
Center
(
child:
RaisedButton
(
onPressed:
null
,
// button.enabled == false
child:
Text
(
'button'
),
),
),
),
);
final
RawMaterialButton
raw
=
tester
.
widget
<
RawMaterialButton
>(
find
.
byType
(
RawMaterialButton
));
expect
(
raw
.
textStyle
!.
color
,
const
Color
(
0x61000000
));
expect
(
raw
.
fillColor
,
const
Color
(
0x61000000
));
// highlightColor, disabled button can't be pressed
// splashColor, disabled button doesn't splash
expect
(
raw
.
elevation
,
2.0
);
expect
(
raw
.
highlightElevation
,
8.0
);
expect
(
raw
.
disabledElevation
,
0.0
);
expect
(
raw
.
constraints
,
defaultButtonConstraints
);
expect
(
raw
.
padding
,
defaultButtonPadding
);
expect
(
raw
.
shape
,
defaultButtonShape
);
expect
(
raw
.
animationDuration
,
defaultButtonDuration
);
expect
(
raw
.
materialTapTargetSize
,
MaterialTapTargetSize
.
padded
);
});
});
group
(
'FlatButton'
,
()
{
testWidgets
(
'theme: ThemeData.light(), enabled: true'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
...
...
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