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
2b85eeed
Unverified
Commit
2b85eeed
authored
Dec 01, 2020
by
xubaolin
Committed by
GitHub
Dec 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let SnackBar inherit themeData from its ancestor (#70080)
parent
3217906e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
8 deletions
+151
-8
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+3
-6
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+146
-0
text_selection_theme_test.dart
...ages/flutter/test/material/text_selection_theme_test.dart
+2
-2
No files found.
packages/flutter/lib/src/material/snack_bar.dart
View file @
2b85eeed
...
...
@@ -460,9 +460,7 @@ class _SnackBarState extends State<SnackBar> {
final
Color
themeBackgroundColor
=
isThemeDark
?
colorScheme
.
onSurface
:
Color
.
alphaBlend
(
colorScheme
.
onSurface
.
withOpacity
(
0.80
),
colorScheme
.
surface
);
final
ThemeData
inverseTheme
=
ThemeData
(
brightness:
brightness
,
backgroundColor:
themeBackgroundColor
,
final
ThemeData
inverseTheme
=
theme
.
copyWith
(
colorScheme:
ColorScheme
(
primary:
colorScheme
.
onPrimary
,
primaryVariant:
colorScheme
.
onPrimary
,
...
...
@@ -480,10 +478,9 @@ class _SnackBarState extends State<SnackBar> {
onError:
colorScheme
.
error
,
brightness:
brightness
,
),
snackBarTheme:
snackBarTheme
,
);
final
TextStyle
?
contentTextStyle
=
snackBarTheme
.
contentTextStyle
??
inverseTheme
.
textTheme
.
subtitle1
;
final
TextStyle
?
contentTextStyle
=
snackBarTheme
.
contentTextStyle
??
ThemeData
(
brightness:
brightness
)
.
textTheme
.
subtitle1
;
final
SnackBarBehavior
snackBarBehavior
=
widget
.
behavior
??
snackBarTheme
.
behavior
??
SnackBarBehavior
.
fixed
;
final
bool
isFloatingSnackBar
=
snackBarBehavior
==
SnackBarBehavior
.
floating
;
final
double
horizontalPadding
=
isFloatingSnackBar
?
16.0
:
24.0
;
...
...
@@ -539,7 +536,7 @@ class _SnackBarState extends State<SnackBar> {
}
final
double
elevation
=
widget
.
elevation
??
snackBarTheme
.
elevation
??
6.0
;
final
Color
backgroundColor
=
widget
.
backgroundColor
??
snackBarTheme
.
backgroundColor
??
inverseTheme
.
backgroundColor
;
final
Color
backgroundColor
=
widget
.
backgroundColor
??
snackBarTheme
.
backgroundColor
??
inverseTheme
.
colorScheme
.
background
;
final
ShapeBorder
?
shape
=
widget
.
shape
??
snackBarTheme
.
shape
??
(
isFloatingSnackBar
?
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
4.0
))
:
null
);
...
...
packages/flutter/test/material/snack_bar_test.dart
View file @
2b85eeed
...
...
@@ -669,6 +669,152 @@ void main() {
expect
(
renderModel
.
color
,
equals
(
darkTheme
.
colorScheme
.
onSurface
));
});
testWidgets
(
'SnackBar should inherit theme data from its ancestor.'
,
(
WidgetTester
tester
)
async
{
final
SliderThemeData
sliderTheme
=
SliderThemeData
.
fromPrimaryColors
(
primaryColor:
Colors
.
black
,
primaryColorDark:
Colors
.
black
,
primaryColorLight:
Colors
.
black
,
valueIndicatorTextStyle:
const
TextStyle
(
color:
Colors
.
black
),
);
final
ChipThemeData
chipTheme
=
ChipThemeData
.
fromDefaults
(
primaryColor:
Colors
.
black
,
secondaryColor:
Colors
.
white
,
labelStyle:
const
TextStyle
(
color:
Colors
.
black
),
);
const
PageTransitionsTheme
pageTransitionTheme
=
PageTransitionsTheme
(
builders:
<
TargetPlatform
,
PageTransitionsBuilder
>{
TargetPlatform
.
iOS
:
CupertinoPageTransitionsBuilder
(),
TargetPlatform
.
macOS
:
CupertinoPageTransitionsBuilder
(),
},
);
final
ThemeData
theme
=
ThemeData
.
raw
(
visualDensity:
const
VisualDensity
(),
primaryColor:
Colors
.
black
,
primaryColorBrightness:
Brightness
.
dark
,
primaryColorLight:
Colors
.
black
,
primaryColorDark:
Colors
.
black
,
accentColor:
Colors
.
black
,
accentColorBrightness:
Brightness
.
dark
,
canvasColor:
Colors
.
black
,
shadowColor:
Colors
.
black
,
scaffoldBackgroundColor:
Colors
.
black
,
bottomAppBarColor:
Colors
.
black
,
cardColor:
Colors
.
black
,
dividerColor:
Colors
.
black
,
focusColor:
Colors
.
black
,
hoverColor:
Colors
.
black
,
highlightColor:
Colors
.
black
,
splashColor:
Colors
.
black
,
splashFactory:
InkRipple
.
splashFactory
,
selectedRowColor:
Colors
.
black
,
unselectedWidgetColor:
Colors
.
black
,
disabledColor:
Colors
.
black
,
buttonTheme:
const
ButtonThemeData
(
colorScheme:
ColorScheme
.
dark
()),
toggleButtonsTheme:
const
ToggleButtonsThemeData
(
textStyle:
TextStyle
(
color:
Colors
.
black
)),
buttonColor:
Colors
.
black
,
secondaryHeaderColor:
Colors
.
black
,
textSelectionColor:
Colors
.
black
,
cursorColor:
Colors
.
black
,
textSelectionHandleColor:
Colors
.
black
,
backgroundColor:
Colors
.
black
,
dialogBackgroundColor:
Colors
.
black
,
indicatorColor:
Colors
.
black
,
hintColor:
Colors
.
black
,
errorColor:
Colors
.
black
,
toggleableActiveColor:
Colors
.
black
,
textTheme:
ThemeData
.
dark
().
textTheme
,
primaryTextTheme:
ThemeData
.
dark
().
textTheme
,
accentTextTheme:
ThemeData
.
dark
().
textTheme
,
inputDecorationTheme:
ThemeData
.
dark
().
inputDecorationTheme
.
copyWith
(
border:
const
OutlineInputBorder
()),
iconTheme:
ThemeData
.
dark
().
iconTheme
,
primaryIconTheme:
ThemeData
.
dark
().
iconTheme
,
accentIconTheme:
ThemeData
.
dark
().
iconTheme
,
sliderTheme:
sliderTheme
,
tabBarTheme:
const
TabBarTheme
(
labelColor:
Colors
.
black
),
tooltipTheme:
const
TooltipThemeData
(
height:
100
),
cardTheme:
const
CardTheme
(
color:
Colors
.
black
),
chipTheme:
chipTheme
,
platform:
TargetPlatform
.
iOS
,
materialTapTargetSize:
MaterialTapTargetSize
.
shrinkWrap
,
applyElevationOverlayColor:
false
,
pageTransitionsTheme:
pageTransitionTheme
,
appBarTheme:
const
AppBarTheme
(
color:
Colors
.
black
),
bottomAppBarTheme:
const
BottomAppBarTheme
(
color:
Colors
.
black
),
colorScheme:
const
ColorScheme
.
light
(),
dialogTheme:
const
DialogTheme
(
backgroundColor:
Colors
.
black
),
floatingActionButtonTheme:
const
FloatingActionButtonThemeData
(
backgroundColor:
Colors
.
black
),
navigationRailTheme:
const
NavigationRailThemeData
(
backgroundColor:
Colors
.
black
),
typography:
Typography
.
material2018
(
platform:
TargetPlatform
.
android
),
cupertinoOverrideTheme:
null
,
snackBarTheme:
const
SnackBarThemeData
(
backgroundColor:
Colors
.
black
),
bottomSheetTheme:
const
BottomSheetThemeData
(
backgroundColor:
Colors
.
black
),
popupMenuTheme:
const
PopupMenuThemeData
(
color:
Colors
.
black
),
bannerTheme:
const
MaterialBannerThemeData
(
backgroundColor:
Colors
.
black
),
dividerTheme:
const
DividerThemeData
(
color:
Colors
.
black
),
buttonBarTheme:
const
ButtonBarThemeData
(
alignment:
MainAxisAlignment
.
start
),
bottomNavigationBarTheme:
const
BottomNavigationBarThemeData
(
type:
BottomNavigationBarType
.
fixed
),
timePickerTheme:
const
TimePickerThemeData
(
backgroundColor:
Colors
.
black
),
textButtonTheme:
TextButtonThemeData
(
style:
TextButton
.
styleFrom
(
primary:
Colors
.
red
)),
elevatedButtonTheme:
ElevatedButtonThemeData
(
style:
ElevatedButton
.
styleFrom
(
primary:
Colors
.
green
)),
outlinedButtonTheme:
OutlinedButtonThemeData
(
style:
OutlinedButton
.
styleFrom
(
primary:
Colors
.
blue
)),
textSelectionTheme:
const
TextSelectionThemeData
(
cursorColor:
Colors
.
black
),
dataTableTheme:
const
DataTableThemeData
(),
checkboxTheme:
const
CheckboxThemeData
(),
radioTheme:
const
RadioThemeData
(),
switchTheme:
const
SwitchThemeData
(),
fixTextFieldOutlineLabel:
false
,
useTextSelectionTheme:
false
,
);
ThemeData
?
themeBeforeSnackBar
;
ThemeData
?
themeAfterSnackBar
;
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
theme
,
home:
Scaffold
(
body:
Builder
(
builder:
(
BuildContext
context
)
{
themeBeforeSnackBar
=
Theme
.
of
(
context
);
return
GestureDetector
(
onTap:
()
{
Scaffold
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Builder
(
builder:
(
BuildContext
context
)
{
themeAfterSnackBar
=
Theme
.
of
(
context
);
return
const
Text
(
'I am a snack bar.'
);
},
),
duration:
const
Duration
(
seconds:
2
),
action:
SnackBarAction
(
label:
'ACTION'
,
onPressed:
()
{
},
),
),
);
},
child:
const
Text
(
'X'
),
);
},
),
),
),
);
await
tester
.
tap
(
find
.
text
(
'X'
));
await
tester
.
pump
();
// start animation
await
tester
.
pump
(
const
Duration
(
milliseconds:
750
));
final
ThemeData
comparedTheme
=
themeBeforeSnackBar
!.
copyWith
(
colorScheme:
themeAfterSnackBar
!.
colorScheme
,
);
// Fields replaced by SnackBar.
expect
(
comparedTheme
,
themeAfterSnackBar
);
});
testWidgets
(
'Snackbar margin can be customized'
,
(
WidgetTester
tester
)
async
{
const
double
padding
=
20.0
;
await
tester
.
pumpWidget
(
...
...
packages/flutter/test/material/text_selection_theme_test.dart
View file @
2b85eeed
...
...
@@ -93,7 +93,7 @@ void main() {
expect
(
handle
,
paints
..
path
(
color:
defaultSelectionHandleColor
));
});
testWidgets
(
'ThemeDat
e
.textSelectionTheme will be used if provided'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'ThemeDat
a
.textSelectionTheme will be used if provided'
,
(
WidgetTester
tester
)
async
{
const
TextSelectionThemeData
textSelectionTheme
=
TextSelectionThemeData
(
cursorColor:
Color
(
0xffaabbcc
),
selectionColor:
Color
(
0x88888888
),
...
...
@@ -138,7 +138,7 @@ void main() {
expect
(
handle
,
paints
..
path
(
color:
textSelectionTheme
.
selectionHandleColor
));
});
testWidgets
(
'TextSelectionTheme widget will override ThemeDat
e
.textSelectionTheme'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'TextSelectionTheme widget will override ThemeDat
a
.textSelectionTheme'
,
(
WidgetTester
tester
)
async
{
const
TextSelectionThemeData
defaultTextSelectionTheme
=
TextSelectionThemeData
(
cursorColor:
Color
(
0xffaabbcc
),
selectionColor:
Color
(
0x88888888
),
...
...
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