Ejemplo n.º 1
0
        public override Widget build(BuildContext context)
        {
            ButtonThemeData buttonTheme = ButtonTheme.of(context);

            return(new _OutlineButton(
                       onPressed: onPressed,
                       onLongPress: onLongPress,
                       brightness: buttonTheme.getBrightness(this),
                       textTheme: textTheme,
                       textColor: buttonTheme.getTextColor(this),
                       disabledTextColor: buttonTheme.getDisabledTextColor(this),
                       color: color,
                       focusColor: buttonTheme.getFocusColor(this),
                       hoverColor: buttonTheme.getHoverColor(this),
                       highlightColor: buttonTheme.getHighlightColor(this),
                       splashColor: buttonTheme.getSplashColor(this),
                       highlightElevation: buttonTheme.getHighlightElevation(this),
                       borderSide: borderSide,
                       disabledBorderColor: disabledBorderColor,
                       highlightedBorderColor: highlightedBorderColor ?? buttonTheme.colorScheme.primary,
                       padding: buttonTheme.getPadding(this),
                       visualDensity: visualDensity,
                       shape: buttonTheme.getShape(this),
                       clipBehavior: clipBehavior,
                       focusNode: focusNode,
                       child: child
                       ));
        }
Ejemplo n.º 2
0
        public override Widget build(BuildContext context)
        {
            ThemeData       theme       = Theme.of(context);
            ButtonThemeData buttonTheme = ButtonTheme.of(context);

            return(new RawMaterialButton(
                       onPressed: onPressed,
                       onLongPress: () => onLongPress?.Invoke(),
                       onHighlightChanged: onHighlightChanged,
                       fillColor: buttonTheme.getFillColor(this),
                       textStyle: theme.textTheme.button.copyWith(color: buttonTheme.getTextColor(this)),
                       focusColor: buttonTheme.getFocusColor(this),
                       hoverColor: buttonTheme.getHoverColor(this),
                       highlightColor: buttonTheme.getHighlightColor(this),
                       splashColor: buttonTheme.getSplashColor(this),
                       elevation: buttonTheme.getElevation(this),
                       focusElevation: buttonTheme.getFocusElevation(this),
                       hoverElevation: buttonTheme.getHoverElevation(this),
                       highlightElevation: buttonTheme.getHighlightElevation(this),
                       disabledElevation: buttonTheme.getDisabledElevation(this),
                       padding: buttonTheme.getPadding(this),
                       visualDensity: visualDensity ?? theme.visualDensity,
                       constraints: buttonTheme.getConstraints(this),
                       shape: buttonTheme.getShape(this),
                       clipBehavior: clipBehavior ?? Clip.none,
                       focusNode: focusNode,
                       autofocus: autofocus ?? false,
                       materialTapTargetSize: buttonTheme.getMaterialTapTargetSize(this),
                       animationDuration: buttonTheme.getAnimationDuration(this),
                       child: child
                       ));
        }
Ejemplo n.º 3
0
        void _handleTap()
        {
            RenderBox  itemBox    = (RenderBox)this.context.findRenderObject();
            Rect       itemRect   = itemBox.localToGlobal(Offset.zero) & itemBox.size;
            EdgeInsets menuMargin = ButtonTheme.of(this.context).alignedDropdown
                ? DropdownConstants._kAlignedMenuMargin
                : DropdownConstants._kUnalignedMenuMargin;

            D.assert(this._dropdownRoute == null);
            this._dropdownRoute = new _DropdownRoute <T>(
                items: this.widget.items,
                buttonRect: menuMargin.inflateRect(itemRect),
                padding: DropdownConstants._kMenuItemPadding,
                selectedIndex: this._selectedIndex ?? 0,
                elevation: this.widget.elevation,
                theme: Theme.of(this.context, shadowThemeOnly: true),
                style: this._textStyle,
                barrierLabel: MaterialLocalizations.of(this.context).modalBarrierDismissLabel
                );

            Navigator.push(this.context, this._dropdownRoute).Then(newValue => {
                _DropdownRouteResult <T> value = newValue as _DropdownRouteResult <T>;
                this._dropdownRoute            = null;
                if (!this.mounted || newValue == null)
                {
                    return;
                }

                if (this.widget.onChanged != null)
                {
                    this.widget.onChanged(value.result);
                }
            });
        }
