Last active
August 19, 2020 08:55
-
-
Save JuYeong0413/7861c785becdd4da8464e06a04782da1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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