Beispiel #1
0
        public RawMaterialButton(
            Key key = null,
            VoidCallback onPressed = null,
            ValueChanged <bool> onHighlightChanged = null,
            TextStyle textStyle        = null,
            Color fillColor            = null,
            Color highlightColor       = null,
            Color splashColor          = null,
            float elevation            = 2.0f,
            float highlightElevation   = 8.0f,
            float disabledElevation    = 0.0f,
            EdgeInsets padding         = null,
            BoxConstraints constraints = null,
            ShapeBorder shape          = null,
            TimeSpan?animationDuration = null,
            Clip clipBehavior          = Clip.none,
            MaterialTapTargetSize?materialTapTargetSize = null,
            Widget child = null) : base(key: key)
        {
            D.assert(elevation >= 0.0);
            D.assert(highlightElevation >= 0.0);
            D.assert(disabledElevation >= 0.0);

            MaterialTapTargetSize _materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;

            shape       = shape ?? new RoundedRectangleBorder();
            padding     = padding ?? EdgeInsets.zero;
            constraints = constraints ?? new BoxConstraints(minWidth: 88.0f, minHeight: 36.0f);
            TimeSpan _animationDuration = animationDuration ?? Constants.kThemeChangeDuration;

            this.onPressed          = onPressed;
            this.onHighlightChanged = onHighlightChanged;
            this.textStyle          = textStyle;
            this.fillColor          = fillColor;
            this.highlightColor     = highlightColor;
            this.splashColor        = splashColor;
            this.elevation          = elevation;
            this.highlightElevation = highlightElevation;
            this.disabledElevation  = disabledElevation;
            this.padding            = padding;
            this.constraints        = constraints;
            this.shape                 = shape;
            this.animationDuration     = _animationDuration;
            this.clipBehavior          = clipBehavior;
            this.materialTapTargetSize = _materialTapTargetSize;
            this.child                 = child;
        }
Beispiel #2
0
        public override Widget build(BuildContext context)
        {
            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 backgroundColor = this.backgroundColor
                                    ?? floatingActionButtonTheme.backgroundColor
                                    ?? theme.colorScheme.secondary;
            float elevation = this.elevation
                              ?? floatingActionButtonTheme.elevation
                              ?? _defaultElevation;
            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 disabledElevation = this.disabledElevation
                                      ?? floatingActionButtonTheme.disabledElevation
                                      ?? elevation;
            float focusElevation = this.focusElevation
                                   ?? floatingActionButtonTheme.focusElevation
                                   ?? _defaultFocusElevation;
            float hoverElevation = this.hoverElevation
                                   ?? floatingActionButtonTheme.hoverElevation
                                   ?? _defaultHoverElevation;
            float highlightElevation = this.highlightElevation
                                       ?? floatingActionButtonTheme.highlightElevation
                                       ?? _defaultHighlightElevation;
            MaterialTapTargetSize materialTapTargetSize = this.materialTapTargetSize
                                                          ?? theme.materialTapTargetSize;
            TextStyle textStyle = theme.textTheme.button.copyWith(
                color: foregroundColor,
                letterSpacing: 1.2f
                );
            ShapeBorder shape = this.shape
                                ?? floatingActionButtonTheme.shape
                                ?? (isExtended ? _defaultExtendedShape : _defaultShape);

            Widget result = new RawMaterialButton(
                onPressed: onPressed,
                elevation: elevation,
                focusElevation: focusElevation,
                hoverElevation: hoverElevation,
                highlightElevation: highlightElevation,
                disabledElevation: disabledElevation,
                constraints: _sizeConstraints,
                materialTapTargetSize: materialTapTargetSize,
                fillColor: backgroundColor,
                focusColor: focusColor,
                hoverColor: hoverColor,
                splashColor: splashColor,
                textStyle: textStyle,
                shape: shape,
                clipBehavior: clipBehavior,
                focusNode: focusNode,
                autofocus: autofocus,
                child: child
                );

            if (tooltip != null)
            {
                result = new Tooltip(
                    message: tooltip,
                    child: result
                    );
            }

            if (heroTag != null)
            {
                result = new Hero(
                    tag: heroTag,
                    child: result
                    );
            }

            return(result);
        }
