title: Flutter RawKeyboardListener listening twice?
body: <p>What I am trying to achieve is when viewing this widget, the <code>RawKeyboardListener</code> starts listening straight away when the <code>TextField</code> is not selected/in focus. It runs the <code>HandleKey function</code> to deal with what I want to do with the <code>keyCode</code>.</p>
  <p>The issue I am having is when running the app for the first time, the <code>handleKey function</code> seems to be running twice. So in the example below it would print <code>why does this run twice $_keyCode</code> TWICE when I only enter 1 key. I think it listens to keyUp AND keyDown. The result I want is for it to only run once...</p>
  <p>However, the code works fine as well when I select the TextField and do a regular submit with the emulator keyboard.</p>
  <p>I am struggling to understand why it only has a problem after interacting with the TextField. I feel like it needs a <code>Future</code> or <code>await</code> somewhere? but I have no idea.</p>
  <p>Please help.</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'dart:async';
  
  class KeyboardListener extends StatefulWidget {
  
      KeyboardListener();
  
      @override
      _RawKeyboardListenerState createState() =&gt; new _RawKeyboardListenerState();
  }
  
  class _RawKeyboardListenerState extends State&lt;KeyboardListener&gt; {
  
      TextEditingController _controller = new TextEditingController();
      FocusNode _textNode = new FocusNode();
  
  
      @override
          initState() {
          super.initState();
      }
      
      //Handle when submitting
      void _handleSubmitted(String finalinput) {
  
          setState(() {
              SystemChannels.textInput.invokeMethod('TextInput.hide'); //hide keyboard again
              _controller.clear();
          });
      }
  
      handleKey(RawKeyEventDataAndroid key) {
          String _keyCode;
          _keyCode = key.keyCode.toString(); //keycode of key event (66 is return)
  
          print(&quot;why does this run twice $_keyCode&quot;);
      }
  
      _buildTextComposer() {
          TextField _textField = new TextField(
              controller: _controller,
              onSubmitted: _handleSubmitted,
          );
  
          FocusScope.of(context).requestFocus(_textNode);
  
          return new RawKeyboardListener(
              focusNode: _textNode,
              onKey: (key) =&gt; handleKey(key.data),
              child: _textField
          );
      }
  
  
    @override
    Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(title: new Text(&quot;Search Item&quot;)),
        body: _buildTextComposer(),
      );
    }
  }
  </code></pre>