Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 4e921c2

Browse files
author
Yuncong Zhang
committed
Fix chip.
1 parent ee1717b commit 4e921c2

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed

Runtime/material/chip.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,7 @@ public FilterChip(
681681
float? elevation = null,
682682
ShapeBorder avatarBorder = null
683683
) : base(key: key) {
684-
D.assert(selected != null);
685-
D.assert(onSelected != null);
686684
D.assert(label != null);
687-
D.assert(clipBehavior != null);
688685
D.assert(pressElevation == null || pressElevation >= 0.0f);
689686
D.assert(elevation == null || elevation >= 0.0f);
690687
this._avatarBorder = avatarBorder ?? new CircleBorder();
@@ -1013,7 +1010,6 @@ public RawChip(
10131010
) : base(key: key) {
10141011
D.assert(label != null);
10151012
D.assert(isEnabled != null);
1016-
D.assert(clipBehavior != null);
10171013
D.assert(pressElevation == null || pressElevation >= 0.0f);
10181014
D.assert(elevation == null || elevation >= 0.0f);
10191015
deleteIcon = deleteIcon ?? ChipUtils._kDefaultDeleteIcon;
@@ -1438,8 +1434,8 @@ public override Widget build(BuildContext context) {
14381434
ChipThemeData chipTheme = ChipTheme.of(context);
14391435
TextDirection textDirection = Directionality.of(context);
14401436
ShapeBorder shape = this.widget.shape ?? chipTheme.shape;
1441-
float elevation = this.widget.elevation ?? chipTheme.elevation ?? _defaultElevation;
1442-
float pressElevation = this.widget.pressElevation ?? chipTheme.pressElevation ?? _defaultPressElevation;
1437+
float elevation = this.widget.elevation ?? (chipTheme.elevation ?? _defaultElevation);
1438+
float pressElevation = this.widget.pressElevation ?? (chipTheme.pressElevation ?? _defaultPressElevation);
14431439

14441440
Widget result = new Material(
14451441
elevation: this.isTapping ? pressElevation : elevation,
@@ -1503,7 +1499,7 @@ public override Widget build(BuildContext context) {
15031499
)
15041500
);
15051501
BoxConstraints constraints;
1506-
switch (this.widget.materialTapTargetSize) {
1502+
switch (this.widget.materialTapTargetSize ?? theme.materialTapTargetSize) {
15071503
case MaterialTapTargetSize.padded:
15081504
constraints = new BoxConstraints(minHeight: 48.0f);
15091505
break;
@@ -1657,7 +1653,7 @@ protected override void forgetChild(Element child) {
16571653
}
16581654

16591655
void _mountChild(Widget widget, _ChipSlot slot) {
1660-
Element oldChild = this.slotToChild[slot];
1656+
Element oldChild = this.slotToChild.getOrDefault(slot);
16611657
Element newChild = this.updateChild(oldChild, widget, slot);
16621658
if (oldChild != null) {
16631659
this.slotToChild.Remove(slot);
@@ -1714,10 +1710,10 @@ void _updateRenderObject(RenderObject child, _ChipSlot slot) {
17141710
}
17151711
}
17161712

1717-
protected override void insertChildRenderObject(RenderObject child, dynamic slotValue) {
1713+
protected override void insertChildRenderObject(RenderObject child, object slotValue) {
17181714
D.assert(child is RenderBox);
17191715
D.assert(slotValue is _ChipSlot);
1720-
_ChipSlot slot = slotValue;
1716+
_ChipSlot slot = (_ChipSlot) slotValue;
17211717
this._updateRenderObject(child, slot);
17221718
D.assert(this.renderObject.childToSlot.ContainsKey((RenderBox) child));
17231719
D.assert(this.renderObject.slotToChild.ContainsKey(slot));
@@ -1731,7 +1727,7 @@ protected override void removeChildRenderObject(RenderObject child) {
17311727
D.assert(!this.renderObject.slotToChild.ContainsKey((_ChipSlot) this.slot));
17321728
}
17331729

1734-
protected override void moveChildRenderObject(RenderObject child, dynamic slotValue) {
1730+
protected override void moveChildRenderObject(RenderObject child, object slotValue) {
17351731
D.assert(false, "not reachable");
17361732
}
17371733
}
@@ -1798,11 +1794,11 @@ public bool Equals(_ChipRenderTheme other) {
17981794
}
17991795

18001796
public static bool operator ==(_ChipRenderTheme left, _ChipRenderTheme right) {
1801-
return left.Equals(right);
1797+
return Equals(left, right);
18021798
}
18031799

18041800
public static bool operator !=(_ChipRenderTheme left, _ChipRenderTheme right) {
1805-
return !left.Equals(right);
1801+
return !Equals(left, right);
18061802
}
18071803

18081804
public override int GetHashCode() {
@@ -1832,9 +1828,9 @@ public _RenderChip(
18321828
) {
18331829
D.assert(theme != null);
18341830
this._theme = theme;
1835-
this.checkmarkAnimation.addListener(this.markNeedsPaint);
1831+
checkmarkAnimation.addListener(this.markNeedsPaint);
18361832
avatarDrawerAnimation.addListener(this.markNeedsLayout);
1837-
this.deleteDrawerAnimation.addListener(this.markNeedsLayout);
1833+
deleteDrawerAnimation.addListener(this.markNeedsLayout);
18381834
enableAnimation.addListener(this.markNeedsPaint);
18391835
this.value = value;
18401836
this.isEnabled = isEnabled;
@@ -2141,11 +2137,10 @@ protected override void performLayout() {
21412137

21422138

21432139
const float left = 0.0f;
2144-
float right = overallSize.width;
21452140

21462141
Offset centerLayout(Size boxSize, float x) {
21472142
D.assert(contentSize >= boxSize.height);
2148-
return new Offset(x - boxSize.width, (contentSize - boxSize.height) / 2.0f);
2143+
return new Offset(x, (contentSize - boxSize.height) / 2.0f);
21492144
}
21502145

21512146
Offset avatarOffset = Offset.zero;
@@ -2202,11 +2197,11 @@ Offset centerLayout(Size boxSize, float x) {
22022197
);
22032198
this.size = this.constraints.constrain(paddedSize);
22042199
D.assert(this.size.height == this.constraints.constrainHeight(paddedSize.height),
2205-
"Constrained height ${size.height} doesn't match expected height " +
2206-
"${constraints.constrainWidth(paddedSize.height)}");
2200+
$"Constrained height {this.size.height} doesn't match expected height " +
2201+
$"{this.constraints.constrainWidth(paddedSize.height)}");
22072202
D.assert(this.size.width == this.constraints.constrainWidth(paddedSize.width),
2208-
"Constrained width ${size.width} doesn't match expected width " +
2209-
"${constraints.constrainWidth(paddedSize.width)}");
2203+
$"Constrained width {this.size.width} doesn't match expected width " +
2204+
$"{this.constraints.constrainWidth(paddedSize.width)}");
22102205
}
22112206

22122207
static ColorTween selectionScrimTween = new ColorTween(

Runtime/material/chip_theme.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ public override bool Equals(object obj) {
254254
}
255255

256256
public static bool operator ==(ChipThemeData left, ChipThemeData right) {
257-
return left.Equals(right);
257+
return Equals(left, right);
258258
}
259259

260260
public static bool operator !=(ChipThemeData left, ChipThemeData right) {
261-
return !left.Equals(right);
261+
return !Equals(left, right);
262262
}
263263

264264
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {

Runtime/material/theme_data.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public ThemeData(
213213
D.assert(typography != null);
214214
D.assert(buttonColor != null);
215215
D.assert(tabBarTheme != null);
216+
D.assert(chipTheme != null);
216217
D.assert(dialogTheme != null);
217218

218219
this.brightness = brightness ?? Brightness.light;
@@ -253,6 +254,7 @@ public ThemeData(
253254
this.primaryIconTheme = primaryIconTheme;
254255
this.accentIconTheme = accentIconTheme;
255256
this.tabBarTheme = tabBarTheme;
257+
this.chipTheme = chipTheme;
256258
this.platform = platform.Value;
257259
this.materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;
258260
this.pageTransitionsTheme = pageTransitionsTheme;
@@ -351,6 +353,7 @@ public static ThemeData raw(
351353
D.assert(typography != null);
352354
D.assert(buttonColor != null);
353355
D.assert(tabBarTheme != null);
356+
D.assert(chipTheme != null);
354357
D.assert(dialogTheme != null);
355358

356359
return new ThemeData(
@@ -392,6 +395,7 @@ public static ThemeData raw(
392395
primaryIconTheme: primaryIconTheme,
393396
accentIconTheme: accentIconTheme,
394397
tabBarTheme: tabBarTheme,
398+
chipTheme: chipTheme,
395399
platform: platform,
396400
materialTapTargetSize: materialTapTargetSize,
397401
pageTransitionsTheme: pageTransitionsTheme,
@@ -542,7 +546,7 @@ public ThemeData copyWith(
542546
IconThemeData primaryIconTheme = null,
543547
IconThemeData accentIconTheme = null,
544548
TabBarTheme tabBarTheme = null,
545-
ChipThemeData chimpTheme = null,
549+
ChipThemeData chipTheme = null,
546550
RuntimePlatform? platform = null,
547551
MaterialTapTargetSize? materialTapTargetSize = null,
548552
PageTransitionsTheme pageTransitionsTheme = null,
@@ -589,6 +593,7 @@ public ThemeData copyWith(
589593
primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme,
590594
accentIconTheme: accentIconTheme ?? this.accentIconTheme,
591595
tabBarTheme: tabBarTheme ?? this.tabBarTheme,
596+
chipTheme: chipTheme ?? this.chipTheme,
592597
platform: platform ?? this.platform,
593598
materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize,
594599
pageTransitionsTheme: pageTransitionsTheme ?? this.pageTransitionsTheme,
@@ -728,6 +733,7 @@ public bool Equals(ThemeData other) {
728733
other.primaryIconTheme == this.primaryIconTheme &&
729734
other.accentIconTheme == this.accentIconTheme &&
730735
other.tabBarTheme == this.tabBarTheme &&
736+
other.chipTheme == this.chipTheme &&
731737
other.platform == this.platform &&
732738
other.materialTapTargetSize == this.materialTapTargetSize &&
733739
other.pageTransitionsTheme == this.pageTransitionsTheme &&
@@ -805,6 +811,7 @@ public override int GetHashCode() {
805811
hashCode = (hashCode * 397) ^ this.primaryIconTheme.GetHashCode();
806812
hashCode = (hashCode * 397) ^ this.accentIconTheme.GetHashCode();
807813
hashCode = (hashCode * 397) ^ this.tabBarTheme.GetHashCode();
814+
hashCode = (hashCode * 397) ^ this.chipTheme.GetHashCode();
808815
hashCode = (hashCode * 397) ^ this.platform.GetHashCode();
809816
hashCode = (hashCode * 397) ^ this.materialTapTargetSize.GetHashCode();
810817
hashCode = (hashCode * 397) ^ this.pageTransitionsTheme.GetHashCode();

Samples/UIWidgetsGallery/demo/material/chip_demo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class ChipDemoUtils {
5050
};
5151

5252
public static readonly Dictionary<string, string> _avatars = new Dictionary<string, string> {
53-
{"hammer", "people/square/ali.png"},
54-
{"chisel", "people/square/sandra.png"},
55-
{"fryer", "people/square/trevor.png"},
56-
{"fabricator", "people/square/stella.png"},
57-
{"customer", "people/square/peter.png"}
53+
{"hammer", "people/square/ali"},
54+
{"chisel", "people/square/sandra"},
55+
{"fryer", "people/square/trevor"},
56+
{"fabricator", "people/square/stella"},
57+
{"customer", "people/square/peter"}
5858
};
5959

6060
public static readonly Dictionary<string, HashSet<string>> _toolActions =

0 commit comments

Comments
 (0)