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 ); } ) )); }
public override Widget buildPage(BuildContext context, Animation <float> animation, Animation <float> secondaryAnimation) { D.assert(WidgetsD.debugCheckHasDirectionality(context)); float screenHeight = MediaQuery.of(context).size.height; float maxMenuHeight = screenHeight - 2.0f * DropdownConstants._kMenuItemHeight; float buttonTop = this.buttonRect.top; float buttonBottom = this.buttonRect.bottom; float topLimit = Mathf.Min(DropdownConstants._kMenuItemHeight, buttonTop); float bottomLimit = Mathf.Max(screenHeight - DropdownConstants._kMenuItemHeight, buttonBottom); float?selectedItemOffset = this.selectedIndex * DropdownConstants._kMenuItemHeight + Constants.kMaterialListPadding.top; float?menuTop = (buttonTop - selectedItemOffset) - (DropdownConstants._kMenuItemHeight - this.buttonRect.height) / 2.0f; float preferredMenuHeight = (this.items.Count * DropdownConstants._kMenuItemHeight) + Constants.kMaterialListPadding.vertical; float menuHeight = Mathf.Min(maxMenuHeight, preferredMenuHeight); float?menuBottom = menuTop + menuHeight; if (menuTop < topLimit) { menuTop = Mathf.Min(buttonTop, topLimit); } if (menuBottom > bottomLimit) { menuBottom = Mathf.Max(buttonBottom, bottomLimit); menuTop = menuBottom - menuHeight; } if (this.scrollController == null) { float scrollOffset = preferredMenuHeight > maxMenuHeight ? Mathf.Max(0.0f, selectedItemOffset ?? 0.0f - (buttonTop - (menuTop ?? 0.0f))) : 0.0f; this.scrollController = new ScrollController(initialScrollOffset: scrollOffset); } Widget menu = new _DropdownMenu <T>( route: this, padding: this.padding ); 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: (BuildContext _context) => { return new CustomSingleChildLayout( layoutDelegate: new _DropdownMenuRouteLayout <T>( buttonRect: this.buttonRect, menuTop: menuTop ?? 0.0f, menuHeight: menuHeight ), child: menu ); } ) )); }