FormMedia<TValue> class

Form for submitting images and videos. Single media can be submitted.

All media is managed by FormMediaValue.

The path to the file asset and the asset type are passed to FormMediaValue as FormMediaType, so display and save accordingly.

Describe the process when the form is tapped in the onTap field. Normally, use image_picker or file_picker to display a dialog to select a file and return the media path to onUpdate.

Implement the part that actually displays the image based on the FormMediaValue in builder.

Place under the Form that gave FormController.key, or pass FormController to form.

When FormController is passed to form, onSaved must also be passed together. The contents of onSaved will be used to save the data.

Enter the initial value given by FormController.value in initialValue.

Each time the content is changed, onChanged is executed.

When FormController.validate is executed, validation and data saving are performed.

Only when emptyErrorText is specified, emptyErrorText will be displayed as an error if the item is not specified.

Other error checking is performed by specifying validator. If a string other than Null is returned in the callback, the string is displayed as an error statement. If Null is returned, it is processed as no error.

Deactivated if enabled is false or readOnly is true.

If showOverlayIcon is set to true, the icon is displayed over the preview even after the media is selected. You can change the design of icons and overlays by specifying icon, iconSize, overlayColor, and overlayIconColor.

画像や映像を投稿するためのフォーム。単一のメディアを投稿することが可能です。

メディアはすべてFormMediaValueで管理されます。

FormMediaValueにファイルアセットへのパスとアセットのタイプがFormMediaTypeで渡されるのでそれに応じて表示や保存を行ってください。

onTapにフォームがタップされた場合の処理を記述します。通常はimage_pickerfile_pickerを用いてファイルを選択するダイアログを表示しメディアのパスをonUpdateに返すようにします。

builderFormMediaValueを元に実際に画像を表示する部分を実装してください。

FormController.keyを与えたForm配下に配置、もしくはformFormControllerを渡します。

formFormControllerを渡した場合、一緒にonSavedも渡してください。データの保存はonSavedの内容が実行されます。

initialValueFormController.valueから与えられた初期値を入力します。

内容が変更される度onChangedが実行されます。

FormController.validateが実行された場合、バリデーションとデータの保存を行ないます。

emptyErrorTextが指定されている時に限り、項目が指定されていない場合emptyErrorTextがエラーとして表示されます。

それ以外のエラーチェックはvalidatorを指定することで行ないます。 コールバック内でNull以外を返すようにするとその文字列がエラー文として表示されます。Nullの場合はエラーなしとして処理されます。

enabledfalseになる、もしくはreadOnlytrueになっている場合は非有効化されます。

showOverlayIcontrueにするとメディアが選択された後でもそのプレビューの上にアイコンを表示します。iconiconSizeoverlayColoroverlayIconColorを指定することでアイコンやオーバーレイのデザインを変更することができます。

Inheritance
Available Extensions

Constructors

FormMedia({Key? key, FormStyle? style, void onChanged(FormMediaValue? value)?, bool readOnly = false, FormController<TValue>? form, required void onTap(FormMediaRef ref)?, required Widget builder(BuildContext context, FormMediaValue value), bool showOverlayIcon = true, Color overlayColor = Colors.black38, Color overlayIconColor = Colors.white70, IconData icon = Icons.add_a_photo, double iconSize = 56.0, String? emptyErrorText, TValue onSaved(FormMediaValue value)?, String validator(FormMediaValue? value)?, FormMediaValue? initialValue, bool enabled = true, bool keepAlive = true})
Form for submitting images and videos. Single media can be submitted.

Properties

autovalidateMode AutovalidateMode
Used to enable/disable this form field auto validation and update its error text.
finalinherited
builder FormFieldBuilder<FormMediaValue>
Function that returns the widget representing this form field. It is passed the form field state as input, containing the current value and validation state of this field.
finalinherited
emptyErrorText String?
Error text. Only displayed if no characters are entered.
final
enabled bool
Whether the form is able to receive user input.
finalinherited
form FormController<TValue>?
Context for forms.
final
hashCode int
The hash code for this object.
no setterinherited
icon IconData
Additional icons or overlay icons.
final
iconSize double
Size of icon.
final
initialValue FormMediaValue?
An optional value to initialize the form field to, or null otherwise.
finalinherited
keepAlive bool
If placed in a list, whether or not it should not be discarded on scrolling.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onChanged → (void Function(FormMediaValue? value)?)
Callback to be executed each time the value is changed.
final
onSaved FormFieldSetter<FormMediaValue>?
An optional method to call with the final value when the form is saved via FormState.save.
finalinherited
onTap → (void Function(FormMediaRef ref)?)
Describe what to do when the form is tapped.
final
overlayColor Color
The foreground color of the overlay when the icon is displayed in an overlay when media is selected.
final
overlayIconColor Color
The color of the icon when the icon is displayed in an overlay when media is selected.
final
readOnly bool
If this is true, the form cannot be filled out and changed from its initial value.
final
restorationId String?
Restoration ID to save and restore the state of the form field.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showOverlayIcon bool
true if you want to show the icon in overlay when media is selected.
final
style FormStyle?
Form Style.
final
validator FormFieldValidator<FormMediaValue>?
An optional method that validates an input. Returns an error string to display if the input is invalid, or null otherwise.
finalinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _FormMediaState<TValue>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited