您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

161 行
5.5 KiB

using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class SnackBarUtils {
public const float _kSnackBarPadding = 24.0f;
public const float _kSingleLineVerticalPadding = 14.0f;
public static Color _kSnackBackground = new Color(0xFF323232);
public static TimeSpan _kSnackBarTransitionDuration = new TimeSpan(0, 0, 0, 0, 250);
public static TimeSpan _kSnackBarDisplayDuration = new TimeSpan(0, 0, 0, 0, 4000);
public static Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
public static Curve _snackBarFadeCurve = new Interval(0.72f, 1.0f, curve: Curves.fastOutSlowIn);
}
public enum SnackBarClosedReason {
action,
dismiss,
swipe,
hide,
remove,
timeout
}
public class SnackBarAction : StatefulWidget {
public SnackBarAction(
Key key = null,
Color textColor = null,
Color disabledTextColor = null,
string label = null,
VoidCallback onPressed = null
) : base(key: key) {
D.assert(label != null);
D.assert(onPressed != null);
this.textColor = textColor;
this.disabledTextColor = disabledTextColor;
this.label = label;
this.onPressed = onPressed;
}
public readonly Color textColor;
public readonly Color disabledTextColor;
public readonly string label;
public readonly VoidCallback onPressed;
public override State createState() {
return new _SnackBarActionState();
}
}
class _SnackBarActionState : State<SnackBarAction> {
bool _haveTriggeredAction = false;
void _handlePressed() {
if (this._haveTriggeredAction) {
return;
}
this.setState(() => {
this._haveTriggeredAction = true;
});
this.widget.onPressed();
Scaffold.of(this.context).hideCurrentSnackBar(reason: SnackBarClosedReason.action);
}
public override Widget build(BuildContext context) {
return new FlatButton(
onPressed: this._haveTriggeredAction ? (VoidCallback)null : this._handlePressed,
child: new Text(this.widget.label),
textColor: this.widget.textColor,
disabledTextColor: this.widget.disabledTextColor
);
}
}
public class SnackBar : StatelessWidget {
public SnackBar(
Key key = null,
Widget content = null,
Color backgroundColor = null,
SnackBarAction action = null,
TimeSpan? duration = null,
Animation<float> animation = null) : base(key: key) {
duration = duration ?? SnackBarUtils._kSnackBarDisplayDuration;
D.assert(content != null);
this.content = content;
this.backgroundColor = backgroundColor;
this.action = action;
this.duration = duration.Value;
this.animation = animation;
}
public readonly Widget content;
public readonly Color backgroundColor;
public readonly SnackBarAction action;
public readonly TimeSpan duration;
public readonly Animation<float> animation;
public override Widget build(BuildContext context) {
MediaQueryData mediaQueryData = MediaQuery.of(context);
D.assert(this.animation != null);
ThemeData theme = Theme.of(context);
ThemeData darkTheme = new ThemeData(
brightness: Brightness.dark,
accentColor: theme.accentColor,
accentColorBrightness: theme.accentColorBrightness
);
List<Widget> children = new List<Widget> {
new SizedBox(width: SnackBarUtils._kSnackBarPadding),
new Expanded(
child: new Container(
padding: EdgeInsets.symmetric(vertical: SnackBarUtils._kSingleLineVerticalPadding),
child: new DefaultTextStyle(
style: darkTheme.textTheme.subhead,
child: this.content)
)
)
};
if (this.action != null) {
children.Add(ButtonTheme.bar(
padding: EdgeInsets.symmetric(horizontal: SnackBarUtils._kSnackBarPadding),
textTheme: ButtonTextTheme.accent,
child: this.action
));
}
else {
children.Add(new SizedBox(width: SnackBarUtils._kSnackBarPadding));
}
CurvedAnimation heightAnimation = new CurvedAnimation(parent: this.animation, curve: SnackBarUtils._snackBarHeightCurve);
CurvedAnimation fadeAnimation = new CurvedAnimation(parent: this.animation, curve: SnackBarUtils._snackBarFadeCurve, reverseCurve: new Threshold(0.0f));
Widget snackbar = new SafeArea(
top: false,
child: new Row(
children: children,
crossAxisAlignment: CrossAxisAlignment.center
)
);
}
}
}