Yuncong Zhang
6 年前
当前提交
bf6f0c01
共有 8 个文件被更改,包括 1086 次插入 和 383 次删除
-
999Runtime/material/chip.cs
-
12Runtime/material/theme_data.cs
-
4Samples/UIWidgetsGallery/demo/material/chip_demo.cs
-
18Samples/UIWidgetsGallery/gallery/demos.cs
-
298Runtime/material/chip_theme.cs
-
3Runtime/material/chip_theme.cs.meta
-
132Runtime/material/circle_avatar.cs
-
3Runtime/material/circle_avatar.cs.meta
999
Runtime/material/chip.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public class ChipTheme : InheritedWidget { |
|||
public ChipTheme( |
|||
Key key = null, |
|||
ChipThemeData data = null, |
|||
Widget child = null |
|||
) : base(key: key, child: child) { |
|||
D.assert(child != null); |
|||
D.assert(data != null); |
|||
this.data = data; |
|||
} |
|||
|
|||
public readonly ChipThemeData data; |
|||
|
|||
public static ChipThemeData of(BuildContext context) { |
|||
ChipTheme inheritedTheme = (ChipTheme) context.inheritFromWidgetOfExactType(typeof(ChipTheme)); |
|||
return inheritedTheme?.data ?? Theme.of(context).chipTheme; |
|||
} |
|||
|
|||
public override bool updateShouldNotify(InheritedWidget _oldWidget) { |
|||
ChipTheme oldWidget = _oldWidget as ChipTheme; |
|||
return this.data != oldWidget.data; |
|||
} |
|||
} |
|||
|
|||
public class ChipThemeData : Diagnosticable { |
|||
public ChipThemeData( |
|||
Color backgroundColor = null, |
|||
Color deleteIconColor = null, |
|||
Color disabledColor = null, |
|||
Color selectedColor = null, |
|||
Color secondarySelectedColor = null, |
|||
EdgeInsets labelPadding = null, |
|||
EdgeInsets padding = null, |
|||
ShapeBorder shape = null, |
|||
TextStyle labelStyle = null, |
|||
TextStyle secondaryLabelStyle = null, |
|||
Brightness? brightness = null, |
|||
float? elevation = null, |
|||
float? pressElevation = null |
|||
) { |
|||
D.assert(backgroundColor != null); |
|||
D.assert(disabledColor != null); |
|||
D.assert(selectedColor != null); |
|||
D.assert(secondarySelectedColor != null); |
|||
D.assert(labelPadding != null); |
|||
D.assert(padding != null); |
|||
D.assert(shape != null); |
|||
D.assert(labelStyle != null); |
|||
D.assert(secondaryLabelStyle != null); |
|||
D.assert(brightness != null); |
|||
this.backgroundColor = backgroundColor; |
|||
this.deleteIconColor = deleteIconColor; |
|||
this.disabledColor = disabledColor; |
|||
this.selectedColor = selectedColor; |
|||
this.secondarySelectedColor = secondarySelectedColor; |
|||
this.labelPadding = labelPadding; |
|||
this.padding = padding; |
|||
this.shape = shape; |
|||
this.labelStyle = labelStyle; |
|||
this.secondaryLabelStyle = secondaryLabelStyle; |
|||
this.brightness = brightness; |
|||
this.elevation = elevation; |
|||
this.pressElevation = pressElevation; |
|||
} |
|||
|
|||
public static ChipThemeData fromDefaults( |
|||
Brightness? brightness = null, |
|||
Color primaryColor = null, |
|||
Color secondaryColor = null, |
|||
TextStyle labelStyle = null |
|||
) { |
|||
D.assert(primaryColor != null || brightness != null, |
|||
"One of primaryColor or brightness must be specified"); |
|||
D.assert(primaryColor == null || brightness == null, |
|||
"Only one of primaryColor or brightness may be specified"); |
|||
D.assert(secondaryColor != null); |
|||
D.assert(labelStyle != null); |
|||
|
|||
if (primaryColor != null) { |
|||
brightness = ThemeData.estimateBrightnessForColor(primaryColor); |
|||
} |
|||
|
|||
const int backgroundAlpha = 0x1f; // 12%
|
|||
const int deleteIconAlpha = 0xde; // 87%
|
|||
const int disabledAlpha = 0x0c; // 38% * 12% = 5%
|
|||
const int selectAlpha = 0x3d; // 12% + 12% = 24%
|
|||
const int textLabelAlpha = 0xde; // 87%
|
|||
ShapeBorder shape = new StadiumBorder(); |
|||
EdgeInsets labelPadding = EdgeInsets.symmetric(horizontal: 8.0f); |
|||
EdgeInsets padding = EdgeInsets.all(4.0f); |
|||
|
|||
primaryColor = primaryColor ?? (brightness == Brightness.light ? Colors.black : Colors.white); |
|||
Color backgroundColor = primaryColor.withAlpha(backgroundAlpha); |
|||
Color deleteIconColor = primaryColor.withAlpha(deleteIconAlpha); |
|||
Color disabledColor = primaryColor.withAlpha(disabledAlpha); |
|||
Color selectedColor = primaryColor.withAlpha(selectAlpha); |
|||
Color secondarySelectedColor = secondaryColor.withAlpha(selectAlpha); |
|||
TextStyle secondaryLabelStyle = labelStyle.copyWith( |
|||
color: secondaryColor.withAlpha(textLabelAlpha) |
|||
); |
|||
labelStyle = labelStyle.copyWith(color: primaryColor.withAlpha(textLabelAlpha)); |
|||
|
|||
return new ChipThemeData( |
|||
backgroundColor: backgroundColor, |
|||
deleteIconColor: deleteIconColor, |
|||
disabledColor: disabledColor, |
|||
selectedColor: selectedColor, |
|||
secondarySelectedColor: secondarySelectedColor, |
|||
labelPadding: labelPadding, |
|||
padding: padding, |
|||
shape: shape, |
|||
labelStyle: labelStyle, |
|||
secondaryLabelStyle: secondaryLabelStyle, |
|||
brightness: brightness |
|||
); |
|||
} |
|||
|
|||
public readonly Color backgroundColor; |
|||
|
|||
public readonly Color deleteIconColor; |
|||
|
|||
public readonly Color disabledColor; |
|||
|
|||
public readonly Color selectedColor; |
|||
|
|||
public readonly Color secondarySelectedColor; |
|||
|
|||
public readonly EdgeInsets labelPadding; |
|||
|
|||
public readonly EdgeInsets padding; |
|||
|
|||
public readonly ShapeBorder shape; |
|||
|
|||
public readonly TextStyle labelStyle; |
|||
|
|||
public readonly TextStyle secondaryLabelStyle; |
|||
|
|||
public readonly Brightness? brightness; |
|||
|
|||
public readonly float? elevation; |
|||
|
|||
public readonly float? pressElevation; |
|||
|
|||
public ChipThemeData copyWith( |
|||
Color backgroundColor = null, |
|||
Color deleteIconColor = null, |
|||
Color disabledColor = null, |
|||
Color selectedColor = null, |
|||
Color secondarySelectedColor = null, |
|||
EdgeInsets labelPadding = null, |
|||
EdgeInsets padding = null, |
|||
ShapeBorder shape = null, |
|||
TextStyle labelStyle = null, |
|||
TextStyle secondaryLabelStyle = null, |
|||
Brightness? brightness = null, |
|||
float? elevation = null, |
|||
float? pressElevation = null |
|||
) { |
|||
return new ChipThemeData( |
|||
backgroundColor: backgroundColor ?? this.backgroundColor, |
|||
deleteIconColor: deleteIconColor ?? this.deleteIconColor, |
|||
disabledColor: disabledColor ?? this.disabledColor, |
|||
selectedColor: selectedColor ?? this.selectedColor, |
|||
secondarySelectedColor: secondarySelectedColor ?? this.secondarySelectedColor, |
|||
labelPadding: labelPadding ?? this.labelPadding, |
|||
padding: padding ?? this.padding, |
|||
shape: shape ?? this.shape, |
|||
labelStyle: labelStyle ?? this.labelStyle, |
|||
secondaryLabelStyle: secondaryLabelStyle ?? this.secondaryLabelStyle, |
|||
brightness: brightness ?? this.brightness, |
|||
elevation: elevation ?? this.elevation, |
|||
pressElevation: pressElevation ?? this.pressElevation |
|||
); |
|||
} |
|||
|
|||
public static ChipThemeData lerp(ChipThemeData a, ChipThemeData b, float t) { |
|||
D.assert(t != null); |
|||
if (a == null && b == null) { |
|||
return null; |
|||
} |
|||
|
|||
return new ChipThemeData( |
|||
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), |
|||
deleteIconColor: Color.lerp(a?.deleteIconColor, b?.deleteIconColor, t), |
|||
disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t), |
|||
selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t), |
|||
secondarySelectedColor: Color.lerp(a?.secondarySelectedColor, b?.secondarySelectedColor, t), |
|||
labelPadding: EdgeInsets.lerp(a?.labelPadding, b?.labelPadding, t), |
|||
padding: EdgeInsets.lerp(a?.padding, b?.padding, t), |
|||
shape: ShapeBorder.lerp(a?.shape, b?.shape, t), |
|||
labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t), |
|||
secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t), |
|||
brightness: t < 0.5f ? a?.brightness ?? Brightness.light : b?.brightness ?? Brightness.light, |
|||
elevation: MathUtils.lerpFloat(a?.elevation ?? 0.0f, b?.elevation ?? 0.0f, t), |
|||
pressElevation: MathUtils.lerpFloat(a?.pressElevation ?? 0.0f, b?.pressElevation ?? 0.0f, t) |
|||
); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
var hashCode = this.backgroundColor.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.deleteIconColor.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.disabledColor.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.selectedColor.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.secondarySelectedColor.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.labelPadding.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.padding.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.shape.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.labelStyle.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.secondaryLabelStyle.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.brightness.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.elevation.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.pressElevation.GetHashCode(); |
|||
return hashCode; |
|||
} |
|||
|
|||
public bool Equals(ChipThemeData other) { |
|||
return other.backgroundColor == this.backgroundColor |
|||
&& other.deleteIconColor == this.deleteIconColor |
|||
&& other.disabledColor == this.disabledColor |
|||
&& other.selectedColor == this.selectedColor |
|||
&& other.secondarySelectedColor == this.secondarySelectedColor |
|||
&& other.labelPadding == this.labelPadding |
|||
&& other.padding == this.padding |
|||
&& other.shape == this.shape |
|||
&& other.labelStyle == this.labelStyle |
|||
&& other.secondaryLabelStyle == this.secondaryLabelStyle |
|||
&& other.brightness == this.brightness |
|||
&& other.elevation == this.elevation |
|||
&& other.pressElevation == this.pressElevation; |
|||
} |
|||
|
|||
public override bool Equals(object obj) { |
|||
if (ReferenceEquals(null, obj)) { |
|||
return false; |
|||
} |
|||
|
|||
if (ReferenceEquals(this, obj)) { |
|||
return true; |
|||
} |
|||
|
|||
if (obj.GetType() != this.GetType()) { |
|||
return false; |
|||
} |
|||
|
|||
return this.Equals((ChipThemeData) obj); |
|||
} |
|||
|
|||
public static bool operator ==(ChipThemeData left, ChipThemeData right) { |
|||
return left.Equals(right); |
|||
} |
|||
|
|||
public static bool operator !=(ChipThemeData left, ChipThemeData right) { |
|||
return !left.Equals(right); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
ThemeData defaultTheme = ThemeData.fallback(); |
|||
ChipThemeData defaultData = fromDefaults( |
|||
secondaryColor: defaultTheme.primaryColor, |
|||
brightness: defaultTheme.brightness, |
|||
labelStyle: defaultTheme.textTheme.body2 |
|||
); |
|||
properties.add(new DiagnosticsProperty<Color>("backgroundColor", this.backgroundColor, |
|||
defaultValue: defaultData.backgroundColor)); |
|||
properties.add(new DiagnosticsProperty<Color>("deleteIconColor", this.deleteIconColor, |
|||
defaultValue: defaultData.deleteIconColor)); |
|||
properties.add(new DiagnosticsProperty<Color>("disabledColor", this.disabledColor, |
|||
defaultValue: defaultData.disabledColor)); |
|||
properties.add(new DiagnosticsProperty<Color>("selectedColor", this.selectedColor, |
|||
defaultValue: defaultData.selectedColor)); |
|||
properties.add(new DiagnosticsProperty<Color>("secondarySelectedColor", this.secondarySelectedColor, |
|||
defaultValue: defaultData.secondarySelectedColor)); |
|||
properties.add(new DiagnosticsProperty<EdgeInsets>("labelPadding", this.labelPadding, |
|||
defaultValue: defaultData.labelPadding)); |
|||
properties.add( |
|||
new DiagnosticsProperty<EdgeInsets>("padding", this.padding, defaultValue: defaultData.padding)); |
|||
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", this.shape, defaultValue: defaultData.shape)); |
|||
properties.add(new DiagnosticsProperty<TextStyle>("labelStyle", this.labelStyle, |
|||
defaultValue: defaultData.labelStyle)); |
|||
properties.add(new DiagnosticsProperty<TextStyle>("secondaryLabelStyle", this.secondaryLabelStyle, |
|||
defaultValue: defaultData.secondaryLabelStyle)); |
|||
properties.add(new EnumProperty<Brightness?>("brightness", this.brightness, |
|||
defaultValue: defaultData.brightness)); |
|||
properties.add(new FloatProperty("elevation", this.elevation, defaultValue: defaultData.elevation)); |
|||
properties.add(new FloatProperty("pressElevation", this.pressElevation, |
|||
defaultValue: defaultData.pressElevation)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4d46bfb5d5bb492e92f07114849df905 |
|||
timeCreated: 1556165564 |
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
public class CircleAvatar : StatelessWidget { |
|||
public CircleAvatar( |
|||
Key key = null, |
|||
Widget child = null, |
|||
Color backgroundColor = null, |
|||
ImageProvider backgroundImage = null, |
|||
Color foregroundColor = null, |
|||
float? radius = null, |
|||
float? minRadius = null, |
|||
float? maxRadius = null |
|||
) : base(key: key) { |
|||
D.assert(radius == null || (minRadius == null && maxRadius == null)); |
|||
this.child = child; |
|||
this.backgroundColor = backgroundColor; |
|||
this.backgroundImage = backgroundImage; |
|||
this.foregroundColor = foregroundColor; |
|||
this.radius = radius; |
|||
this.minRadius = minRadius; |
|||
this.maxRadius = maxRadius; |
|||
} |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public readonly Color backgroundColor; |
|||
|
|||
public readonly Color foregroundColor; |
|||
|
|||
public readonly ImageProvider backgroundImage; |
|||
|
|||
public readonly float? radius; |
|||
|
|||
public readonly float? minRadius; |
|||
|
|||
public readonly float? maxRadius; |
|||
|
|||
const float _defaultRadius = 20.0f; |
|||
|
|||
const float _defaultMinRadius = 0.0f; |
|||
|
|||
const float _defaultMaxRadius = float.PositiveInfinity; |
|||
|
|||
float _minDiameter { |
|||
get { |
|||
if (this.radius == null && this.minRadius == null && this.maxRadius == null) { |
|||
return _defaultRadius * 2.0f; |
|||
} |
|||
|
|||
return 2.0f * (this.radius ?? this.minRadius ?? _defaultMinRadius); |
|||
} |
|||
} |
|||
|
|||
float _maxDiameter { |
|||
get { |
|||
if (this.radius == null && this.minRadius == null && this.maxRadius == null) { |
|||
return _defaultRadius * 2.0f; |
|||
} |
|||
|
|||
return 2.0f * (this.radius ?? this.maxRadius ?? _defaultMaxRadius); |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
D.assert(WidgetsD.debugCheckHasMediaQuery(context)); |
|||
ThemeData theme = Theme.of(context); |
|||
TextStyle textStyle = theme.primaryTextTheme.subhead.copyWith(color: this.foregroundColor); |
|||
Color effectiveBackgroundColor = this.backgroundColor; |
|||
if (effectiveBackgroundColor == null) { |
|||
switch (ThemeData.estimateBrightnessForColor(textStyle.color)) { |
|||
case Brightness.dark: |
|||
effectiveBackgroundColor = theme.primaryColorLight; |
|||
break; |
|||
case Brightness.light: |
|||
effectiveBackgroundColor = theme.primaryColorDark; |
|||
break; |
|||
} |
|||
} |
|||
else if (this.foregroundColor == null) { |
|||
switch (ThemeData.estimateBrightnessForColor(this.backgroundColor)) { |
|||
case Brightness.dark: |
|||
textStyle = textStyle.copyWith(color: theme.primaryColorLight); |
|||
break; |
|||
case Brightness.light: |
|||
textStyle = textStyle.copyWith(color: theme.primaryColorDark); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
float minDiameter = this._minDiameter; |
|||
float maxDiameter = this._maxDiameter; |
|||
return new AnimatedContainer( |
|||
constraints: new BoxConstraints( |
|||
minHeight: minDiameter, |
|||
minWidth: minDiameter, |
|||
maxWidth: maxDiameter, |
|||
maxHeight: maxDiameter |
|||
), |
|||
duration: Constants.kThemeChangeDuration, |
|||
decoration: new BoxDecoration( |
|||
color: effectiveBackgroundColor, |
|||
image: this.backgroundImage != null |
|||
? new DecorationImage(image: this.backgroundImage, fit: BoxFit.cover) |
|||
: null, |
|||
shape: BoxShape.circle |
|||
), |
|||
child: this.child == null |
|||
? null |
|||
: new Center( |
|||
child: new MediaQuery( |
|||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0f), |
|||
child: new IconTheme( |
|||
data: theme.iconTheme.copyWith(color: textStyle.color), |
|||
child: new DefaultTextStyle( |
|||
style: textStyle, |
|||
child: this.child |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 32591e65e11049cab124c86bc8fe573c |
|||
timeCreated: 1556169017 |
撰写
预览
正在加载...
取消
保存
Reference in new issue