diff --git a/packages/masamune/lib/form/form_scoped_widget.dart b/packages/masamune/lib/form/form_scoped_widget.dart index b69af267a..9430e4662 100644 --- a/packages/masamune/lib/form/form_scoped_widget.dart +++ b/packages/masamune/lib/form/form_scoped_widget.dart @@ -63,6 +63,17 @@ class FormRef implements WidgetRef { @override WidgetScopedValueRef get widget => _widgetRef.widget; + + /// When a value is being added to a form, [onAdd] is executed; when editing, [onEdit] is executed. + /// + /// フォームに値を追加しているときは[onAdd]が実行され、編集しているときは[onEdit]が実行されます。 + T? select({T Function()? onAdd, T Function(String? editId)? onEdit}) { + if (isAdding) { + return onAdd?.call(); + } else { + return onEdit?.call(editId); + } + } } /// Abstract class to implement the View portion of the form widget used to both add new and edit existing forms.