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
b56a8c56
Unverified
Commit
b56a8c56
authored
Sep 17, 2020
by
Hans Muller
Committed by
GitHub
Sep 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced reference to obsolete FlatButton button class in SnackBar (#65988)
parent
fb08acf1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
26 deletions
+36
-26
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+23
-13
snack_bar_theme_test.dart
packages/flutter/test/material/snack_bar_theme_test.dart
+13
-13
No files found.
packages/flutter/lib/src/material/snack_bar.dart
View file @
b56a8c56
...
...
@@ -7,12 +7,14 @@
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'button_
them
e.dart'
;
import
'button_
styl
e.dart'
;
import
'color_scheme.dart'
;
import
'flat_button.dart'
;
import
'material.dart'
;
import
'material_state.dart'
;
import
'scaffold.dart'
;
import
'snack_bar_theme.dart'
;
import
'text_button.dart'
;
import
'text_button_theme.dart'
;
import
'theme.dart'
;
import
'theme_data.dart'
;
...
...
@@ -128,15 +130,19 @@ class _SnackBarActionState extends State<SnackBarAction> {
@override
Widget
build
(
BuildContext
context
)
{
final
SnackBarThemeData
snackBarTheme
=
Theme
.
of
(
context
).
snackBarTheme
;
final
Color
textColor
=
widget
.
textColor
??
snackBarTheme
.
actionTextColor
;
final
Color
disabledTextColor
=
widget
.
disabledTextColor
??
snackBarTheme
.
disabledActionTextColor
;
Color
resolveForegroundColor
(
Set
<
MaterialState
>
states
)
{
final
SnackBarThemeData
snackBarTheme
=
Theme
.
of
(
context
).
snackBarTheme
;
if
(
states
.
contains
(
MaterialState
.
disabled
))
return
widget
.
disabledTextColor
??
snackBarTheme
.
disabledActionTextColor
;
return
widget
.
textColor
??
snackBarTheme
.
actionTextColor
;
}
return
FlatButton
(
return
TextButton
(
style:
ButtonStyle
(
foregroundColor:
MaterialStateProperty
.
resolveWith
<
Color
>(
resolveForegroundColor
),
),
onPressed:
_haveTriggeredAction
?
null
:
_handlePressed
,
child:
Text
(
widget
.
label
),
textColor:
textColor
,
disabledTextColor:
disabledTextColor
,
);
}
}
...
...
@@ -385,6 +391,7 @@ class _SnackBarState extends State<SnackBar> {
final
ColorScheme
colorScheme
=
theme
.
colorScheme
;
final
SnackBarThemeData
snackBarTheme
=
theme
.
snackBarTheme
;
final
bool
isThemeDark
=
theme
.
brightness
==
Brightness
.
dark
;
final
Color
buttonColor
=
isThemeDark
?
colorScheme
.
primaryVariant
:
colorScheme
.
secondary
;
// SnackBar uses a theme that is the opposite brightness from
// the surrounding theme.
...
...
@@ -400,7 +407,7 @@ class _SnackBarState extends State<SnackBar> {
primaryVariant:
colorScheme
.
onPrimary
,
// For the button color, the spec says it should be primaryVariant, but for
// backward compatibility on light themes we are leaving it as secondary.
secondary:
isThemeDark
?
colorScheme
.
primaryVariant
:
colorScheme
.
secondary
,
secondary:
buttonColor
,
secondaryVariant:
colorScheme
.
onSecondary
,
surface:
colorScheme
.
onSurface
,
background:
themeBackgroundColor
,
...
...
@@ -445,10 +452,13 @@ class _SnackBarState extends State<SnackBar> {
),
),
if
(
widget
.
action
!=
null
)
ButtonTheme
(
textTheme:
ButtonTextTheme
.
accent
,
minWidth:
64.0
,
padding:
EdgeInsets
.
symmetric
(
horizontal:
horizontalPadding
),
TextButtonTheme
(
data:
TextButtonThemeData
(
style:
TextButton
.
styleFrom
(
primary:
buttonColor
,
padding:
EdgeInsets
.
symmetric
(
horizontal:
horizontalPadding
),
),
),
child:
widget
.
action
,
),
],
...
...
packages/flutter/test/material/snack_bar_theme_test.dart
View file @
b56a8c56
...
...
@@ -101,6 +101,7 @@ void main() {
testWidgets
(
'SnackBar uses values from SnackBarThemeData'
,
(
WidgetTester
tester
)
async
{
const
String
text
=
'I am a snack bar.'
;
const
String
action
=
'ACTION'
;
final
SnackBarThemeData
snackBarTheme
=
_snackBarTheme
();
await
tester
.
pumpWidget
(
MaterialApp
(
...
...
@@ -113,7 +114,7 @@ void main() {
Scaffold
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
const
Text
(
text
),
duration:
const
Duration
(
seconds:
2
),
action:
SnackBarAction
(
label:
'ACTION'
,
onPressed:
()
{}),
action:
SnackBarAction
(
label:
action
,
onPressed:
()
{}),
));
},
child:
const
Text
(
'X'
),
...
...
@@ -128,20 +129,21 @@ void main() {
await
tester
.
pump
(
const
Duration
(
milliseconds:
750
));
final
Material
material
=
_getSnackBarMaterial
(
tester
);
final
R
awMaterialButton
button
=
_getSnackBarButton
(
tester
);
final
R
enderParagraph
button
=
_getSnackBarActionTextRenderObject
(
tester
,
action
);
final
RenderParagraph
content
=
_getSnackBarTextRenderObject
(
tester
,
text
);
expect
(
content
.
text
.
style
,
snackBarTheme
.
contentTextStyle
);
expect
(
material
.
color
,
snackBarTheme
.
backgroundColor
);
expect
(
material
.
elevation
,
snackBarTheme
.
elevation
);
expect
(
material
.
shape
,
snackBarTheme
.
shape
);
expect
(
button
.
text
S
tyle
.
color
,
snackBarTheme
.
actionTextColor
);
expect
(
button
.
text
.
s
tyle
.
color
,
snackBarTheme
.
actionTextColor
);
});
testWidgets
(
'SnackBar widget properties take priority over theme'
,
(
WidgetTester
tester
)
async
{
const
Color
backgroundColor
=
Colors
.
purple
;
const
Color
textColor
=
Colors
.
pink
;
const
double
elevation
=
7.0
;
const
String
action
=
'ACTION'
;
const
ShapeBorder
shape
=
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
9.0
)),
);
...
...
@@ -161,7 +163,7 @@ void main() {
duration:
const
Duration
(
seconds:
2
),
action:
SnackBarAction
(
textColor:
textColor
,
label:
'ACTION'
,
label:
action
,
onPressed:
()
{},
),
));
...
...
@@ -178,12 +180,12 @@ void main() {
await
tester
.
pump
(
const
Duration
(
milliseconds:
750
));
final
Material
material
=
_getSnackBarMaterial
(
tester
);
final
R
awMaterialButton
button
=
_getSnackBarButton
(
tester
);
final
R
enderParagraph
button
=
_getSnackBarActionTextRenderObject
(
tester
,
action
);
expect
(
material
.
color
,
backgroundColor
);
expect
(
material
.
elevation
,
elevation
);
expect
(
material
.
shape
,
shape
);
expect
(
button
.
text
S
tyle
.
color
,
textColor
);
expect
(
button
.
text
.
s
tyle
.
color
,
textColor
);
});
testWidgets
(
'SnackBar theme behavior is correct for floating'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -292,13 +294,11 @@ Material _getSnackBarMaterial(WidgetTester tester) {
);
}
RawMaterialButton
_getSnackBarButton
(
WidgetTester
tester
)
{
return
tester
.
widget
<
RawMaterialButton
>(
find
.
descendant
(
of:
find
.
byType
(
SnackBar
),
matching:
find
.
byType
(
RawMaterialButton
),
).
first
,
);
RenderParagraph
_getSnackBarActionTextRenderObject
(
WidgetTester
tester
,
String
text
)
{
return
tester
.
renderObject
(
find
.
descendant
(
of:
find
.
byType
(
TextButton
),
matching:
find
.
text
(
text
),
));
}
RenderParagraph
_getSnackBarTextRenderObject
(
WidgetTester
tester
,
String
text
)
{
...
...
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