One thing I have noticed is that neither ContextMenu, nor ContextMenuRegion, nor ContextMenuEntry have a generic.
This somewhat impairs typing MenuEntry correctly, which does have a generic.
I see that your package has taken inspiration from PopupMenu in the framework, or is at least built very similar.
It should be possible to fully type MenuEntry by giving all the mentioned classes a generic <T> as well.
Of course we then run into the question how to type MenuDivider which does not have any value that could have a generic type.
Here we can also take inspiration from the framework itself, namely the PopupMenuDivider.
This should also work for us, as the Divider can never be selected and therefore never be passed into the callback.
The Never type will also miracolously conform to the generic T. I have no idea how that works internally, but it will not throw any errors if we use it correctly.
Hi, great package, love it.
One thing I have noticed is that neither
ContextMenu
, norContextMenuRegion
, norContextMenuEntry
have a generic. This somewhat impairs typingMenuEntry
correctly, which does have a generic.I see that your package has taken inspiration from
PopupMenu
in the framework, or is at least built very similar. It should be possible to fully typeMenuEntry
by giving all the mentioned classes a generic<T>
as well.Of course we then run into the question how to type
MenuDivider
which does not have anyvalue
that could have a generic type. Here we can also take inspiration from the framework itself, namely thePopupMenuDivider
.In the framework code, we can see that
PopupMenuDivider
is simply typed<Never>
: https://github.com/flutter/flutter/blob/2e9cb0aa71/packages/flutter/lib/src/material/popup_menu.dart#L102This should also work for us, as the Divider can never be selected and therefore never be passed into the callback. The
Never
type will also miracolously conform to the genericT
. I have no idea how that works internally, but it will not throw any errors if we use it correctly.