浏览代码

Update switch

/main
Yuncong Zhang 5 年前
当前提交
1ce97edb
共有 1 个文件被更改,包括 55 次插入20 次删除
  1. 75
      Runtime/material/switch.cs

75
Runtime/material/switch.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;

Color inactiveTrackColor = null,
ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
MaterialTapTargetSize? materialTapTargetSize = null
MaterialTapTargetSize? materialTapTargetSize = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : this(
key: key,
value: value,

activeThumbImage: activeThumbImage,
inactiveThumbImage: inactiveThumbImage,
materialTapTargetSize: materialTapTargetSize,
switchType: _SwitchType.material
switchType: _SwitchType.material,
dragStartBehavior: dragStartBehavior
) {
}

ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
MaterialTapTargetSize? materialTapTargetSize = null,
_SwitchType switchType = _SwitchType.material
_SwitchType switchType = _SwitchType.material,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(key: key) {
D.assert(value != null);
this.value = value.Value;

this.inactiveThumbImage = inactiveThumbImage;
this.materialTapTargetSize = materialTapTargetSize;
this._switchType = switchType;
this.dragStartBehavior = dragStartBehavior;
}
public static Switch adaptive(

Color inactiveTrackColor = null,
ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
MaterialTapTargetSize? materialTapTargetSize = null
MaterialTapTargetSize? materialTapTargetSize = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) {
return new Switch(key: key,
value: value,

internal readonly _SwitchType _switchType;
public readonly DragStartBehavior dragStartBehavior;
public override State createState() {
return new _SwitchState();
}

properties.add(new FlagProperty("value", value: this.value, ifTrue: "on", ifFalse: "off", showName: true));
properties.add(new ObjectFlagProperty<ValueChanged<bool?>>("onChanged", this.onChanged, ifNull: "disabled"));
properties.add(
new ObjectFlagProperty<ValueChanged<bool?>>("onChanged", this.onChanged, ifNull: "disabled"));
}
}

case MaterialTapTargetSize.shrinkWrap:
return new Size(Switch._kSwitchWidth, Switch._kSwitchHeightCollapsed);
}
D.assert(false);
return null;
}

inactiveThumbColor = this.widget.inactiveThumbColor ??
(isDark ? Colors.grey.shade400 : Colors.grey.shade50);
inactiveTrackColor = this.widget.inactiveTrackColor ?? (isDark ? Colors.white30 : black32);
} else {
}
else {
inactiveThumbColor = this.widget.inactiveThumbColor ??
(isDark ? Colors.grey.shade800 : Colors.grey.shade400);
inactiveTrackColor = this.widget.inactiveTrackColor ?? (isDark ? Colors.white10 : Colors.black12);

dragStartBehavior: this.widget.dragStartBehavior,
value: this.widget.value,
activeColor: activeThumbColor,
inactiveColor: inactiveThumbColor,

ImageConfiguration configuration = null,
ValueChanged<bool?> onChanged = null,
TickerProvider vsync = null,
BoxConstraints additionalConstraints = null
BoxConstraints additionalConstraints = null,
DragStartBehavior? dragStartBehavior = null
) : base(key: key) {
D.assert(value != null);
this.value = value.Value;

this.onChanged = onChanged;
this.vsync = vsync;
this.additionalConstraints = additionalConstraints;
this.dragStartBehavior = dragStartBehavior;
}
public readonly bool value;

public readonly ValueChanged<bool?> onChanged;
public readonly TickerProvider vsync;
public readonly BoxConstraints additionalConstraints;
public readonly DragStartBehavior? dragStartBehavior;
dragStartBehavior: this.dragStartBehavior,
value: this.value,
activeColor: this.activeColor,
inactiveColor: this.inactiveColor,

renderObject.configuration = this.configuration;
renderObject.onChanged = this.onChanged;
renderObject.additionalConstraints = this.additionalConstraints;
renderObject.dragStartBehavior = this.dragStartBehavior;
renderObject.vsync = this.vsync;
}
}

ImageConfiguration configuration = null,
BoxConstraints additionalConstraints = null,
ValueChanged<bool?> onChanged = null,
TickerProvider vsync = null
TickerProvider vsync = null,
DragStartBehavior? dragStartBehavior = null
) : base(
value: value,
tristate: false,

onStart = this._handleDragStart,
onUpdate = this._handleDragUpdate,
onEnd = this._handleDragEnd,
dragStartBehavior = dragStartBehavior ?? DragStartBehavior.down
};
}

if (value == this._activeThumbImage) {
return;
}
this._activeThumbImage = value;
this.markNeedsPaint();
}

if (value == this._inactiveThumbImage) {
return;
}
this._inactiveThumbImage = value;
this.markNeedsPaint();
}

if (value == this._activeTrackColor) {
return;
}
this._activeTrackColor = value;
this.markNeedsPaint();
}

if (value == this._inactiveTrackColor) {
return;
}
this._inactiveTrackColor = value;
this.markNeedsPaint();
}

if (value == this._configuration) {
return;
}
this._configuration = value;
this.markNeedsPaint();
}

public DragStartBehavior? dragStartBehavior {
get { return this._drag.dragStartBehavior; }
set { this._drag.dragStartBehavior = value ?? DragStartBehavior.down; }
}
public override void detach() {
this._cachedThumbPainter?.Dispose();

void _handleDragEnd(DragEndDetails details) {
if (this.position.value >= 0.5) {
this.positionController.forward();
} else {
}
else {
this.reactionController.reverse();
}

this._drag.addPointer((PointerDownEvent) evt);
}
base.handleEvent(evt, entry);
}

public override void paint(PaintingContext context, Offset offset) {
Canvas canvas = context.canvas;
bool isActive = this.onChanged != null;
bool isEnabled = this.onChanged != null;
Color trackColor = isActive
Color trackColor = isEnabled
Color thumbColor = isEnabled
? Color.lerp(this.inactiveColor, this.activeColor, currentValue)
: this.inactiveColor;
ImageProvider thumbImage = isEnabled
? (currentValue < 0.5 ? this.inactiveThumbImage : this.activeThumbImage)
: this.inactiveThumbImage;
// Paint the track
Paint paint = new Paint {color = trackColor};
float trackHorizontalPadding = Constants.kRadialReactionRadius - Switch._kTrackRadius;

try {
this._isPainting = true;
BoxPainter thumbPainter;
Color thumbColor = isActive
? Color.lerp(this.inactiveColor, this.activeColor, currentValue)
: this.inactiveColor;
ImageProvider thumbImage = isActive
? (currentValue < 0.5 ? this.inactiveThumbImage : this.activeThumbImage)
: this.inactiveThumbImage;
if (this._cachedThumbPainter == null || thumbColor != this._cachedThumbColor ||
thumbImage != this._cachedThumbImage) {
this._cachedThumbColor = thumbColor;

}
thumbPainter = this._cachedThumbPainter;
float inset = 1.0f - (currentValue - 0.5f).abs() * 2.0f;

thumbPosition + offset - new Offset(radius, radius),
this.configuration.copyWith(size: Size.fromRadius(radius))
);
} finally {
}
finally {
}
}
正在加载...
取消
保存