浏览代码

Merge branch 'yczhang_material' into gallery

/main
Yuncong Zhang 6 年前
当前提交
1530cdb8
共有 6 个文件被更改,包括 474 次插入460 次删除
  1. 17
      Runtime/material/dropdown.cs
  2. 3
      Runtime/material/input_border.cs
  3. 117
      Runtime/material/input_decorator.cs
  4. 781
      Runtime/material/outline_button.cs
  5. 10
      Runtime/material/progress_indicator.cs
  6. 6
      Runtime/widgets/form.cs

17
Runtime/material/dropdown.cs


public static readonly TimeSpan _kDropdownMenuDuration = new TimeSpan(0, 0, 0, 0, 300);
public const float _kMenuItemHeight = 48.0f;
public const float _kDenseButtonHeight = 24.0f;
public static EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 16.0f);
public static EdgeInsets _kAlignedButtonPadding = EdgeInsets.only(left: 16.0f, right: 4.0f);
public static EdgeInsets _kUnalignedButtonPadding = EdgeInsets.zero;
public static EdgeInsets _kAlignedMenuMargin = EdgeInsets.zero;
public static EdgeInsets _kUnalignedMenuMargin = EdgeInsets.only(left: 16.0f, right: 24.0f);
public static readonly EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 16.0f);
public static readonly EdgeInsets _kAlignedButtonPadding = EdgeInsets.only(left: 16.0f, right: 4.0f);
public static readonly EdgeInsets _kUnalignedButtonPadding = EdgeInsets.zero;
public static readonly EdgeInsets _kAlignedMenuMargin = EdgeInsets.zero;
public static readonly EdgeInsets _kUnalignedMenuMargin = EdgeInsets.only(left: 16.0f, right: 24.0f);
}
class _DropdownMenuPainter : AbstractCustomPainter {

public override void initState() {
base.initState();
// We need to hold these animations as state because of their curve
// direction. When the route's animation reverses, if we were to recreate
// the CurvedAnimation objects in build, we'd lose
// CurvedAnimation._curveDirection.
this._fadeOpacity = new CurvedAnimation(
parent: this.widget.route.animation,
curve: new Interval(0.0f, 0.25f),

D.assert(() => {
Rect container = Offset.zero & size;
if (container.intersect(this.buttonRect) == this.buttonRect) {
// If the button was entirely on-screen, then verify
// that the menu is also on-screen.
// If the button was a bit off-screen, then, oh well.
D.assert(this.menuTop >= 0.0f);
D.assert(this.menuTop + this.menuHeight <= size.height);
}

3
Runtime/material/input_border.cs


public InputBorder(
BorderSide borderSide = null
) {
this.borderSide = this.borderSide ?? BorderSide.none;
this.borderSide = borderSide ?? BorderSide.none;
}
public static readonly InputBorder none = new _NoInputBorder();

float gapPadding = 4.0f
) : base(borderSide: borderSide ?? new BorderSide()) {
D.assert(gapPadding >= 0.0f);
this.gapPadding = gapPadding;
this.borderRadius = borderRadius ?? BorderRadius.all(Radius.circular(4.0f));
}

117
Runtime/material/input_decorator.cs


using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using Transform = Unity.UIWidgets.widgets.Transform;
namespace Unity.UIWidgets.material {
class InputDecoratorConstants {

this.fillColor = fillColor;
}
Animation<float> borderAnimation;
_InputBorderTween border;
Animation<float> gapAnimation;
_InputBorderGap gap;
TextDirection? textDirection;
Color fillColor;
public readonly Animation<float> borderAnimation;
public readonly _InputBorderTween border;
public readonly Animation<float> gapAnimation;
public readonly _InputBorderGap gap;
public readonly TextDirection? textDirection;
public readonly Color fillColor;
public override void paint(Canvas canvas, Size size) {
InputBorder borderValue = this.border.evaluate(this.borderAnimation);

Animation<float> _borderAnimation;
_InputBorderTween _border;
public void initState() {
public override void initState() {
base.initState();
this._controller = new AnimationController(
duration: InputDecoratorConstants._kTransitionDuration,

}
}
// Display the helper and error text. When the error text appears
// it fades and the helper text fades out. The error text also
// slides upwards a little when it first appears.
class _HelperError : StatefulWidget {
public _HelperError(
Key key = null,

void _handleChange() {
this.setState(() => {
// The _controller"s value has changed.
});
}

}
}
// Identifies the children of a _RenderDecorationElement.
enum _DecorationSlot {
icon,
input,

container
}
// An analog of InputDecoration for the _Decorator widget.
class _Decoration {
public _Decoration(
EdgeInsets contentPadding,

public readonly Dictionary<RenderBox, float> boxToBaseline;
public readonly float? inputBaseline;
public readonly float? outlineBaseline;
public readonly float? subtextBaseline; // helper/error counter
public readonly float? subtextBaseline;
// The workhorse: layout and paint a _Decorator widget"s _Decoration.
class _RenderDecoration : RenderBox {
public _RenderDecoration(
_Decoration decoration,

set { this._container = this._updateChild(this._container, value, _DecorationSlot.container); }
}
// The returned list is ordered for hit testing.
IEnumerable<RenderBox> _children {
get {
if (this.icon != null) {

float baseline = box.getDistanceToBaseline(this.textBaseline ?? 0.0f) ?? 0.0f;
D.assert(baseline >= 0.0f);
boxToBaseline[box] = baseline;
aboveBaseline = Math.Max(baseline, aboveBaseline);
belowBaseline = Math.Max(box.size.height - baseline, belowBaseline);
aboveBaseline = Mathf.Max(baseline, aboveBaseline);
belowBaseline = Mathf.Max(box.size.height - baseline, belowBaseline);
}
layoutLineBox(this.prefix);

this.suffixIcon.layout(boxConstraints, parentUsesSize: true);
}
float inputWidth = Math.Max(0.0f, this.constraints.maxWidth - (
float inputWidth = Mathf.Max(0.0f, this.constraints.maxWidth - (
_boxSize(this.icon).width
+ this.contentPadding.left
+ _boxSize(this.prefixIcon).width

+ this.contentPadding.right));
boxConstraints = boxConstraints.copyWith(maxWidth: inputWidth);
if (this.label != null) // The label is not baseline aligned.
if (this.label != null)
{
this.label.layout(boxConstraints, parentUsesSize: true);
}

+ this.contentPadding.bottom;
if (this.label != null) {
// floatingLabelHeight includes the vertical gap between the inline
// elements and the floating label.
containerHeight = Math.Max(
containerHeight = Mathf.Max(
Math.Max(
Mathf.Max(
_boxSize(this.suffixIcon).height,
_boxSize(this.prefixIcon).height));

belowBaseline = 0.0f;
layoutLineBox(this.counter);
// The helper or error text can occupy the full width less the space
// occupied by the icon and counter.
maxWidth: Math.Max(0.0f, boxConstraints.maxWidth
maxWidth: Mathf.Max(0.0f, boxConstraints.maxWidth
- _boxSize(this.icon).width
- _boxSize(this.counter).width
- this.contentPadding.horizontal

+ this.contentPadding.left
+ _minWidth(this.prefixIcon, height)
+ _minWidth(this.prefix, height)
+ Math.Max(_minWidth(this.input, height), _minWidth(this.hint, height))
+ Mathf.Max(_minWidth(this.input, height), _minWidth(this.hint, height))
+ _minWidth(this.suffix, height)
+ _minWidth(this.suffixIcon, height)
+ this.contentPadding.right;

+ this.contentPadding.left
+ _maxWidth(this.prefixIcon, height)
+ _maxWidth(this.prefix, height)
+ Math.Max(_maxWidth(this.input, height), _maxWidth(this.hint, height))
+ Mathf.Max(_maxWidth(this.input, height), _maxWidth(this.hint, height))
+ _maxWidth(this.suffix, height)
+ _maxWidth(this.suffixIcon, height)
+ this.contentPadding.right;

continue;
}
height = Math.Max(_minHeight(box, width), height);
height = Mathf.Max(_minHeight(box, width), height);
}
return height;

this.decoration.borderGap.start = labelX + this.label.size.width;
break;
case TextDirection.ltr:
// The value of _InputBorderGap.start is relative to the origin of the
// _BorderContainer which is inset by the icon"s width.
this.decoration.borderGap.start = labelX - _boxSize(this.icon).width;
break;
}

float dx;
switch (this.textDirection) {
case TextDirection.rtl:
dx = labelOffset.dx + this.label.size.width * (1.0f - scale); // origin is on the right
dx = labelOffset.dx + this.label.size.width * (1.0f - scale);
dx = labelOffset.dx; // origin on the left
dx = labelOffset.dx;
break;
default:
throw new Exception("Unknown direction: " + this.textDirection);

bool isEmpty = false,
Widget child = null
) : base(key: key) {
this.decoration = decoration;
this.baseStyle = baseStyle;
this.textAlign = textAlign;
this.isFocused = isFocused;
this.isEmpty = isEmpty;
this.child = child;
}
public readonly InputDecoration decoration;

public readonly TextAlign textAlign;
public readonly TextAlign? textAlign;
public readonly bool isFocused;

void _handleChange() {
this.setState(() => {
// The _floatingLabelController"s value has changed.
});
}

}
}
TextAlign textAlign {
TextAlign? textAlign {
get { return this.widget.textAlign; }
}

}
Color _getFillColor(ThemeData themeData) {
if (this.decoration.filled != true) // filled == null same as filled == false
if (this.decoration.filled != true)
{
return Colors.transparent;
}

}
// dark theme: 10% white (enabled), 5% white (disabled)
// light theme: 4% black (enabled), 2% black (disabled)
Color darkEnabled = new Color(0x1AFFFFFF);
Color darkDisabled = new Color(0x0DFFFFFF);
Color lightEnabled = new Color(0x0A000000);

);
Color activeColor = this._getActiveColor(themeData);
bool decorationIsDense = this.decoration.isDense == true; // isDense == null, same as false
bool decorationIsDense = this.decoration.isDense == true;
float iconSize = decorationIsDense ? 18.0f : 24.0f;
Color iconColor = this.isFocused ? activeColor : this._getDefaultIconColor(themeData);

floatingLabelHeight =
(4.0f + 0.75f * inlineLabelStyle.fontSize) * MediaQuery.textScaleFactorOf(context);
if (this.decoration.filled == true) {
// filled == null same as filled == false
contentPadding = decorationContentPadding ?? (decorationIsDense
? EdgeInsets.fromLTRB(12.0f, 8.0f, 12.0f, 8.0f)
: EdgeInsets.fromLTRB(12.0f, 12.0f, 12.0f, 12.0f));

D.assert(isDense != null);
D.assert(isCollapsed != null);
D.assert(filled != null);
this.labelStyle = labelStyle;
this.helperStyle = helperStyle;
this.hintStyle = hintStyle;
this.errorStyle = errorStyle;
this.errorMaxLines = errorMaxLines;
this.hasFloatingPlaceholder = hasFloatingPlaceholder;
this.isDense = isDense;
this.contentPadding = contentPadding;
this.isCollapsed = isCollapsed;
this.prefixStyle = prefixStyle;
this.suffixStyle = suffixStyle;
this.counterStyle = counterStyle;
this.filled = filled;
this.fillColor = fillColor;
this.errorBorder = errorBorder;
this.focusedBorder = focusedBorder;
this.focusedErrorBorder = focusedErrorBorder;
this.disabledBorder = disabledBorder;
this.enabledBorder = enabledBorder;
this.border = border;
}
public readonly TextStyle labelStyle;

public readonly TextStyle errorStyle;
public readonly int errorMaxLines;
public readonly int? errorMaxLines;
public readonly bool hasFloatingPlaceholder;
public readonly bool? hasFloatingPlaceholder;
public readonly bool isDense;
public readonly bool? isDense;
public readonly bool isCollapsed;
public readonly bool? isCollapsed;
public readonly TextStyle prefixStyle;

public readonly bool filled;
public readonly bool? filled;
public readonly Color fillColor;

defaultValue: defaultTheme.hintStyle));
properties.add(new DiagnosticsProperty<TextStyle>("errorStyle", this.errorStyle,
defaultValue: defaultTheme.errorStyle));
properties.add(new DiagnosticsProperty<int>("errorMaxLines", this.errorMaxLines,
properties.add(new DiagnosticsProperty<int?>("errorMaxLines", this.errorMaxLines,
properties.add(new DiagnosticsProperty<bool>("hasFloatingPlaceholder", this.hasFloatingPlaceholder,
properties.add(new DiagnosticsProperty<bool?>("hasFloatingPlaceholder", this.hasFloatingPlaceholder,
properties.add(new DiagnosticsProperty<bool>("isDense", this.isDense, defaultValue: defaultTheme.isDense));
properties.add(new DiagnosticsProperty<bool?>("isDense", this.isDense, defaultValue: defaultTheme.isDense));
properties.add(new DiagnosticsProperty<bool>("isCollapsed", this.isCollapsed,
properties.add(new DiagnosticsProperty<bool?>("isCollapsed", this.isCollapsed,
defaultValue: defaultTheme.isCollapsed));
properties.add(new DiagnosticsProperty<TextStyle>("prefixStyle", this.prefixStyle,
defaultValue: defaultTheme.prefixStyle));

defaultValue: defaultTheme.counterStyle));
properties.add(new DiagnosticsProperty<bool>("filled", this.filled, defaultValue: defaultTheme.filled));
properties.add(new DiagnosticsProperty<bool?>("filled", this.filled, defaultValue: defaultTheme.filled));
properties.add(new DiagnosticsProperty<Color>("fillColor", this.fillColor,
defaultValue: defaultTheme.fillColor));
properties.add(new DiagnosticsProperty<InputBorder>("errorBorder", this.errorBorder,

781
Runtime/material/outline_button.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
class OutlineButtonConstants {

}
public class OutlineButton : MaterialButton {
public OutlineButton(
Key key = null,
VoidCallback onPressed = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
BorderSide borderSide = null,
Color disabledBorderColor = null,
Color highlightedBorderColor = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
Widget child = null
) :
base(
key: key,
onPressed: onPressed,
textTheme: textTheme,
textColor: textColor,
disabledTextColor: disabledTextColor,
color: color,
highlightColor: highlightColor,
splashColor: splashColor,
highlightElevation: highlightElevation,
padding: padding,
shape: shape,
clipBehavior: clipBehavior,
child: child
) {
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(onPressed != null);
this.highlightedBorderColor = highlightedBorderColor;
this.disabledBorderColor = disabledBorderColor;
this.borderSide = borderSide;
}
public OutlineButton(
Key key = null,
VoidCallback onPressed = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
BorderSide borderSide = null,
Color disabledBorderColor = null,
Color highlightedBorderColor = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
Widget child = null
) :
base(
key: key,
onPressed: onPressed,
textTheme: textTheme,
textColor: textColor,
disabledTextColor: disabledTextColor,
color: color,
highlightColor: highlightColor,
splashColor: splashColor,
highlightElevation: highlightElevation,
padding: padding,
shape: shape,
clipBehavior: clipBehavior,
child: child
) {
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(onPressed != null);
this.highlightedBorderColor = highlightedBorderColor;
this.disabledBorderColor = disabledBorderColor;
this.borderSide = borderSide;
}
public static OutlineButton icon(
Key key = null,
VoidCallback onPressed = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
Color highlightedBorderColor = null,
Color disabledBorderColor = null,
BorderSide borderSide = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
Widget icon = null,
Widget label = null
) {
public static OutlineButton icon(
Key key = null,
VoidCallback onPressed = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
Color highlightedBorderColor = null,
Color disabledBorderColor = null,
BorderSide borderSide = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
Widget icon = null,
Widget label = null
) {
key,
onPressed,
textTheme,
textColor,
disabledTextColor,
color,
highlightColor,
splashColor,
highlightElevation,
highlightedBorderColor,
disabledBorderColor,
borderSide,
padding,
shape,
clipBehavior,
icon,
label
);
key,
onPressed,
textTheme,
textColor,
disabledTextColor,
color,
highlightColor,
splashColor,
highlightElevation,
highlightedBorderColor,
disabledBorderColor,
borderSide,
padding,
shape,
clipBehavior,
icon,
label
);
public readonly Color highlightedBorderColor;
public readonly Color highlightedBorderColor;
public readonly Color disabledBorderColor;
public readonly Color disabledBorderColor;
public readonly BorderSide borderSide;
public readonly BorderSide borderSide;
public override Widget build(BuildContext context) {
ButtonThemeData buttonTheme = ButtonTheme.of(context);
return new _OutlineButton(
onPressed: this.onPressed,
brightness: buttonTheme.getBrightness(this),
textTheme: this.textTheme,
textColor: buttonTheme.getTextColor(this),
disabledTextColor: buttonTheme.getDisabledTextColor(this),
color: this.color,
highlightColor: buttonTheme.getHighlightColor(this),
splashColor: buttonTheme.getSplashColor(this),
highlightElevation: buttonTheme.getHighlightElevation(this),
borderSide: this.borderSide,
disabledBorderColor: this.disabledBorderColor,
highlightedBorderColor: this.highlightedBorderColor ?? buttonTheme.colorScheme.primary,
padding: buttonTheme.getPadding(this),
shape: buttonTheme.getShape(this),
clipBehavior: this.clipBehavior,
child: this.child
);
}
public override Widget build(BuildContext context) {
ButtonThemeData buttonTheme = ButtonTheme.of(context);
return new _OutlineButton(
onPressed: this.onPressed,
brightness: buttonTheme.getBrightness(this),
textTheme: this.textTheme,
textColor: buttonTheme.getTextColor(this),
disabledTextColor: buttonTheme.getDisabledTextColor(this),
color: this.color,
highlightColor: buttonTheme.getHighlightColor(this),
splashColor: buttonTheme.getSplashColor(this),
highlightElevation: buttonTheme.getHighlightElevation(this),
borderSide: this.borderSide,
disabledBorderColor: this.disabledBorderColor,
highlightedBorderColor: this.highlightedBorderColor ?? buttonTheme.colorScheme.primary,
padding: buttonTheme.getPadding(this),
shape: buttonTheme.getShape(this),
clipBehavior: this.clipBehavior,
child: this.child
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ObjectFlagProperty<VoidCallback>("onPressed", this.onPressed, ifNull: "disabled"));
properties.add(new DiagnosticsProperty<ButtonTextTheme?>("textTheme", this.textTheme, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("textColor", this.textColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("disabledTextColor", this.disabledTextColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("color", this.color, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("highlightColor", this.highlightColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("splashColor", this.splashColor, defaultValue: null));
properties.add(new DiagnosticsProperty<float?>("highlightElevation", this.highlightElevation, defaultValue: null));
properties.add(new DiagnosticsProperty<BorderSide>("borderSide", this.borderSide, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("disabledBorderColor", this.disabledBorderColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("highlightedBorderColor", this.highlightedBorderColor, defaultValue: null));
properties.add(new DiagnosticsProperty<EdgeInsets>("padding", this.padding, defaultValue: null));
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", this.shape, defaultValue: null));
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ObjectFlagProperty<VoidCallback>("onPressed", this.onPressed, ifNull: "disabled"));
properties.add(new DiagnosticsProperty<ButtonTextTheme?>("textTheme", this.textTheme, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("textColor", this.textColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("disabledTextColor", this.disabledTextColor,
defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("color", this.color, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("highlightColor", this.highlightColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("splashColor", this.splashColor, defaultValue: null));
properties.add(new DiagnosticsProperty<float?>("highlightElevation", this.highlightElevation,
defaultValue: null));
properties.add(new DiagnosticsProperty<BorderSide>("borderSide", this.borderSide, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("disabledBorderColor", this.disabledBorderColor,
defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("highlightedBorderColor", this.highlightedBorderColor,
defaultValue: null));
properties.add(new DiagnosticsProperty<EdgeInsets>("padding", this.padding, defaultValue: null));
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", this.shape, defaultValue: null));
}
public _OutlineButtonWithIcon(
Key key = null,
VoidCallback onPressed = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
Color highlightedBorderColor = null,
Color disabledBorderColor = null,
BorderSide borderSide = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
Widget icon = null,
Widget label = null
) :
base(
key: key,
onPressed: onPressed,
textTheme: textTheme,
textColor: textColor,
disabledTextColor: disabledTextColor,
color: color,
highlightColor: highlightColor,
splashColor: splashColor,
highlightElevation: highlightElevation,
disabledBorderColor: disabledBorderColor,
highlightedBorderColor: highlightedBorderColor,
borderSide: borderSide,
padding: padding,
shape: shape,
clipBehavior: clipBehavior,
child: new Row(
mainAxisSize: MainAxisSize.min,
children: new List<Widget>{
icon,
new SizedBox(width: 8.0f),
label
}
)
) {
D.assert(onPressed != null);
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(icon != null);
D.assert(label != null);
}
public _OutlineButtonWithIcon(
Key key = null,
VoidCallback onPressed = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
Color highlightedBorderColor = null,
Color disabledBorderColor = null,
BorderSide borderSide = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
Widget icon = null,
Widget label = null
) :
base(
key: key,
onPressed: onPressed,
textTheme: textTheme,
textColor: textColor,
disabledTextColor: disabledTextColor,
color: color,
highlightColor: highlightColor,
splashColor: splashColor,
highlightElevation: highlightElevation,
disabledBorderColor: disabledBorderColor,
highlightedBorderColor: highlightedBorderColor,
borderSide: borderSide,
padding: padding,
shape: shape,
clipBehavior: clipBehavior,
child: new Row(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
icon,
new SizedBox(width: 8.0f),
label
}
)
) {
D.assert(onPressed != null);
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(icon != null);
D.assert(label != null);
}
public _OutlineButton(
Key key = null,
VoidCallback onPressed = null,
Brightness? brightness = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
BorderSide borderSide = null,
Color disabledBorderColor = null,
Color highlightedBorderColor = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip? clipBehavior = Clip.none,
Widget child = null
) : base(key: key) {
D.assert(highlightElevation != null && highlightElevation >= 0.0f);
D.assert(highlightedBorderColor != null);
D.assert(this.onPressed != null);
this.onPressed = onPressed;
this.brightness = brightness;
this.textTheme = textTheme;
this.textColor = textColor;
this.disabledTextColor = disabledTextColor;
this.color = color;
this.highlightColor = highlightColor;
this.splashColor = splashColor;
this.highlightElevation = highlightElevation;
this.borderSide = borderSide;
this.disabledBorderColor = disabledBorderColor;
this.highlightedBorderColor = highlightedBorderColor;
this.padding = padding;
this.shape = shape;
this.clipBehavior = clipBehavior;
this.child = child;
}
public _OutlineButton(
Key key = null,
VoidCallback onPressed = null,
Brightness? brightness = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color highlightColor = null,
Color splashColor = null,
float? highlightElevation = null,
BorderSide borderSide = null,
Color disabledBorderColor = null,
Color highlightedBorderColor = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip? clipBehavior = Clip.none,
Widget child = null
) : base(key: key) {
D.assert(highlightElevation != null && highlightElevation >= 0.0f);
D.assert(highlightedBorderColor != null);
D.assert(this.onPressed != null);
this.onPressed = onPressed;
this.brightness = brightness;
this.textTheme = textTheme;
this.textColor = textColor;
this.disabledTextColor = disabledTextColor;
this.color = color;
this.highlightColor = highlightColor;
this.splashColor = splashColor;
this.highlightElevation = highlightElevation;
this.borderSide = borderSide;
this.disabledBorderColor = disabledBorderColor;
this.highlightedBorderColor = highlightedBorderColor;
this.padding = padding;
this.shape = shape;
this.clipBehavior = clipBehavior;
this.child = child;
}
public readonly VoidCallback onPressed;
public readonly Brightness? brightness;
public readonly ButtonTextTheme? textTheme;
public readonly Color textColor;
public readonly Color disabledTextColor;
public readonly Color color;
public readonly Color highlightColor;
public readonly Color splashColor;
public readonly float? highlightElevation;
public readonly BorderSide borderSide;
public readonly Color disabledBorderColor;
public readonly Color highlightedBorderColor;
public readonly EdgeInsets padding;
public readonly ShapeBorder shape;
public readonly Clip? clipBehavior;
public readonly Widget child;
public readonly VoidCallback onPressed;
public readonly Brightness? brightness;
public readonly ButtonTextTheme? textTheme;
public readonly Color textColor;
public readonly Color disabledTextColor;
public readonly Color color;
public readonly Color highlightColor;
public readonly Color splashColor;
public readonly float? highlightElevation;
public readonly BorderSide borderSide;
public readonly Color disabledBorderColor;
public readonly Color highlightedBorderColor;
public readonly EdgeInsets padding;
public readonly ShapeBorder shape;
public readonly Clip? clipBehavior;
public readonly Widget child;
public bool enabled {
get {
return this.onPressed != null;
}
}
public bool enabled {
get { return this.onPressed != null; }
}
public override State createState() => new _OutlineButtonState();
public override State createState() {
return new _OutlineButtonState();
}
AnimationController _controller;
Animation<float> _fillAnimation;
Animation<float> _elevationAnimation;
bool _pressed = false;
AnimationController _controller;
Animation<float> _fillAnimation;
Animation<float> _elevationAnimation;
bool _pressed = false;
public override void initState() {
base.initState();
public override void initState() {
base.initState();
this._controller = new AnimationController(
duration: OutlineButtonConstants._kPressDuration,
vsync: this
);
this._fillAnimation = new CurvedAnimation(
parent: this._controller,
curve: new Interval(0.0f, 0.5f,
curve: Curves.fastOutSlowIn
)
);
this._elevationAnimation = new CurvedAnimation(
parent: this._controller,
curve: new Interval(0.5f, 0.5f),
reverseCurve: new Interval(1.0f, 1.0f)
);
}
this._controller = new AnimationController(
duration: OutlineButtonConstants._kPressDuration,
vsync: this
);
this._fillAnimation = new CurvedAnimation(
parent: this._controller,
curve: new Interval(0.0f, 0.5f,
curve: Curves.fastOutSlowIn
)
);
this._elevationAnimation = new CurvedAnimation(
parent: this._controller,
curve: new Interval(0.5f, 0.5f),
reverseCurve: new Interval(1.0f, 1.0f)
);
}
public override void dispose() {
this._controller.dispose();
base.dispose();
}
public override void dispose() {
this._controller.dispose();
base.dispose();
}
Color _getFillColor() {
bool themeIsDark = this.widget.brightness == Brightness.dark;
Color color = this.widget.color ?? (themeIsDark
? new Color(0x00000000)
: new Color(0x00FFFFFF));
ColorTween colorTween = new ColorTween(
begin: color.withAlpha(0x00),
end: color.withAlpha(0xFF)
);
return colorTween.evaluate(this._fillAnimation);
}
Color _getFillColor() {
bool themeIsDark = this.widget.brightness == Brightness.dark;
Color color = this.widget.color ?? (themeIsDark
? new Color(0x00000000)
: new Color(0x00FFFFFF));
ColorTween colorTween = new ColorTween(
begin: color.withAlpha(0x00),
end: color.withAlpha(0xFF)
);
return colorTween.evaluate(this._fillAnimation);
}
BorderSide _getOutline() {
bool isDark = this.widget.brightness == Brightness.dark;
if (this.widget.borderSide?.style == BorderStyle.none)
return this.widget.borderSide;
BorderSide _getOutline() {
bool isDark = this.widget.brightness == Brightness.dark;
if (this.widget.borderSide?.style == BorderStyle.none) {
return this.widget.borderSide;
}
Color color = this.widget.enabled
? (this._pressed
? this.widget.highlightedBorderColor
: (this.widget.borderSide?.color ??
(isDark ? Colors.grey[600] : Colors.grey[200])))
: (this.widget.disabledBorderColor ??
(isDark ? Colors.grey[800] : Colors.grey[100]));
Color color = this.widget.enabled
? (this._pressed
? this.widget.highlightedBorderColor
: (this.widget.borderSide?.color ??
(isDark ? Colors.grey[600] : Colors.grey[200])))
: (this.widget.disabledBorderColor ??
(isDark ? Colors.grey[800] : Colors.grey[100]));
return new BorderSide(
color: color,
width: this.widget.borderSide?.width ?? 2.0f
);
}
return new BorderSide(
color: color,
width: this.widget.borderSide?.width ?? 2.0f
);
}
float _getHighlightElevation() {
return new FloatTween(
begin: 0.0f,
end: this.widget.highlightElevation ?? 2.0f
).evaluate(this._elevationAnimation);
}
float _getHighlightElevation() {
return new FloatTween(
begin: 0.0f,
end: this.widget.highlightElevation ?? 2.0f
).evaluate(this._elevationAnimation);
}
public override Widget build(BuildContext context) {
return new AnimatedBuilder(
animation: this._controller,
builder: (BuildContext _context, Widget child) => {
return new RaisedButton(
textColor: this.widget.textColor,
disabledTextColor: this.widget.disabledTextColor,
color: this._getFillColor(),
splashColor: this.widget.splashColor,
highlightColor: this.widget.highlightColor,
disabledColor: Colors.transparent,
onPressed: this.widget.onPressed,
elevation: 0.0f,
disabledElevation: 0.0f,
highlightElevation: this._getHighlightElevation(),
onHighlightChanged: (bool value) => {
this.setState(() => {
this._pressed = value;
if (value)
this._controller.forward();
else
this._controller.reverse();
});
},
padding:
this.widget.padding,
shape: new _OutlineBorder(
shape: this.widget.shape,
side: this._getOutline()
),
clipBehavior:
this.widget.clipBehavior,
animationDuration: OutlineButtonConstants._kElevationDuration,
child:
this.widget.child
public override Widget build(BuildContext context) {
return new AnimatedBuilder(
animation: this._controller,
builder: (BuildContext _context, Widget child) => {
return new RaisedButton(
textColor: this.widget.textColor,
disabledTextColor: this.widget.disabledTextColor,
color: this._getFillColor(),
splashColor: this.widget.splashColor,
highlightColor: this.widget.highlightColor,
disabledColor: Colors.transparent,
onPressed: this.widget.onPressed,
elevation: 0.0f,
disabledElevation: 0.0f,
highlightElevation: this._getHighlightElevation(),
onHighlightChanged: (bool value) => {
this.setState(() => {
this._pressed = value;
if (value) {
this._controller.forward();
}
else {
this._controller.reverse();
}
});
},
padding:
this.widget.padding,
shape: new _OutlineBorder(
shape: this.widget.shape,
side: this._getOutline()
),
clipBehavior:
this.widget.clipBehavior,
animationDuration: OutlineButtonConstants._kElevationDuration,
child:
this.widget.child
);
}
}
);
}
}
public _OutlineBorder(
ShapeBorder shape,
BorderSide side
) {
D.assert(shape != null);
D.assert(side != null);
this.shape = shape;
this.side = side;
}
public _OutlineBorder(
ShapeBorder shape,
BorderSide side
) {
D.assert(shape != null);
D.assert(side != null);
this.shape = shape;
this.side = side;
}
public readonly ShapeBorder shape;
public readonly BorderSide side;
public override EdgeInsets dimensions {
get { return EdgeInsets.all(this.side.width); }
}
public override ShapeBorder scale(float t) {
return new _OutlineBorder(
shape: this.shape.scale(t),
side: this.side.scale(t)
);
}
public readonly ShapeBorder shape;
public readonly BorderSide side;
public override ShapeBorder lerpFrom(ShapeBorder a, float t) {
if (a is _OutlineBorder) {
return new _OutlineBorder(
side: BorderSide.lerp((a as _OutlineBorder).side, this.side, t),
shape: lerp((a as _OutlineBorder).shape, this.shape, t)
);
}
public override EdgeInsets dimensions {
get {
return EdgeInsets.all(this.side.width);
}
}
return base.lerpFrom(a, t);
}
public override ShapeBorder scale(float t) {
return new _OutlineBorder(
shape: this.shape.scale(t),
side: this.side.scale(t)
);
}
public override ShapeBorder lerpTo(ShapeBorder b, float t) {
if (b is _OutlineBorder) {
return new _OutlineBorder(
side: BorderSide.lerp(this.side, (b as _OutlineBorder).side, t),
shape: lerp(this.shape, (b as _OutlineBorder).shape, t)
);
}
public override ShapeBorder lerpFrom(ShapeBorder a, float t) {
D.assert(t != null);
if (a is _OutlineBorder) {
return new _OutlineBorder(
side: BorderSide.lerp((a as _OutlineBorder).side, this.side, t),
shape: lerp((a as _OutlineBorder).shape, this.shape, t)
);
return base.lerpTo(b, t);
return base.lerpFrom(a, t);
}
public override ShapeBorder lerpTo(ShapeBorder b, float t) {
D.assert(t != null);
if (b is _OutlineBorder) {
return new _OutlineBorder(
side: BorderSide.lerp(this.side, (b as _OutlineBorder).side, t),
shape: lerp(this.shape, (b as _OutlineBorder).shape, t)
);
public override Path getInnerPath(Rect rect) {
return this.shape.getInnerPath(rect.deflate(this.side.width));
return base.lerpTo(b, t);
}
public override Path getInnerPath(Rect rect) {
return this.shape.getInnerPath(rect.deflate(this.side.width));
}
public override Path getOuterPath(Rect rect) {
return this.shape.getOuterPath(rect);
}
public override Path getOuterPath(Rect rect) {
return this.shape.getOuterPath(rect);
}
public override void paint(Canvas canvas, Rect rect) {
switch (this.side.style) {
case BorderStyle.none:
break;
case BorderStyle.solid:
canvas.drawPath(this.shape.getOuterPath(rect), this.side.toPaint());
break;
}
}
public override void paint(Canvas canvas, Rect rect) {
switch (this.side.style) {
case BorderStyle.none:
break;
case BorderStyle.solid:
canvas.drawPath(this.shape.getOuterPath(rect), this.side.toPaint());
break;
public static bool operator ==(_OutlineBorder left, _OutlineBorder other) {
return left.side == other.side && left.shape == other.shape;
}
public static bool operator ==(_OutlineBorder left, _OutlineBorder other) {
return left.side == other.side && left.shape == other.shape;
}
public static bool operator !=(_OutlineBorder left, _OutlineBorder other) {
return left.side != other.side || left.shape != other.shape;
}
public static bool operator !=(_OutlineBorder left, _OutlineBorder other) {
return left.side != other.side || left.shape != other.shape;
}
public override int GetHashCode() {
return (this.shape.GetHashCode() * 397) ^ this.side.GetHashCode();
}
public override int GetHashCode() {
return (this.shape.GetHashCode() * 397) ^ this.side.GetHashCode();
}
}
}

10
Runtime/material/progress_indicator.cs


painter: new _LinearProgressIndicatorPainter(
backgroundColor: this.widget._getBackgroundColor(context),
valueColor: this.widget._getValueColor(context),
value: this.widget.value, // may be null
animationValue: animationValue, // ignored if widget.value is not null
value: this.widget.value,
animationValue: animationValue,
textDirection: textDirection
)
)

paint.strokeWidth = this.strokeWidth ?? 0.0f;
paint.style = PaintingStyle.stroke;
if (this.value == null) // Indeterminate
if (this.value == null)
{
paint.strokeCap = StrokeCap.square;
}

public readonly float? arrowheadScale;
void paintArrowhead(Canvas canvas, Size size) {
// ux, uy: a unit vector whose direction parallels the base of the arrowhead.
// (So ux, -uy points in the direction the arrowhead points.)
float arcEnd = this.arcStart + this.arcSweep ?? 0.0f;
float ux = Mathf.Cos(arcEnd);
float uy = Mathf.Sin(arcEnd);

child: new CustomPaint(
painter: new _RefreshProgressIndicatorPainter(
valueColor: this.widget._getValueColor(context),
value: null, // Draw the indeterminate progress indicator.
value: null,
headValue: headValue,
tailValue: tailValue,
stepValue: stepValue,

6
Runtime/widgets/form.cs


bool enabled = true
) : base(key: key) {
D.assert(builder != null);
this.onSaved = onSaved;
this.validator = validator;
this.builder = builder;
this.initialValue = initialValue;
this.autovalidate = autovalidate;
this.enabled = enabled;
}
public readonly FormFieldSetter<T> onSaved;

正在加载...
取消
保存