title: (Dart) How to execute each Function in a List?
body: <p><strong>TL;DR:</strong> I'm trying to pass a List of Functions to another class, which should then execute every Function.</p>
  
  <p><strong>Why?</strong>
  I need to respond to App Intents in Flutter. My idea was to separate that logic into another Widget, which then gets passed a List of Functions. Upon registering the App onResume event, it should execute the corresponding functions.</p>
  
  <p><strong>How?</strong>
  Currently, my model looks like this:</p>
  
  <pre><code>class LifecycleMethods {
    final List&lt;void&gt; onPaused;
    final List&lt;void&gt; onResumed;
    final List&lt;void&gt; onInactive;
    final List&lt;void&gt; onSuspending;
  
    LifecycleMethods(
        {this.onPaused, this.onInactive, this.onResumed, this.onSuspending});
  }
  </code></pre>
  
  <p>Which gets passed to this class: (Inspired by <a href="https://medium.com/pharos-production/flutter-app-lifecycle-4b0ab4a4211a" rel="nofollow noreferrer">this article</a>)</p>
  
  <pre><code>class AppStateObserver extends StatefulWidget {
    final Widget child;
    final LifecycleMethods lifecycleMethods;
  
    const AppStateObserver({Key key, @required this.child, this.lifecycleMethods})
        : super(key: key);
  
    @override
    _AppStateObserverState createState() =&gt; _AppStateObserverState();
  }
  
  class _AppStateObserverState extends State&lt;AppStateObserver&gt;
      with WidgetsBindingObserver {
    final Widget child;
    final LifecycleMethods lifecycleMethods;
  
    _AppStateObserverState({@required this.child, this.lifecycleMethods});
  
    @override
    Widget build(BuildContext context) =&gt; child;
  
    @override
    void initState() {
      WidgetsBinding.instance.addObserver(this);
      super.initState();
    }
  
    @override
    void dispose() {
      WidgetsBinding.instance.removeObserver(this);
      super.dispose();
    }
  
    @override
    void didChangeAppLifecycleState(AppLifecycleState state) {
      if (state == AppLifecycleState.paused) {
        // Execute every item in lifecycleMethods.onPaused
      }
    }
  }
  </code></pre>
  
  <p>The WidgetBindingObserver seems to be the only way to access the App lifecycle. I'm storing the Methods inside the lifecycleMethods variable. Inside the didChangeAppLifecycleState, it should then finally execute the corresponding functions.</p>
  
  <p>Now - How do I properly execute functions inside a list? Is that even possible?
  <em>Please correct me, if there is a cleaner, better way of solving this problem!</em></p>
  
  <p>Thx</p>