Skip to content

Commit

Permalink
fix: Changed the specification of builder in Modal.show.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Aug 22, 2023
1 parent 6db7486 commit 3c67fc3
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/katana_ui/lib/modal/modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Modal {
Color? backgroundColor,
Color? color,
required String title,
required List<Widget> Function(VoidCallback onClose) builder,
required List<Widget> Function(ModalRef ref) builder,
bool disableBackKey = false,
bool popOnPress = true,
bool willShowRepetition = false,
Expand All @@ -68,12 +68,12 @@ class Modal {
if (overlay == null) {
return;
}
onClose() {
final ref = ModalRef._(() {
if (popOnPress) {
Navigator.of(context, rootNavigator: true).pop();
}
clicked = true;
}
});

do {
await showDialog(
Expand All @@ -93,7 +93,7 @@ class Modal {
),
backgroundColor:
backgroundColor ?? Theme.of(context).colorScheme.surface,
children: builder.call(onClose),
children: builder.call(ref),
),
);
},
Expand Down Expand Up @@ -306,3 +306,18 @@ class Modal {
return state;
}
}

/// Class for controlling Modal.
///
/// Modalをコントロールするためのクラスです。
@immutable
class ModalRef {
const ModalRef._(this._onClose);

final VoidCallback _onClose;

/// Closes the modal.
///
/// モーダルを閉じます。
void close() => _onClose();
}

0 comments on commit 3c67fc3

Please sign in to comment.