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
19899db2
Commit
19899db2
authored
Oct 14, 2019
by
Keshava Muraari
Committed by
Shi-Hao Hong
Oct 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default colorScheme data in ButtonThemeData (Fix for #38655) (#39627)
* Set default colorScheme for ButtonThemeData
parent
dee75839
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
12 deletions
+92
-12
button_theme.dart
packages/flutter/lib/src/material/button_theme.dart
+11
-10
button_theme_test.dart
packages/flutter/test/material/button_theme_test.dart
+81
-2
No files found.
packages/flutter/lib/src/material/button_theme.dart
View file @
19899db2
...
...
@@ -83,7 +83,7 @@ class ButtonTheme extends InheritedTheme {
Color
hoverColor
,
Color
highlightColor
,
Color
splashColor
,
ColorScheme
colorScheme
,
ColorScheme
colorScheme
=
const
ColorScheme
.
light
()
,
MaterialTapTargetSize
materialTapTargetSize
,
Widget
child
,
})
:
assert
(
textTheme
!=
null
),
...
...
@@ -91,6 +91,7 @@ class ButtonTheme extends InheritedTheme {
assert
(
height
!=
null
&&
height
>=
0.0
),
assert
(
alignedDropdown
!=
null
),
assert
(
layoutBehavior
!=
null
),
assert
(
colorScheme
!=
null
),
data
=
ButtonThemeData
(
textTheme:
textTheme
,
minWidth:
minWidth
,
...
...
@@ -179,13 +180,14 @@ class ButtonTheme extends InheritedTheme {
Color
hoverColor
,
Color
highlightColor
,
Color
splashColor
,
ColorScheme
colorScheme
,
ColorScheme
colorScheme
=
const
ColorScheme
.
light
()
,
Widget
child
,
ButtonBarLayoutBehavior
layoutBehavior
=
ButtonBarLayoutBehavior
.
padded
,
})
:
assert
(
textTheme
!=
null
),
assert
(
minWidth
!=
null
&&
minWidth
>=
0.0
),
assert
(
height
!=
null
&&
height
>=
0.0
),
assert
(
alignedDropdown
!=
null
),
assert
(
colorScheme
!=
null
),
data
=
ButtonThemeData
(
textTheme:
textTheme
,
minWidth:
minWidth
,
...
...
@@ -217,15 +219,13 @@ class ButtonTheme extends InheritedTheme {
static
ButtonThemeData
of
(
BuildContext
context
)
{
final
ButtonTheme
inheritedButtonTheme
=
context
.
inheritFromWidgetOfExactType
(
ButtonTheme
);
ButtonThemeData
buttonTheme
=
inheritedButtonTheme
?.
data
;
if
(
buttonTheme
?.
colorScheme
==
null
)
{
// if buttonTheme or buttonTheme.colorScheme is null
if
(
buttonTheme
==
null
)
{
final
ThemeData
theme
=
Theme
.
of
(
context
);
buttonTheme
??=
theme
.
buttonTheme
;
if
(
buttonTheme
.
colorScheme
==
null
)
{
buttonTheme
=
buttonTheme
.
copyWith
(
colorScheme:
theme
.
buttonTheme
.
colorScheme
??
theme
.
colorScheme
,
);
assert
(
buttonTheme
.
colorScheme
!=
null
);
}
buttonTheme
=
buttonTheme
.
copyWith
(
colorScheme:
theme
.
buttonTheme
.
colorScheme
??
const
ColorScheme
.
light
(),
);
assert
(
buttonTheme
.
colorScheme
!=
null
);
}
return
buttonTheme
;
}
...
...
@@ -270,13 +270,14 @@ class ButtonThemeData extends Diagnosticable {
Color
hoverColor
,
Color
highlightColor
,
Color
splashColor
,
this
.
colorScheme
,
this
.
colorScheme
=
const
ColorScheme
.
light
()
,
MaterialTapTargetSize
materialTapTargetSize
,
})
:
assert
(
textTheme
!=
null
),
assert
(
minWidth
!=
null
&&
minWidth
>=
0.0
),
assert
(
height
!=
null
&&
height
>=
0.0
),
assert
(
alignedDropdown
!=
null
),
assert
(
layoutBehavior
!=
null
),
assert
(
colorScheme
!=
null
),
_buttonColor
=
buttonColor
,
_disabledColor
=
disabledColor
,
_focusColor
=
focusColor
,
...
...
packages/flutter/test/material/button_theme_test.dart
View file @
19899db2
...
...
@@ -18,6 +18,7 @@ void main() {
));
expect
(
theme
.
alignedDropdown
,
false
);
expect
(
theme
.
layoutBehavior
,
ButtonBarLayoutBehavior
.
padded
);
expect
(
theme
.
colorScheme
,
const
ColorScheme
.
light
());
});
test
(
'ButtonThemeData default overrides'
,
()
{
...
...
@@ -28,12 +29,14 @@ void main() {
padding:
EdgeInsets
.
zero
,
shape:
RoundedRectangleBorder
(),
alignedDropdown:
true
,
colorScheme:
ColorScheme
.
dark
()
);
expect
(
theme
.
textTheme
,
ButtonTextTheme
.
primary
);
expect
(
theme
.
constraints
,
const
BoxConstraints
(
minWidth:
100.0
,
minHeight:
200.0
));
expect
(
theme
.
padding
,
EdgeInsets
.
zero
);
expect
(
theme
.
shape
,
const
RoundedRectangleBorder
());
expect
(
theme
.
alignedDropdown
,
true
);
expect
(
theme
.
colorScheme
,
const
ColorScheme
.
dark
());
});
testWidgets
(
'ButtonTheme defaults'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -80,7 +83,7 @@ void main() {
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
)),
));
expect
(
alignedDropdown
,
false
);
expect
(
colorScheme
,
ThemeData
.
light
().
colorScheme
);
expect
(
colorScheme
,
const
ColorScheme
.
light
()
);
expect
(
tester
.
widget
<
Material
>(
find
.
byType
(
Material
)).
shape
,
shape
);
expect
(
tester
.
getSize
(
find
.
byType
(
Material
)),
const
Size
(
88.0
,
36.0
));
});
...
...
@@ -95,7 +98,7 @@ void main() {
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
)),
));
expect
(
theme
.
alignedDropdown
,
false
);
expect
(
theme
.
colorScheme
,
null
);
expect
(
theme
.
colorScheme
,
const
ColorScheme
.
light
()
);
theme
=
const
ButtonThemeData
().
copyWith
(
textTheme:
ButtonTextTheme
.
primary
,
...
...
@@ -402,4 +405,80 @@ void main() {
},
semanticsEnabled:
true
,
);
testWidgets
(
'Default RaisedButton text color when textTheme is set to ButtonTextTheme.accent'
,
(
WidgetTester
tester
)
async
{
// Test for https://github.com/flutter/flutter/issues/38655
const
Color
defaultEnabledAccentTextColor
=
Color
(
0xff2196f3
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
RaisedButton
(
child:
const
Text
(
'RaisedButton'
),
onPressed:
()
{},
textTheme:
ButtonTextTheme
.
accent
,
),
),
),
),
);
Color
getRaisedButtonTextColor
()
{
return
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'RaisedButton'
)).
text
.
style
.
color
;
}
expect
(
getRaisedButtonTextColor
(),
equals
(
defaultEnabledAccentTextColor
));
});
testWidgets
(
'default button theme primary color for RaisedButton'
,
(
WidgetTester
tester
)
async
{
// Test for https://github.com/flutter/flutter/issues/38655
const
Color
defaultEnabledPrimaryTextColor
=
Color
(
0xff000000
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
RaisedButton
(
child:
const
Text
(
'RaisedButton'
),
onPressed:
()
{},
textTheme:
ButtonTextTheme
.
primary
,
),
),
),
),
);
Color
getRaisedButtonTextColor
()
{
return
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'RaisedButton'
)).
text
.
style
.
color
;
}
expect
(
getRaisedButtonTextColor
(),
equals
(
defaultEnabledPrimaryTextColor
));
});
testWidgets
(
'default button theme normal color for RaisedButton'
,
(
WidgetTester
tester
)
async
{
// Test for https://github.com/flutter/flutter/issues/38655
const
Color
defaultEnabledNormalTextColor
=
Color
(
0xffffffff
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
dark
(),
home:
Scaffold
(
body:
Center
(
child:
RaisedButton
(
child:
const
Text
(
'RaisedButton'
),
onPressed:
()
{},
textTheme:
ButtonTextTheme
.
normal
),
),
),
),
);
Color
getRaisedButtonTextColor
()
{
return
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'RaisedButton'
)).
text
.
style
.
color
;
}
expect
(
getRaisedButtonTextColor
(),
equals
(
defaultEnabledNormalTextColor
));
});
}
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