You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansu_ui/lib/pop_up_menu/pop_up_menu.dart

35 lines
998 B

4 years ago
import 'package:ansu_ui/extension/num_extension.dart';
import 'package:flutter/material.dart';
/// ## 弹框菜单
///```dart
/// int result = await showASPopUpMenu<int>(
4 years ago
/// context: context,
/// items: [
/// PopupMenuItem(child: Text('test'), value: 1),
4 years ago
/// ],
/// );
4 years ago
/// ```
Future<T?> showASPopUpMenu<T>({
required BuildContext context,
required List<PopupMenuEntry<T>> items,
T? initValue,
4 years ago
}) async {
final RenderBox renderBox = context.findRenderObject() as RenderBox;
4 years ago
Size size = renderBox.size;
4 years ago
return await showMenu(
context: context,
initialValue: initValue,
4 years ago
position: RelativeRect.fromRect(
Rect.fromPoints(
renderBox.localToGlobal(Offset.zero,
ancestor: Overlay.of(context)!.context.findRenderObject()),
4 years ago
renderBox.localToGlobal(size.bottomRight(Offset.zero)),
),
Offset.zero & Overlay.of(context)!.context.size!,
4 years ago
),
items: items,
shape: RoundedRectangleBorder(borderRadius: 10.radius),
);
}