Skip to content

Instantly share code, notes, and snippets.

@JuYeong0413
Last active August 19, 2020 08:55
Show Gist options
  • Save JuYeong0413/7861c785becdd4da8464e06a04782da1 to your computer and use it in GitHub Desktop.
Save JuYeong0413/7861c785becdd4da8464e06a04782da1 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Popup Menu Test',
home: HomePage(),
));
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Popup Menu Test'),
),
body: Center(
child: PopupMenuButton(
child: Text(
'Show Menu',
style: TextStyle(fontSize: 20),
),
itemBuilder: (BuildContext context) {
final GlobalKey key = GlobalKey();
return Iterable.generate(
5, (i) =>
PopupMenuItem(
child: ListTile(
key: i == 0 ? key : null, // 첫 번째 아이템에만 key 부여
title: Text('Item $i'),
),
)
).toList();
RenderBox box = key.currentContext.findRenderObject();
final position = box.localToGlobal(Offset.zero);
double x = position.dx;
double y = position.dy;
print('$x, $y');
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment