I do question regarding Dart and Flutter. So I'm trying to refactor some code and I'm stuck in a referencing problem.
class _LoginPageState extends State<LoginPage> {
String _email;
String _password;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text("Login Page"),
),
body: new Container(
padding: new EdgeInsets.all(16),
child: new Form(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: buildInputs()
)),
));
}
Widget buildInput(String label, String val) {
return new TextFormField(
decoration: new InputDecoration(
labelText: label,
),
validator: (value) => value.isEmpty ? "$label can't be empty" : null,
onSaved: (value) => val = value,
);
}
List<Widget> buildInputs() {
return [
buildInput("Email", this._email),
buildInput("Password", this._password),
];
}
}
I'm trying to create a function called buildInput which will take 2 parameters, one will be my label from my form and the second one will be the actual variable which I want to modify. Now here is the tricky part, for some reason I have no idea why... but my variable is never going to set with the correct value, and it is always null.
Any idea how can I pass a parameter with a function in order to modified in the body of the function and the parameter to stay medicated and after the function call is done?