コード例 #1
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();
            }
        }
コード例 #2
0
        public override Widget build(BuildContext context)
        {
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            if (route.scrollController == null)
            {
                _MenuLimits menuLimits = route.getMenuLimits(buttonRect, constraints.maxHeight, selectedIndex ?? 0);
                route.scrollController = new ScrollController(initialScrollOffset: menuLimits.scrollOffset ?? 0);
            }

            TextDirection textDirection = Directionality.of(context);
            Widget        menu          = new _DropdownMenu <T>(
                route: route,
                padding: padding.resolve(textDirection),
                buttonRect: buttonRect,
                constraints: constraints,
                dropdownColor: dropdownColor
                );

            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: (BuildContext _context) => {
                return new CustomSingleChildLayout(
                    layoutDelegate: new _DropdownMenuRouteLayout <T>(
                        buttonRect: buttonRect,
                        route: route,
                        textDirection: textDirection
                        ),
                    child: menu
                    );
            }
                           )
                       ));
        }
コード例 #3
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterial(context));
            ThemeData     theme     = Theme.of(context);
            ListTileTheme tileTheme = ListTileTheme.of(context);

            IconThemeData iconThemeData = null;

            if (leading != null || trailing != null)
            {
                iconThemeData = new IconThemeData(color: _iconColor(theme, tileTheme));
            }

            Widget leadingIcon = null;

            if (leading != null)
            {
                leadingIcon = IconTheme.merge(
                    data: iconThemeData,
                    child: leading);
            }

            TextStyle titleStyle = _titleTextStyle(theme, tileTheme);
            Widget    titleText  = new AnimatedDefaultTextStyle(
                style: titleStyle,
                duration: material_.kThemeChangeDuration,
                child: title ?? new SizedBox()
                );

            Widget    subtitleText  = null;
            TextStyle subtitleStyle = null;

            if (subtitle != null)
            {
                subtitleStyle = _subtitleTextStyle(theme, tileTheme);
                subtitleText  = new AnimatedDefaultTextStyle(
                    style: subtitleStyle,
                    duration: material_.kThemeChangeDuration,
                    child: subtitle);
            }

            Widget trailingIcon = null;

            if (trailing != null)
            {
                trailingIcon = IconTheme.merge(
                    data: iconThemeData,
                    child: trailing);
            }

            EdgeInsets    _defaultContentPadding = EdgeInsets.symmetric(horizontal: 16.0f);
            TextDirection textDirection          = Directionality.of(context);
            EdgeInsets    resolvedContentPadding =
                contentPadding?.resolve(textDirection) ?? tileTheme?.contentPadding?.resolve(textDirection) ?? _defaultContentPadding;

            return(new InkWell(
                       onTap: enabled?onTap: null,
                       onLongPress: enabled ? onLongPress : null,
                       canRequestFocus: enabled,
                       child: new SafeArea(
                           top: false,
                           bottom: false,
                           mininum: resolvedContentPadding,
                           child: new _ListTile(
                               leading: leadingIcon,
                               title: titleText,
                               subtitle: subtitleText,
                               trailing: trailingIcon,
                               isDense: _isDenseLayout(tileTheme),
                               isThreeLine: isThreeLine,
                               titleBaselineType: titleStyle.textBaseline,
                               subtitleBaselineType: subtitleStyle?.textBaseline
                               )
                           )
                       ));
        }