import 'package:flutter/material.dart';
import 'package:robot3/widgets.dart';
void main() {
final themeData = ThemeData(
popupMenuTheme: PopupMenuThemeData(
menuPadding: EdgeInsets.zero,
color: Colors.tealAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
elevation: 0,
textStyle: TextStyle(
fontSize: 4,
color: Colors.yellow,
),
),
);
runApp(MaterialApp(theme: themeData, home: const SecondScreen()));
}
class SecondScreen extends StatelessWidget {
const SecondScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SizedBox(height: 50),
Row(
children: [
RobotButton(onClick: (text) {}),
SizedBox(width: 200),
Test01(),
],
),
],
),
);
}
}
class Test01 extends StatelessWidget {
const Test01({super.key});
@override
Widget build(BuildContext context) {
return RobotButton(
onClick: (text) {
final RenderBox button = context.findRenderObject() as RenderBox;
final Offset position = button.localToGlobal(Offset.zero);
showMenu(
menuPadding: EdgeInsets.zero,
position: RelativeRect.fromLTRB(
position.dx,
position.dy + button.size.height - 10,
position.dx + button.size.width,
0,
),
context: context,
items: buildItems(),
);
},
);
}
}
final map = {
"关于": Icons.info_outline,
"帮助": Icons.help_outline,
"问题反馈": Icons.add_comment,
};
List<PopupMenuItem<String>> buildItems() {
return map.keys
.toList()
.map(
(e) => PopupMenuItem<String>(
height: 1,
padding: EdgeInsets.zero,
value: e,
child: SizedBox(height: 20, child: Text(e)),
),
)
.toList();
}