Ejemplo n.º 4
0
        void _handleTap()
        {
            RenderBox          itemBox       = (RenderBox)context.findRenderObject();
            Rect               itemRect      = itemBox.localToGlobal(Offset.zero) & itemBox.size;
            TextDirection      textDirection = Directionality.of(context);
            EdgeInsetsGeometry menuMargin    = ButtonTheme.of(context).alignedDropdown
                ? material_._kAlignedMenuMargin
                : material_._kUnalignedMenuMargin;

            List <_MenuItem <T> > menuItems = new List <_MenuItem <T> >(new _MenuItem <T> [widget.items.Count]);

            for (int index = 0; index < widget.items.Count; index += 1)
            {
                var pindex = index;
                menuItems[pindex] = new _MenuItem <T>(
                    item: widget.items[pindex],
                    onLayout: (Size size) => {
                    if (_dropdownRoute == null)
                    {
                        return;
                    }

                    _dropdownRoute.itemHeights[pindex] = size.height;
                }
                    );
            }

            D.assert(_dropdownRoute == null);
            _dropdownRoute = new _DropdownRoute <T>(
                items: menuItems,
                buttonRect: menuMargin.resolve(textDirection).inflateRect(itemRect),
                padding: material_._kMenuItemPadding.resolve(textDirection),
                selectedIndex: _selectedIndex ?? 0,
                elevation: widget.elevation,
                theme: Theme.of(context, shadowThemeOnly: true),
                style: _textStyle,
                barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
                itemHeight: widget.itemHeight,
                dropdownColor: widget.dropdownColor
                );

            Navigator.push <T>(context, _dropdownRoute).then(newValue => {
                _DropdownRouteResult <T> value = newValue as _DropdownRouteResult <T>;
                _removeDropdownRoute();
                if (!mounted || newValue == null)
                {
                    return;
                }

                if (widget.onChanged != null)
                {
                    widget.onChanged(value.result);
                }
            });
            if (widget.onTap != null)
            {
                widget.onTap();
            }
        }
Ejemplo n.º 5
0
        public override Widget build(BuildContext context)
        {
            ButtonThemeData    parentButtonTheme = ButtonTheme.of(context);
            ButtonBarThemeData barTheme          = ButtonBarTheme.of(context);

            ButtonThemeData buttonTheme = parentButtonTheme.copyWith(
                textTheme: buttonTextTheme ?? barTheme?.buttonTextTheme ?? ButtonTextTheme.primary,
                minWidth: buttonMinWidth ?? barTheme?.buttonMinWidth ?? 64.0f,
                height: buttonHeight ?? barTheme?.buttonHeight ?? 36.0f,
                padding: buttonPadding ?? barTheme?.buttonPadding ?? EdgeInsets.symmetric(horizontal: 8.0f),
                alignedDropdown: buttonAlignedDropdown ?? barTheme?.buttonAlignedDropdown ?? false,
                layoutBehavior: layoutBehavior ?? barTheme?.layoutBehavior ?? ButtonBarLayoutBehavior.padded
                );

            float  paddingUnit = buttonTheme.padding.horizontal / 4.0f;
            Widget child       = ButtonTheme.fromButtonThemeData(
                data: buttonTheme,
                child: new _ButtonBarRow(
                    mainAxisAlignment: alignment ?? barTheme?.alignment ?? MainAxisAlignment.end,
                    mainAxisSize: mainAxisSize ?? barTheme?.mainAxisSize ?? MainAxisSize.max,
                    overflowDirection: overflowDirection ?? barTheme?.overflowDirection ?? VerticalDirection.down,
                    children: LinqUtils <Widget> .SelectList(children, ((Widget childWidget) => {
                return((Widget) new Padding(
                           padding: EdgeInsets.symmetric(horizontal: paddingUnit),
                           child: childWidget
                           ));
            })),
                    overflowButtonSpacing: overflowButtonSpacing
                    )
                );

            switch (buttonTheme.layoutBehavior)
            {
            case ButtonBarLayoutBehavior.padded:
                return(new Padding(
                           padding: EdgeInsets.symmetric(
                               vertical: 2.0f * paddingUnit,
                               horizontal: paddingUnit
                               ),
                           child: child
                           ));

            case ButtonBarLayoutBehavior.constrained:
                return(new Container(
                           padding: EdgeInsets.symmetric(horizontal: paddingUnit),
                           constraints: new BoxConstraints(minHeight: 52.0f),
                           alignment: Alignment.center,
                           child: child
                           ));
            }

            D.assert(false);
            return(null);
        }
