3be07064f9
Keep the Material-only terminal implementation while preserving public Cupertino parameters for callers. This removes unreachable Cupertino widgets and imports without changing the Material path.
69 lines
1.8 KiB
Dart
69 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// One choice of a [TerminalMenuButton].
|
|
class TerminalChoice<T> {
|
|
const TerminalChoice(this.value, this.label, {this.checked, this.key});
|
|
final T value;
|
|
final String label;
|
|
|
|
/// Non-null draws the choice as a checkable item.
|
|
final bool? checked;
|
|
final Key? key;
|
|
}
|
|
|
|
/// An icon button opening the host's menu.
|
|
class TerminalMenuButton<T> extends StatelessWidget {
|
|
const TerminalMenuButton({
|
|
super.key,
|
|
required this.cupertino,
|
|
required this.label,
|
|
required this.icon,
|
|
required this.cupertinoIcon,
|
|
required this.choices,
|
|
required this.onSelected,
|
|
this.info,
|
|
});
|
|
|
|
final bool cupertino;
|
|
final String label;
|
|
final IconData icon;
|
|
final IconData cupertinoIcon;
|
|
final List<TerminalChoice<T>> choices;
|
|
final ValueChanged<T> onSelected;
|
|
|
|
/// A note under the choices (the terminal's shortcuts), not selectable.
|
|
final String? info;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return PopupMenuButton<T>(
|
|
tooltip: label,
|
|
icon: Icon(icon),
|
|
onSelected: onSelected,
|
|
itemBuilder: (_) => [
|
|
for (final choice in choices)
|
|
choice.checked == null
|
|
? PopupMenuItem<T>(
|
|
key: choice.key,
|
|
value: choice.value,
|
|
child: Text(choice.label),
|
|
)
|
|
: CheckedPopupMenuItem<T>(
|
|
key: choice.key,
|
|
value: choice.value,
|
|
checked: choice.checked!,
|
|
child: Text(choice.label),
|
|
),
|
|
if (info case final info?) ...[
|
|
const PopupMenuDivider(),
|
|
PopupMenuItem<T>(
|
|
key: const ValueKey('terminal-menu-info'),
|
|
enabled: false,
|
|
child: Text(info),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|