浏览代码

Implement ChipDemo.

/main
Yuncong Zhang 6 年前
当前提交
bf6f0c01
共有 8 个文件被更改,包括 1086 次插入383 次删除
  1. 999
      Runtime/material/chip.cs
  2. 12
      Runtime/material/theme_data.cs
  3. 4
      Samples/UIWidgetsGallery/demo/material/chip_demo.cs
  4. 18
      Samples/UIWidgetsGallery/gallery/demos.cs
  5. 298
      Runtime/material/chip_theme.cs
  6. 3
      Runtime/material/chip_theme.cs.meta
  7. 132
      Runtime/material/circle_avatar.cs
  8. 3
      Runtime/material/circle_avatar.cs.meta

999
Runtime/material/chip.cs
文件差异内容过多而无法显示
查看文件

12
Runtime/material/theme_data.cs


IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
TabBarTheme tabBarTheme = null,
ChipThemeData chipTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,

: ThemeDataUtils._kLightThemeSplashColor);
tabBarTheme = tabBarTheme ?? new TabBarTheme();
chipTheme = chipTheme ?? ChipThemeData.fromDefaults(
secondaryColor: primaryColor,
brightness: brightness,
labelStyle: textTheme.body2
);
dialogTheme = dialogTheme ?? new DialogTheme();
D.assert(brightness != null);

IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
TabBarTheme tabBarTheme = null,
ChipThemeData chipTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,

public readonly IconThemeData accentIconTheme;
public readonly TabBarTheme tabBarTheme;
public readonly ChipThemeData chipTheme;
public readonly RuntimePlatform platform;

IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
TabBarTheme tabBarTheme = null,
ChipThemeData chimpTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,

primaryIconTheme: IconThemeData.lerp(a.primaryIconTheme, b.primaryIconTheme, t),
accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t),
tabBarTheme: TabBarTheme.lerp(a.tabBarTheme, b.tabBarTheme, t),
chipTheme: ChipThemeData.lerp(a.chipTheme, b.chipTheme, t),
platform: t < 0.5 ? a.platform : b.platform,
materialTapTargetSize: t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize,
pageTransitionsTheme: t < 0.5 ? a.pageTransitionsTheme : b.pageTransitionsTheme,

properties.add(new DiagnosticsProperty<IconThemeData>("primaryIconTheme", this.primaryIconTheme));
properties.add(new DiagnosticsProperty<IconThemeData>("accentIconTheme", this.accentIconTheme));
properties.add(new DiagnosticsProperty<TabBarTheme>("tabBarTheme", this.tabBarTheme));
properties.add(new DiagnosticsProperty<ChipThemeData>("chipTheme", this.chipTheme));
properties.add(
new DiagnosticsProperty<MaterialTapTargetSize>("materialTapTargetSize", this.materialTapTargetSize));
properties.add(

4
Samples/UIWidgetsGallery/demo/material/chip_demo.cs


}
public class ChipDemo : StatefulWidget {
const string routeName = "/material/chip";
public const string routeName = "/material/chip";
public override State createState() {
return new _ChipDemoState();

List<Widget> inputChips = this._tools.Select<string, Widget>((string name) => {
return new InputChip(
key: ValueKey<string>.key(name),
avatar: CircleAvatar(
avatar: new CircleAvatar(
backgroundImage: this._nameToAvatar(name)
),
label: new Text(this._capitalize(name)),

18
Samples/UIWidgetsGallery/gallery/demos.cs


documentationUrl: "https://docs.flutter.io/flutter/material/Card-class.html",
buildRoute: (BuildContext context) => new CardsDemo()
),
// new GalleryDemo(
// title: "Chips",
// subtitle: "Labeled with delete buttons and avatars",
// icon: GalleryIcons.chips,
// category: GalleryDemoCategory._kMaterialComponents,
// routeName: ChipDemo.routeName,
// documentationUrl: "https://docs.flutter.io/flutter/material/Chip-class.html",
// buildRoute: (BuildContext context) => ChipDemo()
// ),
new GalleryDemo(
title: "Chips",
subtitle: "Labeled with delete buttons and avatars",
icon: GalleryIcons.chips,
category: _kMaterialComponents,
routeName: ChipDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/Chip-class.html",
buildRoute: (BuildContext context) => new ChipDemo()
),
// new GalleryDemo(
// title: "Data tables",
// subtitle: "Rows and columns",

298
Runtime/material/chip_theme.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));
}
}
}

3
Runtime/material/chip_theme.cs.meta


fileFormatVersion: 2
guid: 4d46bfb5d5bb492e92f07114849df905
timeCreated: 1556165564

132
Runtime/material/circle_avatar.cs


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
)
)
)
)
);
}
}
}

3
Runtime/material/circle_avatar.cs.meta


fileFormatVersion: 2
guid: 32591e65e11049cab124c86bc8fe573c
timeCreated: 1556169017
正在加载...
取消
保存