Ejemplo n.º 6
0
        public override Widget build(BuildContext context)
        {
            ButtonThemeData buttonTheme = ButtonTheme.of(context);
            double          paddingUnit = buttonTheme.padding.horizontal / 4.0;
            List <Widget>   _children   = new List <Widget>();

            foreach (Widget _child in this.children)
            {
                _children.Add(
                    new Padding(
                        padding: EdgeInsets.symmetric(horizontal: paddingUnit),
                        child: _child
                        )
                    );
            }

            Widget child = new Row(
                mainAxisAlignment: this.alignment,
                mainAxisSize: this.mainAxisSize,
                children: _children
                );

            switch (buttonTheme.layoutBehavior)
            {
            case ButtonBarLayoutBehavior.padded:
                return(new Padding(
                           padding: EdgeInsets.symmetric(
                               vertical: 2.0 * paddingUnit,
                               horizontal: paddingUnit
                               ),
                           child: child
                           ));

            case ButtonBarLayoutBehavior.constrained:
                return(new Container(
                           padding: EdgeInsets.symmetric(horizontal: paddingUnit),
                           constraints: new BoxConstraints(minHeight: 52.0),
                           alignment: Alignment.center,
                           child: child
                           ));
            }

            D.assert(false);
            return(null);
        }
Ejemplo n.º 7
0
        public override Widget build(BuildContext context)
        {
            ButtonThemeData buttonTheme = ButtonTheme.of(context);

            return(new _OutlineButton(
                       onPressed: this.onPressed,
                       brightness: buttonTheme.getBrightness(this),
                       textTheme: this.textTheme,
                       textColor: buttonTheme.getTextColor(this),
                       disabledTextColor: buttonTheme.getDisabledTextColor(this),
                       color: this.color,
                       highlightColor: buttonTheme.getHighlightColor(this),
                       splashColor: buttonTheme.getSplashColor(this),
                       highlightElevation: buttonTheme.getHighlightElevation(this),
                       borderSide: this.borderSide,
                       disabledBorderColor: this.disabledBorderColor,
                       highlightedBorderColor: this.highlightedBorderColor ?? buttonTheme.colorScheme.primary,
                       padding: buttonTheme.getPadding(this),
                       shape: buttonTheme.getShape(this),
                       clipBehavior: this.clipBehavior,
                       child: this.child
                       ));
        }
