|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using uiwidgets; |
|
|
|
using Unity.UIWidgets.foundation; |
|
|
|
using Unity.UIWidgets.painting; |
|
|
|
using Unity.UIWidgets.rendering; |
|
|
|
|
|
|
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|
|
|
|
|
|
|
namespace Unity.UIWidgets.material { |
|
|
|
static class FloatActionButtonUtils { |
|
|
|
public partial class material_ { |
|
|
|
public static readonly BoxConstraints _kSizeConstraints = BoxConstraints.tightFor(width: 56.0f, height: 56.0f); |
|
|
|
|
|
|
|
public static readonly BoxConstraints _kMiniSizeConstraints = |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public class FloatingActionButton : StatelessWidget { |
|
|
|
FloatingActionButton( |
|
|
|
public FloatingActionButton( |
|
|
|
Color focusColor = null, |
|
|
|
Color hoverColor = null, |
|
|
|
Color splashColor = null, |
|
|
|
float? focusElevation = null, |
|
|
|
float? hoverElevation = null, |
|
|
|
float? highlightElevation = null, |
|
|
|
float? disabledElevation = null, |
|
|
|
VoidCallback onPressed = null, |
|
|
|
|
|
|
FocusNode focusNode = null, |
|
|
|
bool autofocus = false, |
|
|
|
D.assert(focusElevation == null || focusElevation >= 0.0); |
|
|
|
D.assert(hoverElevation == null || hoverElevation >= 0.0); |
|
|
|
D.assert(highlightElevation == null || highlightElevation >= 0.0f); |
|
|
|
D.assert(disabledElevation == null || disabledElevation >= 0.0f); |
|
|
|
heroTag = heroTag ?? new _DefaultHeroTag(); |
|
|
|
|
|
|
this.backgroundColor = backgroundColor; |
|
|
|
this.focusColor = focusColor; |
|
|
|
this.hoverColor = hoverColor; |
|
|
|
this.splashColor = splashColor; |
|
|
|
this.focusElevation = focusElevation; |
|
|
|
this.hoverElevation = hoverElevation; |
|
|
|
this.focusNode = focusNode; |
|
|
|
this.autofocus = autofocus; |
|
|
|
? FloatActionButtonUtils._kMiniSizeConstraints |
|
|
|
: FloatActionButtonUtils._kSizeConstraints); |
|
|
|
} |
|
|
|
|
|
|
|
public FloatingActionButton( |
|
|
|
Key key = null, |
|
|
|
Widget child = null, |
|
|
|
string tooltip = null, |
|
|
|
Color foregroundColor = null, |
|
|
|
Color backgroundColor = null, |
|
|
|
object heroTag = null, |
|
|
|
float elevation = 6.0f, |
|
|
|
float highlightElevation = 12.0f, |
|
|
|
VoidCallback onPressed = null, |
|
|
|
bool mini = false, |
|
|
|
ShapeBorder shape = null, |
|
|
|
Clip clipBehavior = Clip.none, |
|
|
|
MaterialTapTargetSize? materialTapTargetSize = null, |
|
|
|
bool isExtended = false |
|
|
|
) : this(key: key, |
|
|
|
child: child, |
|
|
|
tooltip: tooltip, |
|
|
|
foregroundColor: foregroundColor, |
|
|
|
backgroundColor: backgroundColor, |
|
|
|
heroTag: heroTag, |
|
|
|
elevation: elevation, |
|
|
|
highlightElevation: highlightElevation, |
|
|
|
onPressed: onPressed, |
|
|
|
mini: mini, |
|
|
|
shape: shape, |
|
|
|
clipBehavior: clipBehavior, |
|
|
|
materialTapTargetSize: materialTapTargetSize, |
|
|
|
isExtended: isExtended, |
|
|
|
_sizeConstraints: null) { |
|
|
|
? material_._kMiniSizeConstraints |
|
|
|
: material_._kSizeConstraints); |
|
|
|
} |
|
|
|
|
|
|
|
public static FloatingActionButton extended( |
|
|
|
|
|
|
Color backgroundColor = null, |
|
|
|
Color focusColor = null, |
|
|
|
Color hoverColor = null, |
|
|
|
float? focusElevation = null, |
|
|
|
float? hoverElevation = null, |
|
|
|
float? splashColor = null, |
|
|
|
float? highlightElevation = null, |
|
|
|
float? disabledElevation = null, |
|
|
|
VoidCallback onPressed = null, |
|
|
|
|
|
|
Clip clipBehavior = Clip.none, |
|
|
|
FocusNode focusNode = null, |
|
|
|
bool autofocus = false, |
|
|
|
D.assert(focusElevation == null || focusElevation >= 0.0); |
|
|
|
D.assert(hoverElevation == null || hoverElevation >= 0.0); |
|
|
|
BoxConstraints _sizeConstraints = FloatActionButtonUtils._kExtendedSizeConstraints; |
|
|
|
BoxConstraints _sizeConstraints = material_._kExtendedSizeConstraints; |
|
|
|
bool mini = false; |
|
|
|
Widget child = new _ChildOverflowBox( |
|
|
|
child: new Row( |
|
|
|
|
|
|
|
|
|
|
public readonly Color backgroundColor; |
|
|
|
|
|
|
|
public readonly Color focusColor; |
|
|
|
|
|
|
|
public readonly Color hoverColor; |
|
|
|
|
|
|
|
public readonly Color splashColor; |
|
|
|
|
|
|
|
public readonly object heroTag; |
|
|
|
|
|
|
|
public readonly VoidCallback onPressed; |
|
|
|
|
|
|
public readonly float? focusElevation; |
|
|
|
|
|
|
|
public readonly float? hoverElevation; |
|
|
|
|
|
|
|
public readonly float? highlightElevation; |
|
|
|
|
|
|
|
public readonly float? disabledElevation; |
|
|
|
|
|
|
|
|
|
|
public readonly bool isExtended; |
|
|
|
|
|
|
|
public readonly FocusNode focusNode; |
|
|
|
|
|
|
|
public readonly bool autofocus; |
|
|
|
|
|
|
|
const float _defaultFocusElevation = 8; |
|
|
|
const float _defaultHoverElevation = 10; |
|
|
|
const float _defaultElevation = 6; |
|
|
|
const float _defaultHighlightElevation = 12; |
|
|
|
readonly ShapeBorder _defaultShape = new CircleBorder(); |
|
|
|
|
|
|
ThemeData theme = Theme.of(context); |
|
|
|
FloatingActionButtonThemeData floatingActionButtonTheme = theme.floatingActionButtonTheme; |
|
|
|
|
|
|
|
if (this.foregroundColor == null && floatingActionButtonTheme.foregroundColor == null) { |
|
|
|
bool accentIsDark = theme.accentColorBrightness == Brightness.dark; |
|
|
|
Color defaultAccentIconThemeColor = accentIsDark ? Colors.white : Colors.black; |
|
|
|
if (theme.accentIconTheme.color != defaultAccentIconThemeColor) { |
|
|
|
Debug.Log( |
|
|
|
"Warning: " + |
|
|
|
"The support for configuring the foreground color of " + |
|
|
|
"FloatingActionButtons using ThemeData.accentIconTheme " + |
|
|
|
"has been deprecated. Please use ThemeData.floatingActionButtonTheme " + |
|
|
|
"instead. " |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Color foregroundColor = this.foregroundColor |
|
|
|
?? floatingActionButtonTheme.foregroundColor |
|
|
|
?? theme.colorScheme.onSecondary; |
|
|
|
Color foregroundColor = this.foregroundColor |
|
|
|
?? floatingActionButtonTheme.foregroundColor |
|
|
|
?? theme.accentIconTheme.color |
|
|
|
?? theme.colorScheme.onSecondary; |
|
|
|
|
|
|
|
Color focusColor = this.focusColor |
|
|
|
?? floatingActionButtonTheme.focusColor |
|
|
|
?? theme.focusColor; |
|
|
|
Color hoverColor = this.hoverColor |
|
|
|
?? floatingActionButtonTheme.hoverColor |
|
|
|
?? theme.hoverColor; |
|
|
|
Color splashColor = this.splashColor |
|
|
|
?? floatingActionButtonTheme.splashColor |
|
|
|
?? theme.splashColor; |
|
|
|
float focusElevation = this.focusElevation |
|
|
|
?? floatingActionButtonTheme.focusElevation |
|
|
|
?? _defaultFocusElevation; |
|
|
|
float hoverElevation = this.hoverElevation |
|
|
|
?? floatingActionButtonTheme.hoverElevation |
|
|
|
?? _defaultHoverElevation; |
|
|
|
TextStyle textStyle = theme.accentTextTheme.button.copyWith( |
|
|
|
TextStyle textStyle = theme.textTheme.button.copyWith( |
|
|
|
color: foregroundColor, |
|
|
|
letterSpacing: 1.2f |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
Widget result = null; |
|
|
|
|
|
|
|
if (child != null) { |
|
|
|
result = IconTheme.merge( |
|
|
|
data: new IconThemeData( |
|
|
|
color: foregroundColor), |
|
|
|
child: child |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
result = new RawMaterialButton( |
|
|
|
Widget result = new RawMaterialButton( |
|
|
|
focusElevation: focusElevation, |
|
|
|
hoverElevation: hoverElevation, |
|
|
|
focusColor: focusColor, |
|
|
|
hoverColor: hoverColor, |
|
|
|
splashColor: splashColor, |
|
|
|
child: result); |
|
|
|
focusNode: focusNode, |
|
|
|
autofocus: autofocus, |
|
|
|
child: child |
|
|
|
); |
|
|
|
child: result); |
|
|
|
child: result |
|
|
|
); |
|
|
|
child: result); |
|
|
|
child: result |
|
|
|
); |
|
|
|
|
|
|
|
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|
|
|
base.debugFillProperties(properties); |
|
|
|
properties.add(new ObjectFlagProperty<VoidCallback>("onPressed", onPressed, ifNull: "disabled")); |
|
|
|
properties.add(new StringProperty("tooltip", tooltip, defaultValue: null)); |
|
|
|
properties.add(new ColorProperty("foregroundColor", foregroundColor, defaultValue: null)); |
|
|
|
properties.add(new ColorProperty("backgroundColor", backgroundColor, defaultValue: null)); |
|
|
|
properties.add(new ColorProperty("focusColor", focusColor, defaultValue: null)); |
|
|
|
properties.add(new ColorProperty("hoverColor", hoverColor, defaultValue: null)); |
|
|
|
properties.add(new ColorProperty("splashColor", splashColor, defaultValue: null)); |
|
|
|
properties.add(new ObjectFlagProperty<object>("heroTag", heroTag, ifPresent: "hero")); |
|
|
|
properties.add(new FloatProperty("elevation", elevation, defaultValue: null)); |
|
|
|
properties.add(new FloatProperty("focusElevation", focusElevation, defaultValue: null)); |
|
|
|
properties.add(new FloatProperty("hoverElevation", hoverElevation, defaultValue: null)); |
|
|
|
properties.add(new FloatProperty("highlightElevation", highlightElevation, defaultValue: null)); |
|
|
|
properties.add(new FloatProperty("disabledElevation", disabledElevation, defaultValue: null)); |
|
|
|
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", shape, defaultValue: null)); |
|
|
|
properties.add(new DiagnosticsProperty<FocusNode>("focusNode", focusNode, defaultValue: null)); |
|
|
|
properties.add(new FlagProperty("isExtended", value: isExtended, ifTrue: "extended")); |
|
|
|
properties.add(new DiagnosticsProperty<MaterialTapTargetSize?>("materialTapTargetSize", |
|
|
|
materialTapTargetSize, defaultValue: null)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class _ChildOverflowBox : SingleChildRenderObjectWidget { |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public override void updateRenderObject(BuildContext context, RenderObject renderObject) { |
|
|
|
if (renderObject is _RenderChildOverflowBox renderChildOverflowBox) { |
|
|
|
renderChildOverflowBox.textDirection = Directionality.of(context); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
protected override void performLayout() { |
|
|
|
BoxConstraints constraints = this.constraints; |
|
|
|
if (child != null) { |
|
|
|
child.layout(new BoxConstraints(), parentUsesSize: true); |
|
|
|
size = new Size( |
|
|
|