mirror of
https://github.com/foss42/apidash.git
synced 2025-05-20 15:56:34 +08:00
Add ADPopupMenu
This commit is contained in:
74
packages/apidash_design_system/lib/widgets/popup_menu.dart
Normal file
74
packages/apidash_design_system/lib/widgets/popup_menu.dart
Normal file
@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../tokens/tokens.dart';
|
||||
|
||||
class ADPopupMenu<T> extends StatelessWidget {
|
||||
const ADPopupMenu({
|
||||
super.key,
|
||||
this.value,
|
||||
required this.values,
|
||||
this.onChanged,
|
||||
this.tooltip,
|
||||
this.width,
|
||||
this.isOutlined = false,
|
||||
});
|
||||
|
||||
final String? value;
|
||||
final Iterable<(T, String?)> values;
|
||||
final void Function(T? value)? onChanged;
|
||||
final String? tooltip;
|
||||
final double? width;
|
||||
final bool isOutlined;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double containerWidth = width ?? 220;
|
||||
var popup = PopupMenuButton<T>(
|
||||
tooltip: tooltip,
|
||||
surfaceTintColor: kColorTransparent,
|
||||
constraints: BoxConstraints(minWidth: containerWidth),
|
||||
itemBuilder: (BuildContext context) => values
|
||||
.map((item) => PopupMenuItem<T>(
|
||||
value: item.$1,
|
||||
child: Text(
|
||||
item.$2 ?? "",
|
||||
style: kTextStylePopupMenuItem,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
onSelected: onChanged,
|
||||
child: Container(
|
||||
width: containerWidth,
|
||||
padding: kP8,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
value ?? "",
|
||||
style: kTextStylePopupMenuItem,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
size: 16,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (isOutlined) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
borderRadius: kBorderRadius8,
|
||||
),
|
||||
child: popup,
|
||||
);
|
||||
}
|
||||
return popup;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
export 'button_icon.dart';
|
||||
export 'checkbox.dart';
|
||||
export 'dropdown.dart';
|
||||
export 'popup_menu.dart';
|
||||
export 'snackbar.dart';
|
||||
export 'textfield_outlined.dart';
|
||||
export 'textfield_raw.dart';
|
||||
|
Reference in New Issue
Block a user