Ejemplo n.º 8
0
        public override Widget build(BuildContext context)
        {
            ThemeData       theme       = Theme.of(context);
            ButtonThemeData buttonTheme = ButtonTheme.of(context);

            return(new RawMaterialButton(
                       onPressed: this.onPressed,
                       fillColor: this.color,
                       textStyle: theme.textTheme.button.copyWith(color: buttonTheme.getTextColor(this)),
                       highlightColor: this.highlightColor ?? theme.highlightColor,
                       splashColor: this.splashColor ?? theme.splashColor,
                       elevation: buttonTheme.getElevation(this),
                       highlightElevation: buttonTheme.getHighlightElevation(this),
                       padding: buttonTheme.getPadding(this),
                       constraints: buttonTheme.getConstraints(this).copyWith(
                           minWidth: this.minWidth,
                           minHeight: this.height),
                       shape: buttonTheme.shape,
                       clipBehavior: this.clipBehavior ?? Clip.none,
                       animationDuration: buttonTheme.getAnimationDuration(this),
                       child: this.child,
                       materialTapTargetSize: this.materialTapTargetSize ?? theme.materialTapTargetSize));
        }
Ejemplo n.º 9
0
        public override Widget build(BuildContext context)
        {
            ThemeData       theme       = Theme.of(context);
            ButtonThemeData buttonTheme = ButtonTheme.of(context);

            return(new RawMaterialButton(
                       onPressed: this.onPressed,
                       onHighlightChanged: this.onHighlightChanged,
                       clipBehavior: this.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: this.child
                       ));
        }
Ejemplo n.º 10
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterial(context));
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            Orientation?newOrientation = _getOrientation(context);

            _lastOrientation = _lastOrientation ?? newOrientation;
            if (newOrientation != _lastOrientation)
            {
                _removeDropdownRoute();
                _lastOrientation = newOrientation;
            }

            List <Widget> items = null;

            if (_enabled)
            {
                items = widget.selectedItemBuilder == null
                    ? new List <Widget>(widget.items)
                    : widget.selectedItemBuilder(context);
            }
            else
            {
                items = widget.selectedItemBuilder == null
                    ? new List <Widget>()
                    : widget.selectedItemBuilder(context);
            }

            int hintIndex = 0;

            if (widget.hint != null || (!_enabled && widget.disabledHint != null))
            {
                Widget displayedHint = _enabled ? widget.hint : widget.disabledHint ?? widget.hint;
                if (widget.selectedItemBuilder == null)
                {
                    displayedHint = new _DropdownMenuItemContainer(child: displayedHint);
                }

                hintIndex = items.Count;
                items.Add(new DefaultTextStyle(
                              style: _textStyle.copyWith(color: Theme.of(context).hintColor),
                              child: new IgnorePointer(
                                  child: displayedHint
                                  )
                              ));
            }

            EdgeInsetsGeometry padding = ButtonTheme.of(context).alignedDropdown
                ? material_._kAlignedButtonPadding
                : material_._kUnalignedButtonPadding;

            int    index            = _enabled ? (_selectedIndex ?? hintIndex) : hintIndex;
            Widget innerItemsWidget = null;

            if (items.isEmpty())
            {
                innerItemsWidget = new Container();
            }
            else
            {
                innerItemsWidget = new IndexedStack(
                    index: index,
                    alignment: AlignmentDirectional.centerStart,
                    children: widget.isDense
                        ? items
                        : LinqUtils <Widget> .SelectList(items, (Widget item) => {
                    return(widget.itemHeight != null
                                ? new SizedBox(height: widget.itemHeight, child: item)
                                : (Widget) new Column(mainAxisSize: MainAxisSize.min,
                                                      children: new List <Widget>()
                    {
                        item
                    }));
                }));
            }

            Icon   defaultIcon = new Icon(Icons.arrow_drop_down);
            Widget result      = new DefaultTextStyle(
                style: _textStyle,
                child: new Container(
                    decoration: _showHighlight ?? false
                        ? new BoxDecoration(
                        color: widget.focusColor ?? Theme.of(context).focusColor,
                        borderRadius: BorderRadius.all(Radius.circular(4.0f))
                        )
                        : null,
                    padding: padding,
                    height: widget.isDense ? _denseButtonHeight : null,
                    child: new Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        mainAxisSize: MainAxisSize.min,
                        children: new List <Widget> {
                widget.isExpanded ? new Expanded(child: innerItemsWidget) : (Widget)innerItemsWidget,
                new IconTheme(
                    data: new IconThemeData(
                        color: _iconColor,
                        size: widget.iconSize
                        ),
                    child: widget.icon ?? defaultIcon
                    )
            }
                        )
                    )
                );

            if (!DropdownButtonHideUnderline.at(context))
            {
                float bottom = widget.isDense || widget.itemHeight == null ? 0.0f : 8.0f;
                result = new Stack(
                    children: new List <Widget> {
                    result,
                    new Positioned(
                        left: 0.0f,
                        right: 0.0f,
                        bottom: bottom,
                        child: widget.underline ?? new Container(
                            height: 1.0f,
                            decoration: new BoxDecoration(
                                border: new Border(
                                    bottom: new BorderSide(color: new Color(0xFFBDBDBD), width: 0.0f))
                                )
                            )
                        )
                }
                    );
            }

            return(new Focus(
                       canRequestFocus: _enabled,
                       focusNode: focusNode,
                       autofocus: widget.autofocus,
                       child: new GestureDetector(
                           onTap: _enabled ? (GestureTapCallback)_handleTap : null,
                           behavior: HitTestBehavior.opaque,
                           child: result
                           )
                       ));
        }
