title: flutter update value in another file widget
body: <p>I'm new in flutter and I try to update a variable in my main.dart from a customWidget in another file.
  I search on internet but I'm a little lost.</p>
  
  <p>How to update my variable userDistance with the value that the user enter ?
  Is my widget structure correct? or does it have to be stateless or stateful?</p>
  
  <p>Main.dart :</p>
  
  <pre><code>class HomeController extends StatefulWidget {
    HomeController({Key key, this.title}) : super(key: key);
    final String title;
  
    @override
    _HomeControllerState createState() =&gt; _HomeControllerState();
  }
  
  class _HomeControllerState extends State&lt;HomeController&gt; {
  
    // ************************************
    // Variable
    // ************************************
    int userDistance = null;
    final _formKey = GlobalKey&lt;FormState&gt;();
  
    // ************************************
    // Initialisation
    // ************************************
    @override
    void initState() {
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return GestureDetector(
        onTap: (() =&gt; FocusScope.of(context).requestFocus(FocusNode())),
        child: Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: FutureBuilder(
            future: loadJson(),
            builder: (context, snapshot) {
              if (!snapshot.hasData) {
                return CircularProgressIndicator();
              }
  
              return SingleChildScrollView(
                padding: EdgeInsets.all(24),
                child: Form(
                  key: _formKey,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: &lt;Widget&gt;[
                      FormValidatorWidgets.buildDistance(), // =&gt; Here I call my external widget
  ...
  
  </code></pre>
  
  <p>And my customWidget :</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  class FormValidatorWidgets{
  
    static buildDistance() {
      return TextFormField(
        decoration: InputDecoration(
          border: OutlineInputBorder(),
          labelText: "Distance",
          hintText: "Enter a distance",
        ),
        keyboardType: TextInputType.number,
        validator: (String value) {
          int distance = int.tryParse(value);
  
          if (distance == null) {
            return "Distance is required";
          }
          if (distance &lt;= 0) {
            return "Distance must be greater than zero";
          }
        },
        onSaved: (String value) {
          userDistance = int.tryParse(value);
        },
      );
    }
  
  }
  
  </code></pre>
  
  <p>How to update my variable userDistance ?</p>