A package that provides the widget position details.
Add dependency to pubspec.yaml file
An example using it with TextField suffixIcon to show a Menu above it.
import 'package:anchored/anchored.dart';
class AnchoredTest extends StatelessWidget {
const AnchoredTest({super.key});
@override
Widget build(BuildContext context) {
return TextField(
decoration: InputDecoration(
suffixIcon: Anchored(
anchoredBuilder: (_, anchor, anchorCenter){
return IconButton(
onPressed: (){
showMenu(
context: context,
position: RelativeRect.fromLTRB(anchor.left, anchor.top, anchor.right, anchor.bottom),
items: const [
PopupMenuItem(child: Text("copy")),
PopupMenuItem(child: Text("paste")),
]
);
},
icon: const Icon(Icons.arrow_drop_down)
);
},
),
),
);
}
}