Exemple #1
0
        public override Widget buildPage(BuildContext context, Animation <float> animation,
                                         Animation <float> secondaryAnimation)
        {
            int?selectedItemIndex = null;

            if (initialValue != null)
            {
                for (int index = 0; selectedItemIndex == null && index < items.Count; index += 1)
                {
                    if (items[index].represents(initialValue))
                    {
                        selectedItemIndex = index;
                    }
                }
            }

            Widget menu = new _PopupMenu <T>(route: this);

            if (captureInheritedThemes ?? false)
            {
                menu = InheritedTheme.captureAll(showMenuContext, menu);
            }
            else
            {
                if (theme != null)
                {
                    menu = new Theme(data: theme, child: menu);
                }
            }

            return(MediaQuery.removePadding(
                       context: context,
                       removeTop: true,
                       removeBottom: true,
                       removeLeft: true,
                       removeRight: true,
                       child: new Builder(
                           builder: _ => new CustomSingleChildLayout(
                               layoutDelegate: new _PopupMenuRouteLayout(
                                   position,
                                   itemSizes,
                                   selectedItemIndex ?? 0,
                                   Directionality.of(context)
                                   ),
                               child: menu
                               ))
                       ));
        }
        public override Widget buildPage(BuildContext context, Animation <float> animation,
                                         Animation <float> secondaryAnimation)
        {
            float?selectedItemOffset = null;

            if (this.initialValue != null)
            {
                float y = PopupMenuUtils._kMenuVerticalPadding;
                foreach (PopupMenuEntry <T> entry in this.items)
                {
                    if (entry.represents((T)this.initialValue))
                    {
                        selectedItemOffset = y + entry.height / 2.0f;
                        break;
                    }

                    y += entry.height;
                }
            }

            Widget menu = new _PopupMenu <T>(route: this);

            if (this.theme != null)
            {
                menu = new Theme(data: this.theme, child: menu);
            }

            return(MediaQuery.removePadding(
                       context: context,
                       removeTop: true,
                       removeBottom: true,
                       removeLeft: true,
                       removeRight: true,
                       child: new Builder(
                           builder: _ => new CustomSingleChildLayout(
                               layoutDelegate: new _PopupMenuRouteLayout(
                                   this.position,
                                   selectedItemOffset
                                   ),
                               child: menu
                               ))
                       ));
        }