浏览代码

Implement RaisedButton, update DividerButtonCanvas to demo it.

/main
Yuncong Zhang 6 年前
当前提交
09710dc0
共有 2 个文件被更改,包括 255 次插入69 次删除
  1. 118
      Samples/MaterialSample/DividerButtonCanvas.cs
  2. 206
      Runtime/material/raised_button.cs

118
Samples/MaterialSample/DividerButtonCanvas.cs


using Unity.UIWidgets.widgets;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.material;
using Unity.UIWidgets.ui;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;

public class _DemoAppState : State<DemoApp> {
string title = "Hello";
string subtitle = "World";
bool setTitle = true;
TextEditingController controller = new TextEditingController("");
public override Widget build(BuildContext context) {
return new Container(

child: new Center(
child: new Column(
children: new List<Widget>() {
new Text(title),
new Divider(),
new Text(subtitle),
new Divider(),
new Container(
width: 500,
decoration: new BoxDecoration(border: Border.all(new Color(0xFF00FF00), 1)),
child: new EditableText(
controller: controller,
focusNode: new FocusNode(),
style: new TextStyle(
fontSize: 18,
height: 1.5f,
color: new Color(0xFFFF89FD)),
cursorColor: Color.fromARGB(255, 0, 0, 0)
)
),
new Divider(),
new Container(
width: 100,
height: 50,
child: new CustomButton(
onPressed: () => {
setState(() => {
if(setTitle) {
title = controller.text;
} else {
subtitle = controller.text;
}
setTitle = !setTitle;
});
},
padding: EdgeInsets.all(5.0),
child: new Center(
child: new Text(setTitle? "Set Title": "Set Subtitle")
new Text(title),
new Divider(),
new Text(subtitle),
new Divider(),
new Container(
width: 500,
decoration: new BoxDecoration(border: Border.all(new Color(0xFF00FF00), 1)),
child: new EditableText(
controller: controller,
focusNode: new FocusNode(),
style: new TextStyle(
fontSize: 18,
height: 1.5f,
color: new Color(0xFFFF89FD)),
cursorColor: Color.fromARGB(255, 0, 0, 0)
)
),
new Divider(),
new Container(
width: 100,
height: 50,
child: new FlatButton(
onPressed: () => {
setState(() => {
title = controller.text;
});
},
padding: EdgeInsets.all(5.0),
child: new Center(
child: new Text("Set Title")
)
)
),
new Divider(),
new Container(
width: 100,
height: 50,
child: new RaisedButton(
onPressed: () => {
setState(() => {
subtitle = controller.text;
});
},
padding: EdgeInsets.all(5.0),
child: new Center(
child: new Text("Set Subtitle")
)
)
)
)
)
);
}
}
public class CustomButton : StatelessWidget {
public CustomButton(
Key key = null,
GestureTapCallback onPressed = null,
EdgeInsets padding = null,
Color backgroundColor = null,
Widget child = null
) : base(key: key) {
this.onPressed = onPressed;
this.padding = padding ?? EdgeInsets.all(8.0);
this.backgroundColor = backgroundColor ?? new Color(0xFFFF00FD);
this.child = child;
}
public readonly GestureTapCallback onPressed;
public readonly EdgeInsets padding;
public readonly Widget child;
public readonly Color backgroundColor;
public override Widget build(BuildContext context) {
return new GestureDetector(
onTap: this.onPressed,
child: new Container(
padding: this.padding,
color: this.backgroundColor,
child: this.child
)
);
}

206
Runtime/material/raised_button.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public class RaisedButton : MaterialButton {
public RaisedButton(
Key key = null,
VoidCallback onPressed = null,
ValueChanged<bool> onHighlightChanged = null,
ButtonTextTheme textTheme = ButtonTextTheme.normal,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color disabledColor = null,
Color highlightColor = null,
Color splashColor = null,
Brightness? colorBrightness = null,
double? elevation = null,
double? highlightElevation = null,
double? disabledElevation = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
MaterialTapTargetSize? materialTapTargetSize = null,
TimeSpan? animationDuration = null,
Widget child = null) : base(
key: key,
onPressed: onPressed,
onHighlightChanged: onHighlightChanged,
textTheme: textTheme,
textColor: textColor,
disabledTextColor: disabledTextColor,
color: color,
disabledColor: disabledColor,
highlightColor: highlightColor,
splashColor: splashColor,
colorBrightness: colorBrightness,
elevation: elevation,
highlightElevation: highlightElevation,
disabledElevation: disabledElevation,
padding: padding,
shape: shape,
clipBehavior: clipBehavior,
materialTapTargetSize: materialTapTargetSize,
animationDuration: animationDuration,
child: child) {
D.assert(elevation == null || elevation >= 0.0);
D.assert(highlightElevation == null || highlightElevation >= 0.0);
D.assert(disabledElevation == null || disabledElevation >= 0.0);
}
public static RaisedButton icon(
Key key = null,
VoidCallback onPressed = null,
ValueChanged<bool> onHighlightChanged = null,
ButtonTextTheme textTheme = ButtonTextTheme.normal,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color disabledColor = null,
Color highlightColor = null,
Color splashColor = null,
Brightness colorBrightness = Brightness.dark,
double? elevation = null,
double? highlightElevation = null,
double? disabledElevation = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
MaterialTapTargetSize materialTapTargetSize = MaterialTapTargetSize.padded,
TimeSpan? animationDuration = null,
Widget icon = null,
Widget label = null) {
return new _RaisedButtonWithIcon(
key: key,
onPressed: onPressed,
onHighlightChanged: onHighlightChanged,
textTheme: textTheme,
textColor: textColor,
disabledTextColor: disabledTextColor,
color: color,
disabledColor: disabledColor,
highlightColor: highlightColor,
splashColor: splashColor,
colorBrightness: colorBrightness,
elevation: elevation,
highlightElevation: highlightElevation,
disabledElevation: disabledElevation,
padding: padding,
shape: shape,
clipBehavior: clipBehavior,
materialTapTargetSize: materialTapTargetSize,
animationDuration: animationDuration,
icon: icon,
label: label);
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
ButtonThemeData buttonTheme = ButtonTheme.of(context);
return new RawMaterialButton(
onPressed: onPressed,
onHighlightChanged: onHighlightChanged,
clipBehavior: clipBehavior ?? Clip.none,
fillColor: buttonTheme.getFillColor(this),
textStyle: theme.textTheme.button.copyWith(color: buttonTheme.getTextColor(this)),
highlightColor: buttonTheme.getHighlightColor(this),
splashColor: buttonTheme.getSplashColor(this),
elevation: buttonTheme.getElevation(this),
highlightElevation: buttonTheme.getHighlightElevation(this),
disabledElevation: buttonTheme.getDisabledElevation(this),
padding: buttonTheme.getPadding(this),
constraints: buttonTheme.getConstraints(this),
shape: buttonTheme.getShape(this),
animationDuration: buttonTheme.getAnimationDuration(this),
materialTapTargetSize: buttonTheme.getMaterialTapTargetSize(this),
child: child
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ObjectFlagProperty<VoidCallback>("onPressed", onPressed, ifNull: "disabled"));
properties.add(new DiagnosticsProperty<ButtonTextTheme?>("textTheme", textTheme, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("textColor", textColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("disabledTextColor", disabledTextColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("color", color, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("disabledColor", disabledColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("highlightColor", highlightColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("splashColor", splashColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Brightness?>("colorBrightness", colorBrightness, defaultValue: null));
properties.add(new DiagnosticsProperty<double?>("elevation", elevation, defaultValue: null));
properties.add(new DiagnosticsProperty<double?>("highlightElevation", highlightElevation, defaultValue: null));
properties.add(new DiagnosticsProperty<double?>("disabledElevation", disabledElevation, defaultValue: null));
properties.add(new DiagnosticsProperty<EdgeInsets>("padding", padding, defaultValue: null));
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", shape, defaultValue: null));
properties.add(new DiagnosticsProperty<MaterialTapTargetSize?>("materialTapTargetSize", materialTapTargetSize, defaultValue: null));
}
}
class _RaisedButtonWithIcon : RaisedButton {
public _RaisedButtonWithIcon(
Key key = null,
VoidCallback onPressed = null,
ValueChanged<bool> onHighlightChanged = null,
ButtonTextTheme textTheme = ButtonTextTheme.normal,
Color textColor = null,
Color disabledTextColor = null,
Color color = null,
Color disabledColor = null,
Color highlightColor = null,
Color splashColor = null,
Brightness colorBrightness = Brightness.dark,
double? elevation = null,
double? highlightElevation = null,
double? disabledElevation = null,
EdgeInsets padding = null,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
MaterialTapTargetSize materialTapTargetSize = MaterialTapTargetSize.padded,
TimeSpan? animationDuration = null,
Widget icon = null,
Widget label = null) : base(
key: key,
onPressed: onPressed,
onHighlightChanged: onHighlightChanged,
textTheme: textTheme,
textColor: textColor,
disabledTextColor: disabledTextColor,
color: color,
disabledColor: disabledColor,
highlightColor: highlightColor,
splashColor: splashColor,
colorBrightness: colorBrightness,
elevation: elevation,
highlightElevation: highlightElevation,
disabledElevation: disabledElevation,
padding: padding,
shape: shape,
clipBehavior: clipBehavior,
materialTapTargetSize: materialTapTargetSize,
animationDuration: animationDuration,
child: new Row(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
icon,
new SizedBox(width: 8.0),
label
}
)) {
D.assert(elevation == null || elevation >= 0.0);
D.assert(highlightElevation == null || highlightElevation >= 0.0);
D.assert(disabledElevation == null || disabledElevation >= 0.0);
D.assert(icon != null);
D.assert(label != null);
}
}
}
正在加载...
取消
保存