Fix LineHeight button

pull/1986/head
AtlasAutocode 10 months ago
parent b6b6ff97b3
commit 304edd30f5
  1. 64
      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,7 +134,19 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
); );
} }
return Builder( return MenuAnchor(
controller: _menuController,
menuChildren: lineHeightAttributes
.map(
(e) => MenuItemButton(
onPressed: () {
_onPressed(e);
},
child: Text(_label(e)),
),
)
.toList(),
child: Builder(
builder: (context) { builder: (context) {
final isMaterial3 = Theme.of(context).useMaterial3; final isMaterial3 = Theme.of(context).useMaterial3;
final child = Row( final child = Row(
@ -155,7 +168,7 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
); );
if (!isMaterial3) { if (!isMaterial3) {
return RawMaterialButton( return RawMaterialButton(
onPressed: () => _onDropdownButtonPressed(context), onPressed: _onDropdownButtonPressed,
child: child, child: child,
); );
} }
@ -166,45 +179,16 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
child: child, child: child,
); );
}, },
); ));
} }
Future<void> _onDropdownButtonPressed(BuildContext context) async { void _onDropdownButtonPressed() {
final position = _renderPosition(context); if (_menuController.isOpen) {
await showMenu<Attribute<dynamic>>( _menuController.close();
context: context, } else {
position: position, _menuController.open();
items: lineHeightAttributes
.map(
(e) => PopupMenuItem(
value: e,
child: Text(_label(e)),
),
)
.toList())
.then<void>(
(value) {
if (value != null) {
_onPressed(value);
} }
}, afterButtonPressed?.call();
);
}
RelativeRect _renderPosition(BuildContext context) {
final size = MediaQuery.sizeOf(context);
final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
final button = context.findRenderObject() as RenderBox;
final position = RelativeRect.fromRect(
Rect.fromPoints(
button.localToGlobal(const Offset(0, -65), ancestor: overlay),
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