Skip to content

Commit

Permalink
feat: Close dialogs on esc
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo committed Mar 10, 2024
1 parent f0972ce commit 69129c9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.19.0
- feat: adding `NesSectionHeader`
- feat: adding `NesIcons16.check`
- feat: Dialogs close on ESC key.

# 0.18.0
- feat: add `NesIcons.wrench`
Expand Down
83 changes: 53 additions & 30 deletions lib/src/widgets/dialogs/nes_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:nes_ui/nes_ui.dart';

class _CloseDialogIntent extends Intent {
const _CloseDialogIntent();
}

/// {@template nes_confirm_dialog}
/// A dialog that shows a child.
///
Expand Down Expand Up @@ -63,38 +68,56 @@ class NesDialog extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Align(
child: Material(
color: Colors.transparent,
child: IntrinsicWidth(
stepHeight: 0.56,
child: SizedBox.expand(
child: Stack(
clipBehavior: Clip.none,
children: [
NesContainer(
child: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: child,
),
),
),
Positioned(
right: -8,
top: -8,
child: NesButton(
type: NesButtonType.error,
onPressed: () {
Navigator.of(context).pop();
},
child: NesIcon(
size: const Size(16, 16),
iconData: NesIcons.close,
),
return Shortcuts(
shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.escape): const _CloseDialogIntent(),
},
child: Actions(
actions: <Type, Action<Intent>>{
_CloseDialogIntent: CallbackAction<_CloseDialogIntent>(
onInvoke: (intent) {
Navigator.of(context).pop();
return null;
},
),
},
child: Focus(
autofocus: true,
child: Align(
child: Material(
color: Colors.transparent,
child: IntrinsicWidth(
stepHeight: 0.56,
child: SizedBox.expand(
child: Stack(
clipBehavior: Clip.none,
children: [
NesContainer(
child: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: child,
),
),
),
Positioned(
right: -8,
top: -8,
child: NesButton(
type: NesButtonType.error,
onPressed: () {
Navigator.of(context).pop();
},
child: NesIcon(
size: const Size(16, 16),
iconData: NesIcons.close,
),
),
),
],
),
),
],
),
),
),
),
Expand Down

0 comments on commit 69129c9

Please sign in to comment.