RxTextFormFieldBuilder<B extends RxBlocTypeBase> class
RxTextFormFieldBuilder is a RxFormFieldBuilder which specializes in building text form fields with reactive streams, it handles the most important parts of managing a text field's state.
It requires a state callback, which returns a Stream of values, and can emmit errors which have to be of type RxFieldException.
-
If the value Stream emits a value, that value is loaded into the controller.
-
If the value Stream emits an error of type RxFieldException the value from the exception is loaded into the controller, and the error string is loaded into the decoration which is later provided to the builder function trough the field state
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.
A onChanged callback is required, this function is called every time the controller receives a change from the generated text form field, to which the controller should be provided. It provides a bloc instance and the current value from the state stream.
An optional decorationData of type RxInputDecorationData can be provided, if it isn't a default one is used.
An optional controller can be provided, if it isn't an internal one is created and managed.
The optional obscureText field is a boolean value which determines whether or not the text field should be obscured. If it is set the text field starts off as obscured, and the generated decoration provided to the builder gets filled in with a trailing icon from RxInputDecorationData, after that obscureText changes are automatically managed in response to taps on the trailing icon.
You can optionally provide an RxBloc
to the bloc field, if you do
the provided bloc would be used, otherwise RxTextFormFieldBuilder
automatically searches for and uses the closest instance up the widget tree
of RxBloc
of type B
.
This example shows general use.
Widget build(BuildContext context) =>
RxTextFormFieldBuilder<EditProfileBlocType>(
state: (bloc) => bloc.states.name,
showErrorState: (bloc) => bloc.states.showErrors,
onChanged: (bloc, value) => bloc.events.setName(value),
builder: (fieldState) => TextFormField(
//use the controller from the fieldState
controller: fieldState.controller,
//copy the decoration generated by the builder widget, which
//contains stuff like when to show errors, with additional
//decoration
decoration: fieldState.decoration
.copyWithDecoration(InputStyles.textFieldDecoration),
),
);
This example shows how to create a password field.
Widget build(BuildContext context) =>
RxTextFormFieldBuilder<LoginBlocType>(
state: (bloc) => bloc.states.password,
showErrorState: (bloc) => bloc.states.showErrors,
onChanged: (bloc, value) => bloc.events.setPassword(value),
decorationData: InputStyles.passwordFieldDecorationData, //extra decoration for the field
obscureText: true, //tell the password field that it should be obscured
builder: (fieldState) => TextFormField(
//use the controller from the fieldState
controller: fieldState.controller,
//use the isTextObscured field from fieldState to determine
//when the text should be obscured. The isTextObscured field
//automatically changes in response to taps on the suffix icon.
//how the suffix icon looks is determined by the iconVisibility
//and iconVisibilityOff properties of the decorationData.
obscureText: fieldState.isTextObscured,
//copy the decoration generated by the builder widget, which
//contains stuff like when to show errors, with additional
//decoration
decoration: fieldState.decoration
.copyWithDecoration(InputStyles.passwordFieldDecoration),
),
);
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- RxFormFieldBuilder<
B, String> - RxTextFormFieldBuilder
Constructors
-
RxTextFormFieldBuilder({required RxFormFieldState<
B, String> state, required RxFormFieldShowError<B> showErrorState, required RxTextFormFieldBuilderFunction<B> builder, required RxFormFieldOnChanged<B, String> onChanged, RxInputDecorationData decorationData = const RxInputDecorationData(), TextEditingController? controller, bool obscureText = false, RxTextFormFieldCursorBehaviour cursorBehaviour = RxTextFormFieldCursorBehaviour.start, B? bloc, Key? key}) - The default constructor
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
.finalinherited -
builder
→ RxFormFieldBuilderFunction<
B, String> -
A builder function is required, this is a function which gives you
access to the current field state, and must return a Widget.
finalinherited
- controller → TextEditingController?
-
An optional controller can be provided, if it isn't
an internal one is created and managed.
final
- cursorBehaviour → RxTextFormFieldCursorBehaviour
-
the cursor behaviour for when the text is changed by the state stream
final
- decorationData → RxInputDecorationData
-
An optional decorationData of type RxInputDecorationData
can be provided, if it isn't a default one is used.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- obscureText → bool
-
The optional obscureText field is a boolean value which determines
whether or not the text field should be obscured. If it is set
the text field starts off as obscured, and the generated decoration
provided to the builder gets filled in with a trailing icon from
RxInputDecorationData, after that obscureText changes are automatically
managed in response to taps on the trailing icon.
final
-
onChanged
→ RxFormFieldOnChanged<
B, String> -
A onChanged callback is required, this function is called every time
the controller receives a change from the generated text form field,
to which the controller should be provided. It provides a bloc instance
and the current value from the state stream.
final
- 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.
finalinherited
-
state
→ RxFormFieldState<
B, String> -
A state callback, which returns a Stream of values
which are provided to the builder function in order to be
displayed.
finalinherited
-
textFormBuilder
→ RxTextFormFieldBuilderFunction<
B> -
A builder function is required, this is a function which gives you
access to the current field state, and must return a Widget.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → RxTextFormFieldBuilderState< RxBlocTypeBase> -
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