Flutter: Where to add listeners in StatelessWidget? : <p>If I were using a StatefulWidget, then I would be listening to a Stream for example inside the initState method. Where would I do the equivalent in a StatelessWidget (like to use Bloc with streams for state management)? I could do it in the build method but since these are repetitively I wondered if there is a more efficient way than checking for existent listeners like below. I know that this is a redundant and useless example but it's just to show the problem.</p>

<pre class="lang-dart prettyprint-override"><code>    import "package:rxdart/rxdart.dart";

    import 'package:flutter/material.dart';

    final counter = BehaviorSubject&lt;int&gt;();
    final notifier = ValueNotifier&lt;int&gt;(0);

    void main() =&gt; runApp(MyApp());

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        if (!counter.hasListener)
          counter.listen((value) =&gt; notifier.value += value);  

        return MaterialApp(
          home: Scaffold(
            body: Center(
              child:FlatButton(
                onPressed: () =&gt; counter.add(1),
                child: ValueListenableBuilder(
                  valueListenable: notifier,
                  builder: (context, value, child) =&gt; Text(
                    value.toString()
                  ),
                ),
              )
            ),
          )
        );
      }
    }
</code></pre>
