RxFormFieldBuilder<B extends RxBlocTypeBase, T> class
RxFormFieldBuilder is a convenience widget, which makes it easier to build and update responsive form fields with reactive Streams.
It requires a state callback, which returns a Stream of values, and can emmit errors which have to be of type RxFieldException. The values and errors are provided to the builder function in order to be displayed.
If the state Stream emits an error that error is provided to the builder function in order to be displayed.
Important! - any errors emitted by the state Stream, must be of type RxFieldException. The reason for this requirement is that RxFieldException provides a value field as well as an error field, and thus the value provided to the builder is kept and not lost upon update.
It requires a showErrorState callback, which returns a Stream of boolean values which determine when it is time to show any potential errors. !The stream provided by showErrorState must never emmit an error.
A builder function is required, this is a function which gives you access to the current field state, and must return a Widget.
The field state provided to the builder function contains several useful fields: bloc, value, error and showError; reference the documentation of RxFormFieldBuilderState for more information on those fields.
You can optionally provide an RxBloc
to the bloc field, if you do
the provided bloc would be used, otherwise RxFormFieldBuilder
automatically searches for and uses the closest instance up the widget tree
of RxBloc
of type B
.
This is an example of how to make a radio button form field.
Widget build(BuildContext context) =>
RxFormFieldBuilder<ColorSelectionBlocType, ColorEnum>(
state: (bloc) => bloc.states.color,
showErrorState: (bloc) => bloc.states.showErrors,
builder: (fieldState) => Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
const Text(
'White',
),
Radio<Gender>(
value: ColorEnum.white,
groupValue: fieldState.value,
onChanged: fieldState.bloc.events.setColor,
),
],
),
Row(
children: [
const Text(
'Black',
),
Radio<Gender>(
value: ColorEnum.black,
groupValue: fieldState.value,
onChanged: fieldState.bloc.events.setColor,
),
],
),
],
),
//show errors, say for instance the user tries to save the
//changes to the form, but they forgot to select a color.
if (fieldState.showError)
Row(
children: [
Text(
fieldState.error,
),
],
),
],
),
);
This is an example of a drop down menu form field.
Widget build(BuildContext context) =>
RxFormFieldBuilder<ColorSelectionBlocType, ColorEnum>(
state: (bloc) => bloc.states.color,
showErrorState: (bloc) => bloc.states.showErrors,
builder: (fieldState) => Column(
children: [
Center(
child: DropdownButton<ColorEnum>(
value: fieldState.value,
onChanged: fieldState.bloc.events.setColor,
items: ColorEnum.values
.map(
(color) => DropdownMenuItem<ColorEnum>(
value: color,
child: Text(
color.toString(),
),
),
)
.toList(),
),
),
//show errors, say for instance the user tries to save the
//changes to the form, but they forgot to select a color.
if (fieldState.showError)
Row(
children: [
Text(
fieldState.error,
),
],
),
],
),
);
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- RxFormFieldBuilder
- Implementers
Constructors
-
RxFormFieldBuilder({required RxFormFieldState<
B, T> state, required RxFormFieldShowError<B> showErrorState, required RxFormFieldBuilderFunction<B, T> builder, B? bloc, Key? key}) -
The default constructor
const
Properties
- bloc → B?
-
You can optionally provide an
RxBloc
to the bloc field, if you do the provided bloc would be used, otherwise RxFormFieldBuilder automatically searches for and uses the closest instance up the widget tree ofRxBloc
of typeB
.final -
builder
→ RxFormFieldBuilderFunction<
B, T> -
A builder function is required, this is a function which gives you
access to the current field state, and must return a Widget.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
showErrorState
→ RxFormFieldShowError<
B> -
A showErrorState callback, which returns a Stream of boolean
values which determine when it is time to show any potential errors.
!The stream provided by showErrorState must never emmit an error.
final
-
state
→ RxFormFieldState<
B, T> -
A state callback, which returns a Stream of values
which are provided to the builder function in order to be
displayed.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → RxFormFieldBuilderState< RxBlocTypeBase, dynamic, RxFormFieldBuilder< RxBlocTypeBase, dynamic> > -
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