public _DropdownRoutePage(
     Key key = null,
     _DropdownRoute <T> route    = null,
     BoxConstraints constraints  = null,
     List <_MenuItem <T> > items = null,
     EdgeInsetsGeometry padding  = null,
     Rect buttonRect             = null,
     int?selectedIndex           = null,
     int elevation       = 0,
     ThemeData theme     = null,
     TextStyle style     = null,
     Color dropdownColor = null
     ) : base(key: key)
 {
     this.route         = route;
     this.constraints   = constraints;
     this.items         = items;
     this.padding       = padding;
     this.buttonRect    = buttonRect;
     this.selectedIndex = selectedIndex;
     this.elevation     = elevation;
     this.theme         = theme;
     this.style         = style;
     this.dropdownColor = dropdownColor;
 }
Beispiel #2
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);
                }
            });
        }
        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();
            }
        }
Beispiel #4
0
 public _DropdownMenu(
     Key key                  = null,
     EdgeInsets padding       = null,
     _DropdownRoute <T> route = null
     ) : base(key: key)
 {
     this.route   = route;
     this.padding = padding;
 }
 public _DropdownMenuRouteLayout(
     Rect buttonRect,
     _DropdownRoute <T> route    = null,
     TextDirection?textDirection = null
     )
 {
     this.buttonRect    = buttonRect;
     this.route         = route;
     this.textDirection = textDirection;
 }
 public _DropdownMenu(
     Key key                    = null,
     EdgeInsets padding         = null,
     _DropdownRoute <T> route   = null,
     Rect buttonRect            = null,
     BoxConstraints constraints = null,
     Color dropdownColor        = null
     ) : base(key: key)
 {
     this.route         = route;
     this.padding       = padding;
     this.buttonRect    = buttonRect;
     this.constraints   = constraints;
     this.dropdownColor = dropdownColor;
 }
 internal _DropdownMenuItemButton(
     Key key = null,
     _DropdownRoute <T> route   = null,
     EdgeInsets padding         = null,
     Rect buttonRect            = null,
     BoxConstraints constraints = null,
     int?itemIndex = null
     ) : base(key: key)
 {
     this.route       = route;
     this.padding     = padding;
     this.buttonRect  = buttonRect;
     this.constraints = constraints;
     this.itemIndex   = itemIndex;
 }
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            _DropdownRoute <T>    route         = widget.route;
            List <Widget>         children      = new List <Widget>();

            for (int itemIndex = 0; itemIndex < route.items.Count; ++itemIndex)
            {
                children.Add(new _DropdownMenuItemButton <T>(
                                 route: widget.route,
                                 padding: widget.padding,
                                 buttonRect: widget.buttonRect,
                                 constraints: widget.constraints,
                                 itemIndex: itemIndex
                                 ));
            }

            return(new FadeTransition(
                       opacity: _fadeOpacity,
                       child: new CustomPaint(
                           painter: new _DropdownMenuPainter(
                               color: widget.dropdownColor ?? Theme.of(context).canvasColor,
                               elevation: route.elevation,
                               selectedIndex: route.selectedIndex,
                               resize: _resize,
                               getSelectedItemOffset: () => route.getItemOffset(route.selectedIndex ?? 0)
                               ),
                           child: new Material(
                               type: MaterialType.transparency,
                               textStyle: route.style,
                               child: new ScrollConfiguration(
                                   behavior: new _DropdownScrollBehavior(),
                                   child: new Scrollbar(
                                       child: new ListView(
                                           controller: widget.route.scrollController,
                                           padding: material_.kMaterialListPadding,
                                           shrinkWrap: true,
                                           children: children
                                           )
                                       )
                                   )
                               )
                           )
                       ));
        }
 void _removeDropdownRoute()
 {
     _dropdownRoute?._dismiss();
     _dropdownRoute   = null;
     _lastOrientation = null;
 }
Beispiel #10
0
 void _removeDropdownRoute()
 {
     this._dropdownRoute?._dismiss();
     this._dropdownRoute = null;
 }
Beispiel #11
0
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            _DropdownRoute <T>    route         = this.widget.route;
            float         unit     = 0.5f / (route.items.Count + 1.5f);
            List <Widget> children = new List <Widget>();

            for (int itemIndex = 0; itemIndex < route.items.Count; ++itemIndex)
            {
                CurvedAnimation opacity;
                if (itemIndex == route.selectedIndex)
                {
                    opacity = new CurvedAnimation(parent: route.animation, curve: new Threshold(0.0f));
                }
                else
                {
                    float start = (0.5f + (itemIndex + 1) * unit).clamp(0.0f, 1.0f);
                    float end   = (start + 1.5f * unit).clamp(0.0f, 1.0f);
                    opacity = new CurvedAnimation(parent: route.animation, curve: new Interval(start, end));
                }

                var index = itemIndex;
                children.Add(new FadeTransition(
                                 opacity: opacity,
                                 child: new InkWell(
                                     child: new Container(
                                         padding: this.widget.padding,
                                         child: route.items[itemIndex]
                                         ),
                                     onTap: () => Navigator.pop(
                                         context,
                                         new _DropdownRouteResult <T>(route.items[index].value)
                                         )
                                     )
                                 ));
            }

            return(new FadeTransition(
                       opacity: this._fadeOpacity,
                       child: new CustomPaint(
                           painter: new _DropdownMenuPainter(
                               color: Theme.of(context).canvasColor,
                               elevation: route.elevation,
                               selectedIndex: route.selectedIndex,
                               resize: this._resize
                               ),
                           child: new Material(
                               type: MaterialType.transparency,
                               textStyle: route.style,
                               child: new ScrollConfiguration(
                                   behavior: new _DropdownScrollBehavior(),
                                   child: new Scrollbar(
                                       child: new ListView(
                                           controller: this.widget.route.scrollController,
                                           padding: Constants.kMaterialListPadding,
                                           itemExtent: DropdownConstants._kMenuItemHeight,
                                           shrinkWrap: true,
                                           children: children
                                           )
                                       )
                                   )
                               )
                           )
                       ));
        }