Beispiel #3
0
        public RawMaterialButton(
            Key key = null,
            VoidCallback onPressed = null,
            GestureLongPressCallback onLongPress   = null,
            ValueChanged <bool> onHighlightChanged = null,
            TextStyle textStyle         = null,
            Color fillColor             = null,
            Color focusColor            = null,
            Color hoverColor            = null,
            Color highlightColor        = null,
            Color splashColor           = null,
            float elevation             = 2.0f,
            float focusElevation        = 4.0f,
            float hoverElevation        = 4.0f,
            float highlightElevation    = 8.0f,
            float disabledElevation     = 0.0f,
            EdgeInsetsGeometry padding  = null,
            VisualDensity visualDensity = null,
            BoxConstraints constraints  = null,
            ShapeBorder shape           = null,
            TimeSpan?animationDuration  = null,
            Clip clipBehavior           = Clip.none,
            FocusNode focusNode         = null,
            bool autofocus = false,
            MaterialTapTargetSize?materialTapTargetSize = null,
            Widget child        = null,
            bool enableFeedback = true) : base(key: key)
        {
            D.assert(elevation >= 0.0f);
            D.assert(focusElevation >= 0.0f);
            D.assert(focusElevation >= 0.0f);
            D.assert(highlightElevation >= 0.0f);
            D.assert(disabledElevation >= 0.0f);

            MaterialTapTargetSize _materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;

            shape         = shape ?? new RoundedRectangleBorder();
            visualDensity = visualDensity ?? new VisualDensity();
            padding       = padding ?? EdgeInsets.zero;
            constraints   = constraints ?? new BoxConstraints(minWidth: 88.0f, minHeight: 36.0f);
            TimeSpan _animationDuration = animationDuration ?? material_.kThemeChangeDuration;

            this.onPressed          = onPressed;
            this.onLongPress        = onLongPress;
            this.onHighlightChanged = onHighlightChanged;
            this.textStyle          = textStyle;
            this.fillColor          = fillColor;
            this.focusColor         = focusColor;
            this.hoverColor         = hoverColor;
            this.highlightColor     = highlightColor;
            this.splashColor        = splashColor;
            this.elevation          = elevation;
            this.focusElevation     = focusElevation;
            this.hoverElevation     = hoverElevation;
            this.highlightElevation = highlightElevation;
            this.disabledElevation  = disabledElevation;
            this.padding            = padding;
            this.visualDensity      = visualDensity;
            this.constraints        = constraints;
            this.shape                 = shape;
            this.animationDuration     = _animationDuration;
            this.clipBehavior          = clipBehavior;
            this.focusNode             = focusNode;
            this.autofocus             = autofocus;
            this.enableFeedback        = enableFeedback;
            this.materialTapTargetSize = _materialTapTargetSize;
            this.child                 = child;
        }
        public override Widget build(BuildContext context)
        {
            ThemeData theme = Theme.of(context);
            FloatingActionButtonThemeData floatingActionButtonTheme = theme.floatingActionButtonTheme;
            Color backgroundColor = this.backgroundColor
                                    ?? floatingActionButtonTheme.backgroundColor
                                    ?? theme.colorScheme.secondary;
            Color foregroundColor = this.foregroundColor
                                    ?? floatingActionButtonTheme.foregroundColor
                                    ?? theme.accentIconTheme.color
                                    ?? theme.colorScheme.onSecondary;

            float elevation = this.elevation
                              ?? floatingActionButtonTheme.elevation
                              ?? _defaultElevation;
            float disabledElevation = this.disabledElevation
                                      ?? floatingActionButtonTheme.disabledElevation
                                      ?? elevation;
            float highlightElevation = this.highlightElevation
                                       ?? floatingActionButtonTheme.highlightElevation
                                       ?? _defaultHighlightElevation;
            MaterialTapTargetSize materialTapTargetSize = this.materialTapTargetSize
                                                          ?? theme.materialTapTargetSize;
            TextStyle textStyle = theme.accentTextTheme.button.copyWith(
                color: foregroundColor,
                letterSpacing: 1.2f
                );
            ShapeBorder shape = this.shape
                                ?? floatingActionButtonTheme.shape
                                ?? (this.isExtended ? this._defaultExtendedShape : this._defaultShape);

            Widget result = null;

            if (this.child != null)
            {
                result = IconTheme.merge(
                    data: new IconThemeData(
                        color: foregroundColor),
                    child: this.child
                    );
            }

            result = new RawMaterialButton(
                onPressed: this.onPressed,
                elevation: elevation,
                highlightElevation: highlightElevation,
                disabledElevation: disabledElevation,
                constraints: this._sizeConstraints,
                materialTapTargetSize: materialTapTargetSize,
                fillColor: backgroundColor,
                textStyle: textStyle,
                shape: shape,
                clipBehavior: this.clipBehavior,
                child: result);

            if (this.tooltip != null)
            {
                result = new Tooltip(
                    message: this.tooltip,
                    child: result);
            }

            if (this.heroTag != null)
            {
                result = new Hero(
                    tag: this.heroTag,
                    child: result);
            }

            return(result);
        }