title: Facing 'No Firebase App has been created' while uploading to Firebase Storage in a Flutter app
body: <p>I want to collect user browsing data for offline backend analysis for a Flutter app. What is the optimal way to do that?</p>
  <p>What I am planning to do is run a daily cron on the app that uploads it using the <a href="https://pub.dev/packages/workmanager" rel="nofollow noreferrer">WorkManager</a> package.</p>
  <pre class="lang-dart prettyprint-override"><code>void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    Workmanager().initialize(uploadUserData, isInDebugMode: true);
    Workmanager()
        .registerOneOffTask('1', 'task1', initialDelay: Duration(seconds: 10));
    runApp(MyApp());
  }
  
  void uploadUserData() {
    Workmanager().executeTask((task, inputData) {
      firebase_storage.FirebaseStorage.instance
          .ref('/uploads/test_workmanager.txt')
          .putString('workmanager test');
      return Future.value(true);
    });
  }
  </code></pre>
  <p>I am facing the following issue while running the above code</p>
  <blockquote>
  <p>E/BackgroundWorker( 6733): errorCode: error, errorMessage: [core/no-app] <strong>No Firebase App '[DEFAULT]' has been created</strong> - call Firebase.initializeApp()</p>
  </blockquote>
  <blockquote>
  <p>I/WM-WorkerWrapper( 6733): Worker result FAILURE for Work [ id=81642715-826f-4d40-b8ec-9d86eab75136, tags={ be.tramckrijte.workmanager.BackgroundWorker } ]</p>
  </blockquote>
  <p>I have checked in multiple ways that firebase is initialized before calling the workmanager task (using <code>firebase.apps.length</code> &amp; <code>.whenComplete</code>)</p>
  <p><em>Update</em>: Many are doubting whether firebase connection is right: basically everything just works if I just call <code>firebase_storage....putString</code> in the <code>main()</code> instead of within <code>Workmanager().executeTask</code>. So, the trouble is only due to <code>Workmanager</code>.</p>