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

274 行
9.6 KiB

using System;
using System.Collections.Generic;
using RSG;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public class Dialog : StatelessWidget {
public Dialog(
Key key = null,
Widget child = null,
TimeSpan? insetAnimationDuration = null,
Curve insetAnimationCurve = null,
ShapeBorder shape = null
) : base(key: key) {
this.child = child;
this.insetAnimationDuration = insetAnimationDuration ?? new TimeSpan(0, 0, 0, 0, 100);
this.insetAnimationCurve = Curves.decelerate;
this.shape = shape;
}
public readonly Widget child;
public readonly TimeSpan insetAnimationDuration;
public readonly Curve insetAnimationCurve;
public readonly ShapeBorder shape;
Color _getColor(BuildContext context) {
return Theme.of(context).dialogBackgroundColor;
}
public static readonly RoundedRectangleBorder _defaultDialogShape =
new RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2.0f)));
public override Widget build(BuildContext context) {
DialogTheme dialogTheme = DialogTheme.of(context);
return new AnimatedPadding(
padding: MediaQuery.of(context).viewInsets + EdgeInsets.symmetric(horizontal: 40.0f, vertical: 24.0f),
duration: this.insetAnimationDuration,
curve: this.insetAnimationCurve,
child: MediaQuery.removeViewInsets(
removeLeft: true,
removeTop: true,
removeRight: true,
removeBottom: true,
context: context,
child: new Center(
child: new ConstrainedBox(
constraints: new BoxConstraints(minWidth: 280.0f),
child: new Material(
elevation: 24.0f,
color: this._getColor(context),
type: MaterialType.card,
child: this.child,
shape: this.shape ?? dialogTheme.shape ?? _defaultDialogShape
)
)
)
)
);
}
}
public class AlertDialog : StatelessWidget {
public AlertDialog(
Key key = null,
Widget title = null,
EdgeInsets titlePadding = null,
Widget content = null,
EdgeInsets contentPadding = null,
List<Widget> actions = null,
ShapeBorder shape = null
) : base(key: key) {
this.title = title;
this.titlePadding = titlePadding;
this.content = content;
this.contentPadding = contentPadding ?? EdgeInsets.fromLTRB(24.0f, 20.0f, 24.0f, 24.0f);
this.actions = actions;
this.shape = shape;
}
public readonly Widget title;
public readonly EdgeInsets titlePadding;
public readonly Widget content;
public readonly EdgeInsets contentPadding;
public readonly List<Widget> actions;
public readonly ShapeBorder shape;
public override Widget build(BuildContext context) {
// D.assert(debugCheckHasMaterialLocalizations(context));
List<Widget> children = new List<Widget>();
if (this.title != null) {
children.Add(new Padding(
padding: this.titlePadding ??
EdgeInsets.fromLTRB(24.0f, 24.0f, 24.0f, this.content == null ? 20.0f : 0.0f),
child: new DefaultTextStyle(
style: Theme.of(context).textTheme.title,
child: this.title
)
));
}
if (this.content != null) {
children.Add(new Flexible(
child: new Padding(
padding: this.contentPadding,
child: new DefaultTextStyle(
style: Theme.of(context).textTheme.subhead,
child: this.content
)
)
));
}
if (this.actions != null) {
children.Add(ButtonTheme.bar(
child: new ButtonBar(
children: this.actions
)
));
}
Widget dialogChild = new IntrinsicWidth(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children
)
);
return new Dialog(child: dialogChild, shape: this.shape);
}
}
public class SimpleDialogOption : StatelessWidget {
public SimpleDialogOption(
Key key = null,
VoidCallback onPressed = null,
Widget child = null
) : base(key: key) {
this.onPressed = onPressed;
this.child = child;
}
public readonly VoidCallback onPressed;
public readonly Widget child;
public override Widget build(BuildContext context) {
return new InkWell(
onTap: () => this.onPressed(),
child: new Padding(
padding: EdgeInsets.symmetric(vertical: 8.0f, horizontal: 24.0f),
child: this.child
)
);
}
}
public class SimpleDialog : StatelessWidget {
public SimpleDialog(
Key key = null,
Widget title = null,
EdgeInsets titlePadding = null,
List<Widget> children = null,
EdgeInsets contentPadding = null,
ShapeBorder shape = null
) : base(key: key) {
this.title = title;
this.titlePadding = titlePadding ?? EdgeInsets.fromLTRB(24.0f, 24.0f, 24.0f, 0.0f);
this.children = children;
this.contentPadding = contentPadding ?? EdgeInsets.fromLTRB(0.0f, 12.0f, 0.0f, 16.0f);
this.shape = shape;
}
public readonly Widget title;
public readonly EdgeInsets titlePadding;
public readonly List<Widget> children;
public readonly EdgeInsets contentPadding;
public readonly ShapeBorder shape;
public override Widget build(BuildContext context) {
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
List<Widget> body = new List<Widget>();
if (this.title != null) {
body.Add(new Padding(
padding: this.titlePadding,
child: new DefaultTextStyle(
style: Theme.of(context).textTheme.title,
child: this.title
)
));
}
if (this.children != null) {
body.Add(new Flexible(
child: new SingleChildScrollView(
padding: this.contentPadding,
child: new ListBody(children: this.children)
)
));
}
Widget dialogChild = new IntrinsicWidth(
stepWidth: 56.0f,
child: new ConstrainedBox(
constraints: new BoxConstraints(minWidth: 280.0f),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: body
)
)
);
return new Dialog(child: dialogChild, shape: this.shape);
}
}
public static class DialogUtils {
static Widget _buildMaterialDialogTransitions(BuildContext context, Animation<float> animation,
Animation<float> secondaryAnimation, Widget child) {
return new FadeTransition(
opacity: new CurvedAnimation(
parent: animation,
curve: Curves.easeOut
),
child: child
);
}
public static IPromise<object> showDialog(
BuildContext context = null,
bool barrierDismissible = true,
WidgetBuilder builder = null
) {
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
return widgets.DialogUtils.showGeneralDialog(
context: context,
pageBuilder: (buildContext, animation, secondaryAnimation) => {
ThemeData theme = Theme.of(context, shadowThemeOnly: true);
Widget pageChild = new Builder(builder: builder);
return new SafeArea(
child: new Builder(
builder: (_) => theme != null
? new Theme(data: theme, child: pageChild)
: pageChild)
);
},
barrierDismissible: barrierDismissible,
barrierColor: Colors.black54,
transitionDuration: new TimeSpan(0, 0, 0, 0, 150),
transitionBuilder: _buildMaterialDialogTransitions
);
}
}
}