Ejemplo n.º 11
0
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterial(context));
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));

            List <Widget> items     = this._enabled ? new List <Widget>(this.widget.items) : new List <Widget>();
            int           hintIndex = 0;

            if (this.widget.hint != null || (!this._enabled && this.widget.disabledHint != null))
            {
                Widget emplacedHint =
                    this._enabled
                        ? this.widget.hint
                        : new DropdownMenuItem <Widget>(child: this.widget.disabledHint ?? this.widget.hint);
                hintIndex = items.Count;
                items.Add(new DefaultTextStyle(
                              style: this._textStyle.copyWith(color: Theme.of(context).hintColor),
                              child: new IgnorePointer(
                                  child: emplacedHint
                                  )
                              ));
            }

            EdgeInsets padding = ButtonTheme.of(context).alignedDropdown
                ? DropdownConstants._kAlignedButtonPadding
                : DropdownConstants._kUnalignedButtonPadding;

            IndexedStack innerItemsWidget = new IndexedStack(
                index: this._enabled ? (this._selectedIndex ?? hintIndex) : hintIndex,
                alignment: Alignment.centerLeft,
                children: items
                );

            Widget result = new DefaultTextStyle(
                style: this._textStyle,
                child: new Container(
                    padding: padding,
                    height: this.widget.isDense ? this._denseButtonHeight : null,
                    child: new Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        mainAxisSize: MainAxisSize.min,
                        children: new List <Widget> {
                this.widget.isExpanded ? new Expanded(child: innerItemsWidget) : (Widget)innerItemsWidget,
                new Icon(Icons.arrow_drop_down,
                         size: this.widget.iconSize,
                         color: this._downArrowColor
                         )
            }
                        )
                    )
                );

            if (!DropdownButtonHideUnderline.at(context))
            {
                float bottom = this.widget.isDense ? 0.0f : 8.0f;
                result = new Stack(
                    children: new List <Widget> {
                    result,
                    new Positioned(
                        left: 0.0f,
                        right: 0.0f,
                        bottom: bottom,
                        child: new Container(
                            height: 1.0f,
                            decoration: new BoxDecoration(
                                border: new Border(
                                    bottom: new BorderSide(color: new Color(0xFFBDBDBD), width: 0.0f))
                                )
                            )
                        )
                }
                    );
            }

            return(new GestureDetector(
                       onTap: this._enabled ? (GestureTapCallback)this._handleTap : null,
                       behavior: HitTestBehavior.opaque,
                       child: result
                       ));
        }