Comments (6)
Hello @DinoSane,
I'm unable to reproduce your issue, could you kindly elaborate on the issue, more code could be helpful.
from flutter_form_builder.
I created a simple project to ilustrate the problem
can you clone it?
git clone [email protected]:dinosane/form_builder.git
thanks in advance.
from flutter_form_builder.
Please note that your string is fetched from SharedPreferences after the form is already built since the fetching is asyncronous. See code below and the corresponding console output:
`class _FailingPageState extends State {
String _aStringValue = '';
@OverRide
void initState() {
_loadVals();
super.initState();
}
//Loading counter value on start
_loadVals() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('aStringValue', 'My string value');
_aStringValue = prefs.getString('aStringValue');
print("After fetch '$_aStringValue'");
}
@OverRide
Widget build(BuildContext context) {
print("During build '$_aStringValue'");
return SharedScaffold(
titulo: 'Failing',
body: Padding(
padding: EdgeInsets.all(20.0),
child: Padding(
padding: EdgeInsets.all(20.0),
child: FormBuilder(
context,
autovalidate: true,
controls: [
FormBuilderInput.textField(
type: FormBuilderInput.TYPE_TEXT,
attribute: "aStringValue",
value: _aStringValue,
label: "Any Value:",
)
],
onChanged: () async {},
onSubmit: (formValue) async {
if (formValue != null) {
print(formValue);
final prefs = await SharedPreferences.getInstance();
prefs.setString('aStringValue', formValue['aStringValue']);
} else {
print("Form invalid");
}
},
),
),
),
);
}
}`
Console:
Performing hot restart... Syncing files to device Android SDK built for x86... Restarted application in 1,699ms. I/flutter ( 4934): During build '' I/flutter ( 4934): After fetch 'My string value'
I'd advise declaring the form within a FutureBuilder
or a similar implementation
from flutter_form_builder.
You are correct!
Using a FutureBuilder solve the problem.
I though setting the value inside a setState was suffice, but as you pointed, it doesn't.
Thanks.
from flutter_form_builder.
I forgot to say: great job! :-)
from flutter_form_builder.
You're welcome @DinoSane. Thank you.
Also note that you're not really required to use setState()
when setting a value within initState()
from flutter_form_builder.
Related Issues (20)
- No named parameter with the name 'onPopInvoked' HOT 9
- State dos not contain all fields HOT 1
- [Field name or General]: FormBuilderDropdown silently ignores an unknown initialValue
- Resetting form shows error messages HOT 1
- Reuse same widget causes child form field to be overwritten
- [FormBuilderRadioGroup]: No way to decrease padding of Radio widget HOT 4
- [FormBuilderDateTimePicker]: Got problem if initialDate is null and lastDate is years ago.
- [FormBuilderTextField]: Cannot swith to chinese keyborad with keyboardType: TextInputType.text HOT 5
- Internal field 'isDirty' flag is reset too late.
- FormBuilderDropdown onChanged fires twice during form Reset HOT 1
- FormBuilderDropdown when selected keeps triggering a rebuild HOT 1
- [Documentation] RaisedButton is removed.
- [FormBuilderTextField]: TextInputType.emailAddress - not working
- [FormBuilderTextField]: Cannot type the latin text (Vietnamese) on Android HOT 4
- [General]: Add support for lists with multiple fields in each item HOT 1
- [Localizations]: Language code fow Swedish is wrong HOT 1
- [FormBuilderTextField]: Can we add canRequestFocus
- Create custom text field using FormBuilderField
- [FormBuilderField & FormBuilder]: Unexpected retention of `initialValue` when coerced widget recreation
- [FormBuilderField]: Add "resetError" method
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_form_builder.