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
2e10b46b
Unverified
Commit
2e10b46b
authored
Feb 03, 2022
by
Taha Tesser
Committed by
GitHub
Feb 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Local `CheckBoxTheme` not being inherited by `CheckBox` Widget (#97715)
parent
ab89ce28
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
13 deletions
+50
-13
checkbox.dart
packages/flutter/lib/src/material/checkbox.dart
+15
-13
checkbox_theme_test.dart
packages/flutter/test/material/checkbox_theme_test.dart
+35
-0
No files found.
packages/flutter/lib/src/material/checkbox.dart
View file @
2e10b46b
...
...
@@ -4,6 +4,7 @@
import
'package:flutter/widgets.dart'
;
import
'checkbox_theme.dart'
;
import
'constants.dart'
;
import
'debug.dart'
;
import
'material_state.dart'
;
...
...
@@ -403,11 +404,12 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, Togg
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
final
ThemeData
themeData
=
Theme
.
of
(
context
);
final
CheckboxThemeData
checkboxTheme
=
CheckboxTheme
.
of
(
context
);
final
MaterialTapTargetSize
effectiveMaterialTapTargetSize
=
widget
.
materialTapTargetSize
??
themeData
.
checkboxTheme
.
materialTapTargetSize
??
checkboxTheme
.
materialTapTargetSize
??
themeData
.
materialTapTargetSize
;
final
VisualDensity
effectiveVisualDensity
=
widget
.
visualDensity
??
themeData
.
checkboxTheme
.
visualDensity
??
checkboxTheme
.
visualDensity
??
themeData
.
visualDensity
;
Size
size
;
switch
(
effectiveMaterialTapTargetSize
)
{
...
...
@@ -422,7 +424,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, Togg
final
MaterialStateProperty
<
MouseCursor
>
effectiveMouseCursor
=
MaterialStateProperty
.
resolveWith
<
MouseCursor
>((
Set
<
MaterialState
>
states
)
{
return
MaterialStateProperty
.
resolveAs
<
MouseCursor
?>(
widget
.
mouseCursor
,
states
)
??
themeData
.
checkboxTheme
.
mouseCursor
?.
resolve
(
states
)
??
checkboxTheme
.
mouseCursor
?.
resolve
(
states
)
??
MaterialStateMouseCursor
.
clickable
.
resolve
(
states
);
});
...
...
@@ -432,37 +434,37 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, Togg
final
Set
<
MaterialState
>
inactiveStates
=
states
..
remove
(
MaterialState
.
selected
);
final
Color
effectiveActiveColor
=
widget
.
fillColor
?.
resolve
(
activeStates
)
??
_widgetFillColor
.
resolve
(
activeStates
)
??
themeData
.
checkboxTheme
.
fillColor
?.
resolve
(
activeStates
)
??
checkboxTheme
.
fillColor
?.
resolve
(
activeStates
)
??
_defaultFillColor
.
resolve
(
activeStates
);
final
Color
effectiveInactiveColor
=
widget
.
fillColor
?.
resolve
(
inactiveStates
)
??
_widgetFillColor
.
resolve
(
inactiveStates
)
??
themeData
.
checkboxTheme
.
fillColor
?.
resolve
(
inactiveStates
)
??
checkboxTheme
.
fillColor
?.
resolve
(
inactiveStates
)
??
_defaultFillColor
.
resolve
(
inactiveStates
);
final
Set
<
MaterialState
>
focusedStates
=
states
..
add
(
MaterialState
.
focused
);
final
Color
effectiveFocusOverlayColor
=
widget
.
overlayColor
?.
resolve
(
focusedStates
)
??
widget
.
focusColor
??
themeData
.
checkboxTheme
.
overlayColor
?.
resolve
(
focusedStates
)
??
checkboxTheme
.
overlayColor
?.
resolve
(
focusedStates
)
??
themeData
.
focusColor
;
final
Set
<
MaterialState
>
hoveredStates
=
states
..
add
(
MaterialState
.
hovered
);
final
Color
effectiveHoverOverlayColor
=
widget
.
overlayColor
?.
resolve
(
hoveredStates
)
??
widget
.
hoverColor
??
themeData
.
checkboxTheme
.
overlayColor
?.
resolve
(
hoveredStates
)
??
checkboxTheme
.
overlayColor
?.
resolve
(
hoveredStates
)
??
themeData
.
hoverColor
;
final
Set
<
MaterialState
>
activePressedStates
=
activeStates
..
add
(
MaterialState
.
pressed
);
final
Color
effectiveActivePressedOverlayColor
=
widget
.
overlayColor
?.
resolve
(
activePressedStates
)
??
themeData
.
checkboxTheme
.
overlayColor
?.
resolve
(
activePressedStates
)
??
checkboxTheme
.
overlayColor
?.
resolve
(
activePressedStates
)
??
effectiveActiveColor
.
withAlpha
(
kRadialReactionAlpha
);
final
Set
<
MaterialState
>
inactivePressedStates
=
inactiveStates
..
add
(
MaterialState
.
pressed
);
final
Color
effectiveInactivePressedOverlayColor
=
widget
.
overlayColor
?.
resolve
(
inactivePressedStates
)
??
themeData
.
checkboxTheme
.
overlayColor
?.
resolve
(
inactivePressedStates
)
??
checkboxTheme
.
overlayColor
?.
resolve
(
inactivePressedStates
)
??
effectiveActiveColor
.
withAlpha
(
kRadialReactionAlpha
);
final
Color
effectiveCheckColor
=
widget
.
checkColor
??
themeData
.
checkboxTheme
.
checkColor
?.
resolve
(
states
)
??
checkboxTheme
.
checkColor
?.
resolve
(
states
)
??
const
Color
(
0xFFFFFFFF
);
return
Semantics
(
...
...
@@ -481,7 +483,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, Togg
..
reactionColor
=
effectiveActivePressedOverlayColor
..
hoverColor
=
effectiveHoverOverlayColor
..
focusColor
=
effectiveFocusOverlayColor
..
splashRadius
=
widget
.
splashRadius
??
themeData
.
checkboxTheme
.
splashRadius
??
kRadialReactionRadius
..
splashRadius
=
widget
.
splashRadius
??
checkboxTheme
.
splashRadius
??
kRadialReactionRadius
..
downPosition
=
downPosition
..
isFocused
=
states
.
contains
(
MaterialState
.
focused
)
..
isHovered
=
states
.
contains
(
MaterialState
.
hovered
)
...
...
@@ -490,10 +492,10 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, Togg
..
checkColor
=
effectiveCheckColor
..
value
=
value
..
previousValue
=
_previousValue
..
shape
=
widget
.
shape
??
themeData
.
checkboxTheme
.
shape
??
const
RoundedRectangleBorder
(
..
shape
=
widget
.
shape
??
checkboxTheme
.
shape
??
const
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
1.0
)),
)
..
side
=
_resolveSide
(
widget
.
side
)
??
_resolveSide
(
themeData
.
checkboxTheme
.
side
),
..
side
=
_resolveSide
(
widget
.
side
)
??
_resolveSide
(
checkboxTheme
.
side
),
),
);
}
...
...
packages/flutter/test/material/checkbox_theme_test.dart
View file @
2e10b46b
...
...
@@ -351,6 +351,41 @@ void main() {
reason:
'Active pressed Checkbox should have overlay color:
$activePressedOverlayColor
'
,
);
});
testWidgets
(
'Local CheckboxTheme can override global CheckboxTheme'
,
(
WidgetTester
tester
)
async
{
const
Color
globalThemeFillColor
=
Color
(
0xfffffff1
);
const
Color
globalThemeCheckColor
=
Color
(
0xff000000
);
const
Color
localThemeFillColor
=
Color
(
0xffff0000
);
const
Color
localThemeCheckColor
=
Color
(
0xffffffff
);
Widget
buildCheckbox
({
required
bool
active
})
{
return
MaterialApp
(
theme:
ThemeData
(
checkboxTheme:
CheckboxThemeData
(
checkColor:
MaterialStateProperty
.
all
<
Color
>(
globalThemeCheckColor
),
fillColor:
MaterialStateProperty
.
all
<
Color
>(
globalThemeFillColor
),
),
),
home:
Scaffold
(
body:
CheckboxTheme
(
data:
CheckboxThemeData
(
fillColor:
MaterialStateProperty
.
all
<
Color
>(
localThemeFillColor
),
checkColor:
MaterialStateProperty
.
all
<
Color
>(
localThemeCheckColor
),
),
child:
Checkbox
(
value:
active
,
onChanged:
(
_
)
{
},
),
),
),
);
}
await
tester
.
pumpWidget
(
buildCheckbox
(
active:
true
));
await
tester
.
pumpAndSettle
();
expect
(
_getCheckboxMaterial
(
tester
),
paints
..
path
(
color:
localThemeFillColor
));
expect
(
_getCheckboxMaterial
(
tester
),
paints
..
path
(
color:
localThemeFillColor
)..
path
(
color:
localThemeCheckColor
));
});
}
Future
<
void
>
_pointGestureToCheckbox
(
WidgetTester
tester
)
async
{
...
...
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