Ejemplo n.º 1
0
 public _PopupMenuRoute(
     RelativeRect position            = null,
     List <PopupMenuEntry <T> > items = null,
     T initialValue  = default,
     float?elevation = 8.0f,
     ThemeData theme = null,
     PopupMenuThemeData popupMenuTheme = null,
     string barrierLabel          = null,
     ShapeBorder shape            = null,
     Color color                  = null,
     BuildContext showMenuContext = null,
     bool?captureInheritedThemes  = null
     )
 {
     this.position               = position;
     this.items                  = items;
     this.initialValue           = initialValue;
     this.elevation              = elevation;
     this.theme                  = theme;
     this.popupMenuTheme         = popupMenuTheme;
     this.barrierLabel           = barrierLabel;
     this.shape                  = shape;
     this.color                  = color;
     this.showMenuContext        = showMenuContext;
     this.captureInheritedThemes = captureInheritedThemes;
     itemSizes = new List <Size>(new Size[items.Count]);
 }
Ejemplo n.º 2
0
 public PopupMenuTheme(
     Key key = null,
     PopupMenuThemeData data = null,
     Widget child            = null
     ) : base(key: key, child: child)
 {
     D.assert(data != null);
 }
Ejemplo n.º 3
0
        void showButtonMenu()
        {
            PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
            RenderBox          button         = (RenderBox)context.findRenderObject();
            RenderBox          overlay        = (RenderBox)Overlay.of(context).context.findRenderObject();
            RelativeRect       position       = RelativeRect.fromRect(
                Rect.fromPoints(
                    button.localToGlobal(widget.offset, ancestor: overlay),
                    button.localToGlobal(button.size.bottomRight(Offset.zero), ancestor: overlay)
                    ),
                Offset.zero & overlay.size
                );
            List <PopupMenuEntry <T> > items = widget.itemBuilder(context);

            if (items.isNotEmpty())
            {
                material_.showMenu <T>(
                    context: context,
                    elevation: widget.elevation ?? popupMenuTheme.elevation,
                    items: items,
                    initialValue: widget.initialValue,
                    position: position,
                    shape: widget.shape ?? popupMenuTheme.shape,
                    color: widget.color ?? popupMenuTheme.color,
                    captureInheritedThemes: widget.captureInheritedThemes
                    )
                .then(newValue => {
                    if (!mounted)
                    {
                        return;
                    }
                    if (newValue == null)
                    {
                        if (widget.onCanceled != null)
                        {
                            widget.onCanceled();
                        }
                        return;
                    }

                    if (widget.onSelected != null)
                    {
                        widget.onSelected((T)newValue);
                    }
                });
            }
        }
Ejemplo n.º 4
0
        public override Widget build(BuildContext context)
        {
            ThemeData          theme          = Theme.of(context);
            PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
            TextStyle          style          = widget.textStyle ?? popupMenuTheme.textStyle ?? theme.textTheme.subtitle1;

            if (!widget.enabled)
            {
                style = style.copyWith(color: theme.disabledColor);
            }

            Widget item = new AnimatedDefaultTextStyle(
                style: style,
                duration: material_.kThemeChangeDuration,
                child: new Container(
                    alignment: AlignmentDirectional.centerStart,
                    constraints: new BoxConstraints(minHeight: widget.height),
                    padding: EdgeInsets.symmetric(horizontal: material_._kMenuHorizontalPadding),
                    child: buildChild()
                    )
                );

            if (!widget.enabled)
            {
                bool isDark = theme.brightness == Brightness.dark;
                item = IconTheme.merge(
                    data: new IconThemeData(opacity: isDark ? 0.5f : 0.38f),
                    child: item
                    );
            }

            return(new InkWell(
                       onTap: widget.enabled?handleTap: (GestureTapCallback)null,
                       canRequestFocus: widget.enabled,
                       child: item
                       ));
        }
Ejemplo n.º 5
0
        public override Widget build(BuildContext context)
        {
            float              unit           = 1.0f / (route.items.Count + 1.5f);
            List <Widget>      children       = new List <Widget>();
            PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);

            for (int i = 0; i < route.items.Count; i += 1)
            {
                int             index = i;
                float           start = (index + 1) * unit;
                float           end   = (start + 1.5f * unit).clamp(0.0f, 1.0f);
                CurvedAnimation opacityCurvedAnimation = new CurvedAnimation(
                    parent: route.animation,
                    curve: new Interval(start, end)
                    );
                Widget item = route.items[index];
                if (route.initialValue != null && route.items[index].represents((T)route.initialValue))
                {
                    item = new Container(
                        color: Theme.of(context).highlightColor,
                        child: item
                        );
                }

                children.Add(
                    new _MenuItem(
                        onLayout: (Size size) => { route.itemSizes[index] = size; },
                        child: new FadeTransition(
                            opacity: opacityCurvedAnimation,
                            child: item
                            )
                        )
                    );
            }

            CurveTween opacity = new CurveTween(curve: new Interval(0.0f, 1.0f / 3.0f));
            CurveTween width   = new CurveTween(curve: new Interval(0.0f, unit));
            CurveTween height  = new CurveTween(curve: new Interval(0.0f, unit * route.items.Count));

            Widget child = new ConstrainedBox(
                constraints: new BoxConstraints(
                    minWidth: material_._kMenuMinWidth,
                    maxWidth: material_._kMenuMaxWidth
                    ),
                child: new IntrinsicWidth(
                    stepWidth: material_._kMenuWidthStep,
                    child: new SingleChildScrollView(
                        padding: EdgeInsets.symmetric(
                            vertical: material_._kMenuVerticalPadding
                            ),
                        child: new ListBody(children: children)
                        )
                    )
                );

            return(new AnimatedBuilder(
                       animation: route.animation,
                       builder: (_, builderChild) => {
                return new Opacity(
                    opacity: opacity.evaluate(route.animation),
                    child: new Material(
                        shape: route.shape ?? popupMenuTheme.shape,
                        color: route.color ?? popupMenuTheme.color,
                        type: MaterialType.card,
                        elevation: route.elevation ?? popupMenuTheme.elevation ?? 8.0f,
                        child: new Align(
                            alignment: Alignment.topRight,
                            widthFactor: width.evaluate(route.animation),
                            heightFactor: height.evaluate(route.animation),
                            child: builderChild
                            )
                        )
                    );
            },
                       child: child
                       ));
        }