Fix: LineHeight button to use MenuAnchor (#1986)

pull/1988/head v9.5.10
AtlasAutocode 9 months ago committed by GitHub
parent 0c6ade2fd8
commit b61c10af0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 128
      lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart

@ -44,6 +44,7 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
Attribute<dynamic> _selectedItem = Attribute.lineHeight; Attribute<dynamic> _selectedItem = Attribute.lineHeight;
final _menuController = MenuController();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -133,78 +134,61 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
); );
} }
return Builder( return MenuAnchor(
builder: (context) { controller: _menuController,
final isMaterial3 = Theme.of(context).useMaterial3; menuChildren: lineHeightAttributes
final child = Row( .map(
mainAxisSize: MainAxisSize.min, (e) => MenuItemButton(
mainAxisAlignment: MainAxisAlignment.spaceBetween, onPressed: () {
children: [ _onPressed(e);
Text( },
_label(_selectedItem), child: Text(_label(e)),
style: widget.options.textStyle ?? ),
TextStyle( )
fontSize: iconSize / 1.15, .toList(),
), child: Builder(
), builder: (context) {
Icon( final isMaterial3 = Theme.of(context).useMaterial3;
Icons.arrow_drop_down, final child = Row(
size: iconSize * iconButtonFactor, mainAxisSize: MainAxisSize.min,
), mainAxisAlignment: MainAxisAlignment.spaceBetween,
], children: [
); Text(
if (!isMaterial3) { _label(_selectedItem),
return RawMaterialButton( style: widget.options.textStyle ??
onPressed: () => _onDropdownButtonPressed(context), TextStyle(
child: child, fontSize: iconSize / 1.15,
); ),
} ),
return _QuillToolbarLineHeightIcon( Icon(
iconTheme: iconTheme, Icons.arrow_drop_down,
tooltip: tooltip, size: iconSize * iconButtonFactor,
onPressed: _onDropdownButtonPressed, ),
child: child, ],
); );
}, if (!isMaterial3) {
); return RawMaterialButton(
} onPressed: _onDropdownButtonPressed,
child: child,
Future<void> _onDropdownButtonPressed(BuildContext context) async { );
final position = _renderPosition(context); }
await showMenu<Attribute<dynamic>>( return _QuillToolbarLineHeightIcon(
context: context, iconTheme: iconTheme,
position: position, tooltip: tooltip,
items: lineHeightAttributes onPressed: _onDropdownButtonPressed,
.map( child: child,
(e) => PopupMenuItem( );
value: e, },
child: Text(_label(e)), ));
),
)
.toList())
.then<void>(
(value) {
if (value != null) {
_onPressed(value);
}
},
);
} }
RelativeRect _renderPosition(BuildContext context) { void _onDropdownButtonPressed() {
final size = MediaQuery.sizeOf(context); if (_menuController.isOpen) {
final overlay = Overlay.of(context).context.findRenderObject() as RenderBox; _menuController.close();
final button = context.findRenderObject() as RenderBox; } else {
final position = RelativeRect.fromRect( _menuController.open();
Rect.fromPoints( }
button.localToGlobal(const Offset(0, -65), ancestor: overlay), afterButtonPressed?.call();
button.localToGlobal(
button.size.bottomRight(Offset.zero) + const Offset(-50, 0),
ancestor: overlay),
),
Offset.zero & size * 0.40,
);
return position;
} }
} }
@ -217,7 +201,7 @@ class _QuillToolbarLineHeightIcon extends StatelessWidget {
}); });
final Row child; final Row child;
final void Function(BuildContext) onPressed; final void Function() onPressed;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final String tooltip; final String tooltip;
@ -228,7 +212,7 @@ class _QuillToolbarLineHeightIcon extends StatelessWidget {
isSelected: false, isSelected: false,
iconTheme: iconTheme, iconTheme: iconTheme,
tooltip: tooltip, tooltip: tooltip,
onPressed: () => onPressed(context), onPressed: onPressed,
); );
} }
} }

Loading…
Cancel
Save