title: How to debounce Textfield onChange in Dart?
body: <p>I'm trying to develop a TextField that update the data on a Firestore database when they change. It seems to work but I need to prevent the onChange event to fire multiple times.</p>
  <p>In JS I would use lodash _debounce() but in Dart I don't know how to do it. I've read of some debounce libraries but I can't figure out how they work.</p>
  <p>That's my code, it's only a test so something may be strange:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  
  
  class ClientePage extends StatefulWidget {
  
    String idCliente;
  
  
    ClientePage(this.idCliente);
  
    @override
    _ClientePageState createState() =&gt; new _ClientePageState();
  
    
  }
  
  class _ClientePageState extends State&lt;ClientePage&gt; {
  
    TextEditingController nomeTextController = new TextEditingController();
  
  
    void initState() {
      super.initState();
  
      // Start listening to changes 
      nomeTextController.addListener(((){
          _updateNomeCliente(); // &lt;- Prevent this function from run multiple times
      }));
    }
  
  
    _updateNomeCliente = (){
  
      print(&quot;Aggiorno nome cliente&quot;);
      Firestore.instance.collection('clienti').document(widget.idCliente).setData( {
        &quot;nome&quot; : nomeTextController.text
      }, merge: true);
  
    }
  
  
  
    @override
    Widget build(BuildContext context) {
  
      return new StreamBuilder&lt;DocumentSnapshot&gt;(
        stream: Firestore.instance.collection('clienti').document(widget.idCliente).snapshots(),
        builder: (BuildContext context, AsyncSnapshot&lt;DocumentSnapshot&gt; snapshot) {
          if (!snapshot.hasData) return new Text('Loading...');
  
          nomeTextController.text = snapshot.data['nome'];
  
  
          return new DefaultTabController(
            length: 3,
            child: new Scaffold(
              body: new TabBarView(
                children: &lt;Widget&gt;[
                  new Column(
                    children: &lt;Widget&gt;[
                      new Padding(
                        padding: new EdgeInsets.symmetric(
                          vertical : 20.00
                        ),
                        child: new Container(
                          child: new Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: &lt;Widget&gt;[
                              new Text(snapshot.data['cognome']),
                              new Text(snapshot.data['ragionesociale']),
                            ],
                          ),
                        ),
                      ),
                      new Expanded(
                        child: new Container(
                          decoration: new BoxDecoration(
                            borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(20.00),
                              topRight: Radius.circular(20.00)
                            ),
                            color: Colors.brown,
                          ),
                          child: new ListView(
                            children: &lt;Widget&gt;[
                              new ListTile(
                                title: new TextField(
                                  style: new TextStyle(
                                    color: Colors.white70
                                  ),
                                  controller: nomeTextController,
                                  decoration: new InputDecoration(labelText: &quot;Nome&quot;)
                                ),
                              )
                            ]
                          )
                        ),
                      )
                    ],
                  ),
                  new Text(&quot;La seconda pagina&quot;),
                  new Text(&quot;La terza pagina&quot;),
                ]
              ),
              appBar: new AppBar(
                title: Text(snapshot.data['nome'] + ' oh ' + snapshot.data['cognome']),
                bottom: new TabBar(          
                  tabs: &lt;Widget&gt;[
                    new Tab(text: &quot;Informazioni&quot;),  // 1st Tab
                    new Tab(text: &quot;Schede cliente&quot;), // 2nd Tab
                    new Tab(text: &quot;Altro&quot;), // 3rd Tab
                  ],
                ),
              ),
            )
          );
          
        },
      );
  
      print(&quot;Il widget id è&quot;);
      print(widget.idCliente);
      
    }
  }
  </code></pre>