从下面的代码中了解关于下拉的基本概念
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: Center(
child: MyStatefulWidget(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
GlobalKey menuKey = GlobalKey();
showMenus(BuildContext context) async {
final render = menuKey.currentContext!.findRenderObject() as RenderBox;
await showMenu(
context: context,
position: RelativeRect.fromLTRB(
render.localToGlobal(Offset.zero).dx,
render.localToGlobal(Offset.zero).dy + 50,
double.infinity,
double.infinity),
items: [
PopupMenuItem(
child: Text("Create a website"),
),
PopupMenuItem(
child: Text("Top Ms commericial management"),
),
PopupMenuItem(
child: Text("Mobile inventory application"),
),
],
);
}
@override
Widget build(BuildContext context) {
return Container(
key: menuKey,
color: Colors.lightBlueAccent,
constraints: BoxConstraints(
minWidth: 100,
minHeight: 50,
),
child: MouseRegion(
onHover: (event) => showMenus(context),
child: Text('Solutions'),
),
);
}
}