Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Text Input form from Slider. #124

Closed
jamiethain opened this issue Sep 2, 2019 · 1 comment
Closed

Setting Text Input form from Slider. #124

jamiethain opened this issue Sep 2, 2019 · 1 comment

Comments

@jamiethain
Copy link

jamiethain commented Sep 2, 2019

I have a tree

  FormBuilder child:(Column(children:[ 
     FormBuilderSlider(...),
     FormBuilderTextField(...)   
     

What I want to do is update the values in the text field as the slider changes and I tried setting and initial value in the TextField and calling a setState () and setting as a property in the stateful class.

I had the FormBuildSlider onChanged call


 void _setBidValue(val)
  {
    setState(() {
      _bidValue = val;
    }); 
  }

Is there a proper way to set the values on the FormBuilder ?

With thanks,

@danvick
Copy link
Collaborator

danvick commented Sep 3, 2019

Hi @jamiethain,
That's not normally how you'd go about changing the value of a TextField in Flutter.
I think the best way to go is to define a TextEditingController and use that to change the value of the TextField.
See my approach below:

TextEditingController _controller = TextEditingController();

@override
Widget build(BuildContext context) {
    return FormBuilder(
        key: _fbKey,
        child: Column(
        children: <Widget>[
            FormBuilderSlider(
                attribute: "slider",
                validators: [FormBuilderValidators.min(6)],
                onChanged: (val){
                    _controller.text = val.toString();
                },
                min: 0.0,
                max: 10.0,
                initialValue: 7.0,
                decoration: InputDecoration(
                    labelText: "Number of things",
                ),
            ),
            FormBuilderTextField(
                attribute: "text",
                controller: _controller,
            ),
        ],
    ),
);
}

Hope that helps.
Cheers!

@danvick danvick closed this as completed Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants