title: Is there any way intercept 'Back' keydown in Flutter app on Android?
body: <p>I need to show an alert dialog before user navigates away from current route by pressing <code>Back</code> button on Android devices. I tried to intercept back button behavior by implementing <a href="https://docs.flutter.io/flutter/widgets/WidgetsBindingObserver-class.html" rel="noreferrer" title="WidgetsBindingObserver"><code>WidgetsBindingObserver</code></a> in widget state. There is an closed <a href="https://github.com/flutter/flutter/issues/4867#issuecomment-276289384" rel="noreferrer" title="issue">issue</a> on GitHub regarding same topic. However my code is not working as the method <a href="https://docs.flutter.io/flutter/widgets/WidgetsBindingObserver/didPopRoute.html" rel="noreferrer" title="didPopRoute&#40;&#41;">didPopRoute()</a> was never called. Here is my code below:
  </p>
  
  <pre><code>import 'dart:async';
  
  import 'package:flutter/material.dart';
  
  class NewEntry extends StatefulWidget {
    NewEntry({Key key, this.title}) :super(key: key);
  
    final String title;
  
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; new _NewEntryState();
  }
  
  class _NewEntryState extends State&lt;NewEntry&gt; with WidgetsBindingObserver {
    @override
    void initState() {
      super.initState();
      WidgetsBinding.instance.addObserver(this);
    }
  
    @override
    void dispose() {
      WidgetsBinding.instance.removeObserver(this);
      super.dispose();
    }
  
    @override
    Future&lt;bool&gt; didPopRoute() {
      return showDialog(
        context: context,
        child: new AlertDialog(
          title: new Text('Are you sure?'),
          content: new Text('Unsaved data will be lost.'),
          actions: &lt;Widget&gt;[
            new FlatButton(
              onPressed: () =&gt; Navigator.of(context).pop(true),
              child: new Text('No'),
            ),
            new FlatButton(
              onPressed: () =&gt; Navigator.of(context).pop(false),
              child: new Text('Yes'),
            ),
          ],
        ),
      );
    }
  
    @override
    Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(
          title: new Text(widget.title),
        ),
        floatingActionButton: new FloatingActionButton(
          child: new Icon(Icons.edit),
          onPressed: () {},
        ),
      );
    }
  }
  </code></pre>