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
ddfe8a35
Unverified
Commit
ddfe8a35
authored
Jun 08, 2023
by
Taha Tesser
Committed by
GitHub
Jun 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `chip.dart` to use set of `MaterialState` (#128507)
parent
29c858ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
18 deletions
+44
-18
chip.dart
packages/flutter/lib/src/material/chip.dart
+44
-18
No files found.
packages/flutter/lib/src/material/chip.dart
View file @
ddfe8a35
...
...
@@ -19,7 +19,6 @@ import 'ink_well.dart';
import
'material.dart'
;
import
'material_localizations.dart'
;
import
'material_state.dart'
;
import
'material_state_mixin.dart'
;
import
'text_theme.dart'
;
import
'theme.dart'
;
import
'theme_data.dart'
;
...
...
@@ -842,7 +841,7 @@ class RawChip extends StatefulWidget
State
<
RawChip
>
createState
()
=>
_RawChipState
();
}
class
_RawChipState
extends
State
<
RawChip
>
with
MaterialStateMixin
,
TickerProviderStateMixin
<
RawChip
>
{
class
_RawChipState
extends
State
<
RawChip
>
with
TickerProviderStateMixin
<
RawChip
>
{
static
const
Duration
pressedAnimationDuration
=
Duration
(
milliseconds:
75
);
late
AnimationController
selectController
;
...
...
@@ -854,6 +853,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
late
Animation
<
double
>
deleteDrawerAnimation
;
late
Animation
<
double
>
enableAnimation
;
late
Animation
<
double
>
selectionFade
;
late
final
Set
<
MaterialState
>
states
;
bool
get
hasDeleteButton
=>
widget
.
onDeleted
!=
null
;
bool
get
hasAvatar
=>
widget
.
avatar
!=
null
;
...
...
@@ -871,8 +871,10 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
void
initState
()
{
assert
(
widget
.
onSelected
==
null
||
widget
.
onPressed
==
null
);
super
.
initState
();
setMaterialState
(
MaterialState
.
disabled
,
!
widget
.
isEnabled
);
setMaterialState
(
MaterialState
.
selected
,
widget
.
selected
);
states
=
<
MaterialState
>{
if
(!
widget
.
isEnabled
)
MaterialState
.
disabled
,
if
(
widget
.
selected
)
MaterialState
.
selected
,
};
selectController
=
AnimationController
(
duration:
_kSelectDuration
,
value:
widget
.
selected
?
1.0
:
0.0
,
...
...
@@ -947,7 +949,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
if
(!
canTap
)
{
return
;
}
s
etMaterialState
(
MaterialState
.
pressed
,
true
);
s
tates
.
add
(
MaterialState
.
pressed
);
setState
(()
{
_isTapping
=
true
;
});
...
...
@@ -957,7 +959,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
if
(!
canTap
)
{
return
;
}
s
etMaterialState
(
MaterialState
.
pressed
,
false
);
s
tates
.
remove
(
MaterialState
.
pressed
);
setState
(()
{
_isTapping
=
false
;
});
...
...
@@ -967,7 +969,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
if
(!
canTap
)
{
return
;
}
s
etMaterialState
(
MaterialState
.
pressed
,
false
);
s
tates
.
remove
(
MaterialState
.
pressed
);
setState
(()
{
_isTapping
=
false
;
});
...
...
@@ -976,13 +978,33 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
widget
.
onPressed
?.
call
();
}
void
_updateFocusState
(
bool
focused
)
{
setState
(()
{
if
(
focused
)
{
states
.
add
(
MaterialState
.
focused
);
}
else
{
states
.
remove
(
MaterialState
.
focused
);
}
});
}
void
_updateHoverState
(
bool
hovered
)
{
setState
(()
{
if
(
hovered
)
{
states
.
add
(
MaterialState
.
hovered
);
}
else
{
states
.
remove
(
MaterialState
.
hovered
);
}
});
}
OutlinedBorder
_getShape
(
ThemeData
theme
,
ChipThemeData
chipTheme
,
ChipThemeData
chipDefaults
)
{
final
BorderSide
?
resolvedSide
=
MaterialStateProperty
.
resolveAs
<
BorderSide
?>(
widget
.
side
,
materialS
tates
)
??
MaterialStateProperty
.
resolveAs
<
BorderSide
?>(
chipTheme
.
side
,
materialS
tates
)
??
MaterialStateProperty
.
resolveAs
<
BorderSide
?>(
chipDefaults
.
side
,
materialS
tates
);
final
OutlinedBorder
resolvedShape
=
MaterialStateProperty
.
resolveAs
<
OutlinedBorder
?>(
widget
.
shape
,
materialS
tates
)
??
MaterialStateProperty
.
resolveAs
<
OutlinedBorder
?>(
chipTheme
.
shape
,
materialS
tates
)
??
MaterialStateProperty
.
resolveAs
<
OutlinedBorder
?>(
chipDefaults
.
shape
,
materialS
tates
)
final
BorderSide
?
resolvedSide
=
MaterialStateProperty
.
resolveAs
<
BorderSide
?>(
widget
.
side
,
s
tates
)
??
MaterialStateProperty
.
resolveAs
<
BorderSide
?>(
chipTheme
.
side
,
s
tates
)
??
MaterialStateProperty
.
resolveAs
<
BorderSide
?>(
chipDefaults
.
side
,
s
tates
);
final
OutlinedBorder
resolvedShape
=
MaterialStateProperty
.
resolveAs
<
OutlinedBorder
?>(
widget
.
shape
,
s
tates
)
??
MaterialStateProperty
.
resolveAs
<
OutlinedBorder
?>(
chipTheme
.
shape
,
s
tates
)
??
MaterialStateProperty
.
resolveAs
<
OutlinedBorder
?>(
chipDefaults
.
shape
,
s
tates
)
??
const
StadiumBorder
();
return
resolvedShape
.
copyWith
(
side:
resolvedSide
);
}
...
...
@@ -1032,7 +1054,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
super
.
didUpdateWidget
(
oldWidget
);
if
(
oldWidget
.
isEnabled
!=
widget
.
isEnabled
)
{
setState
(()
{
setMaterialState
(
MaterialState
.
disabled
,
!
widget
.
isEnabled
);
if
(!
widget
.
isEnabled
)
{
states
.
add
(
MaterialState
.
disabled
);
}
if
(
widget
.
isEnabled
)
{
enableController
.
forward
();
}
else
{
...
...
@@ -1051,7 +1075,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
}
if
(
oldWidget
.
selected
!=
widget
.
selected
)
{
setState
(()
{
setMaterialState
(
MaterialState
.
selected
,
widget
.
selected
);
if
(
widget
.
selected
)
{
states
.
add
(
MaterialState
.
selected
);
}
if
(
widget
.
selected
)
{
selectController
.
forward
();
}
else
{
...
...
@@ -1187,7 +1213,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
??
chipDefaults
.
iconTheme
;
final
TextStyle
effectiveLabelStyle
=
labelStyle
.
merge
(
widget
.
labelStyle
);
final
Color
?
resolvedLabelColor
=
MaterialStateProperty
.
resolveAs
<
Color
?>(
effectiveLabelStyle
.
color
,
materialS
tates
);
final
Color
?
resolvedLabelColor
=
MaterialStateProperty
.
resolveAs
<
Color
?>(
effectiveLabelStyle
.
color
,
s
tates
);
final
TextStyle
resolvedLabelStyle
=
effectiveLabelStyle
.
copyWith
(
color:
resolvedLabelColor
);
final
Widget
?
avatar
=
iconTheme
!=
null
&&
hasAvatar
?
IconTheme
(
data:
iconTheme
,
child:
widget
.
avatar
!)
...
...
@@ -1201,14 +1227,14 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
shape:
resolvedShape
,
clipBehavior:
widget
.
clipBehavior
,
child:
InkWell
(
onFocusChange:
updateMaterialState
(
MaterialState
.
focused
)
,
onFocusChange:
_updateFocusState
,
focusNode:
widget
.
focusNode
,
autofocus:
widget
.
autofocus
,
canRequestFocus:
widget
.
isEnabled
,
onTap:
canTap
?
_handleTap
:
null
,
onTapDown:
canTap
?
_handleTapDown
:
null
,
onTapCancel:
canTap
?
_handleTapCancel
:
null
,
onHover:
canTap
?
updateMaterialState
(
MaterialState
.
hovered
)
:
null
,
onHover:
canTap
?
_updateHoverState
:
null
,
customBorder:
resolvedShape
,
child:
AnimatedBuilder
(
animation:
Listenable
.
merge
(<
Listenable
>[
selectController
,
enableController
]),
...
...
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