show<T> method
Implementation
@override
Future<T?> show<T>() {
return showDialog<T>(
context: context,
builder: (ctx) {
return Shortcuts(
shortcuts: {
LogicalKeySet(LogicalKeyboardKey.enter): const ActivateIntent(),
LogicalKeySet(LogicalKeyboardKey.numpadEnter): const ActivateIntent(),
},
child: Actions(
actions: {
ActivateIntent: CallbackAction<ActivateIntent>(
onInvoke: (_) {
final defaultButton = buttons.firstWhere(
(b) => b.isDefault,
orElse: () => buttons.first,
);
if (defaultButton.dismiss)
Navigator.of(ctx).pop(defaultButton.value as T);
if( defaultButton.onPressed != null)
defaultButton.onPressed!();
return null;
},
),
},
child: AlertDialog(
title: titleString != null ? Text(titleString!) : null,
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (messageString != null) Text(messageString!),
..._inputs.map(
(input) => Padding(
padding: const EdgeInsets.only(top: 8.0),
child: TextField(
controller: input.controller,
obscureText: input.obscureText,
decoration: InputDecoration(
labelText: input.label,
border: const OutlineInputBorder(),
),
onSubmitted: (_) {
final defaultButton = buttons.firstWhere(
(b) => b.isDefault,
orElse: () => buttons.first,
);
if (defaultButton.dismiss)
Navigator.of(ctx).pop(defaultButton.value as T);
if ( defaultButton.onPressed != null)
defaultButton.onPressed!();
},
),
),
),
],
),
actions: buttons
.map(
(b) => TextButton(
onPressed: () {
if (b.dismiss) Navigator.of(ctx).pop(b.value);
if (b.onPressed != null)
b.onPressed!();
},
style: b.isDefault
? TextButton.styleFrom(
backgroundColor: Theme.of(ctx).primaryColor,
foregroundColor: Colors.white,
)
: null,
child: Text(b.label),
),
)
.toList(),
),
),
);
},
);
}