title: Flutter send local notification by API in background
body: <p>I have an API that I'm checking, and when the response changes I need to send a notification to the user. I would like to know how to do this without FCM Push Notifications.</p>
  
  <p>I'm using <code>flutter-local-notifications</code> and background fetch (<a href="https://github.com/transistorsoft/flutter_background_fetch" rel="nofollow noreferrer">https://github.com/transistorsoft/flutter_background_fetch</a>) to do it. On the background fetch docs it says that background fetch will do your function once every 15 minutes, which is good enough for me.</p>
  
  <p>This is my <code>initPlatformState()</code>:</p>
  
  <pre class="lang-dart prettyprint-override"><code>// Platform messages are asynchronous, so we initialize in an async method.
    Future&lt;void&gt; initPlatformState() async {
      // Load persisted fetch events from SharedPreferences
      SharedPreferences prefs = await SharedPreferences.getInstance();
      String json = prefs.getString(EVENTS_KEY);
      if (json != null) {
        setState(() {
          _events = jsonDecode(json).cast&lt;String&gt;();
        });
      }
  
      // Configure BackgroundFetch.
      BackgroundFetch.configure(BackgroundFetchConfig(
          minimumFetchInterval: 15,
          stopOnTerminate: false,
          enableHeadless: true,
          forceReload: true,
          startOnBoot: true,
      ), _onBackgroundFetch).then((int status) {
        print('[BackgroundFetch] SUCCESS: $status');
        setState(() {
          _status = status;
        });
      }).catchError((e) {
        print('[BackgroundFetch] ERROR: $e');
        setState(() {
          _status = e;
        });
      });
  
      // Optionally query the current BackgroundFetch status.
      int status = await BackgroundFetch.status;
      setState(() {
        _status = status;
      });
  
      // If the widget was removed from the tree while the asynchronous platform
      // message was in flight, we want to discard the reply rather than calling
      // setState to update our non-existent appearance.
      if (!mounted) return;
    }
  </code></pre>
  
  <p>I'm assuming that what's in the function that gets called in the fetch isn't needed for the question.</p>
  
  <p>I tried this on my phone and simulator, and I used Xcode -> Simulate Background Fetch and it ran properly. It also ran properly when I opened the app. Unfortunately, it didn't run after 15 minutes. Is there something I'm missing?</p>
  
  <p>How would I change my code to make the background fetch to happen every 15 minutes?</p>