Start with an existing cloud functions Flutter Project

155

Usually, you don't need to run all the initialization steps twice as long as you've pushed your initialized app to Version Control. Just flutter run should be fine on the new machine. If you've run the initialization twice then delete that local copy, re-clone and do flutter run.

If this doesn't work, then you may need to dive deeper. Depending on the platform (Web, iOS, or Android) and whether you are running on the Firebase emulator or actual endpoint, you may need to change some settings. You also could check your network connection.

  1. When using the Firebase emulator while debugging an iOS application, you may receive an error regarding App Transport Security. To fix it, you need to set Allows Local Networking in the Info.plist:

  2. On Android, you will not be able to make requests for 8.0+ without enabling this in the AndroidManifest.xml:

<application
  android:usesCleartextTraffic="true"
/>

  1. On Web, you also need to add the dependency to index.html:

<html>
  <body>
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-functions.js"></script>
  </body>
</html>

If you are still having issues, then it's worth attaching the debugger to the process and catching the error when initializing:

For example:

import 'package:flutter/material.dart';

// Import the firebase_core plugin
import 'package:firebase_core/firebase_core.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(App());
}

class App extends StatelessWidget {
  // Create the initialization Future outside of `build`:
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // Initialize FlutterFire:
      future: _initialization,
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          print(snapshot.error.toString()); // <---- Print the error out here.
          return SomethingWentWrong();
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return MyAwesomeApp();
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Loading();
      },
    );
  }
}

If this doesn't fix your issue, please provide more details about your setup.

Share:
155
Adham Saheb
Author by

Adham Saheb

Updated on December 27, 2022

Comments

  • Adham Saheb
    Adham Saheb over 1 year

    I initialized a Flutter project with firebase cloud functions and chose typescript as the language for my Node12 files, my colleague needs to pull the Github repo and branch, what are the right steps for him to initialize cloud functions ? Should he do the regular init commands ? Because the following error occurs upon trying to deploy changes enter image description here

    • Pranav Kasetti
      Pranav Kasetti about 3 years
      Have you done the steps listed here?
    • Adham Saheb
      Adham Saheb about 3 years
      Yes, initialized and working 100 % on my side, when my colleague pulled the repo he couldn't use it and we figured he has to initialize on his side as well, we followed the initialization steps with no luck
    • Pranav Kasetti
      Pranav Kasetti about 3 years
      Ok thanks for sharing. On Android we also need to enable clearText traffic otherwise the requests will be blocked. On iOS we also need to Allow Local Networking in ATS. Have you tried that?
    • Adham Saheb
      Adham Saheb about 3 years
      I have, I have listed a snapshot for our issue in specific, the app runs fine but cloud functions cannot be deployed
    • Pranav Kasetti
      Pranav Kasetti about 3 years
      Ok, is the file path correct for the other user?
    • Adham Saheb
      Adham Saheb about 3 years
      yes it is, all files are identical
    • Pranav Kasetti
      Pranav Kasetti about 3 years
      Can you share your package.json?
    • Adham Saheb
      Adham Saheb about 3 years
    • Jofre
      Jofre about 3 years
  • Adham Saheb
    Adham Saheb about 3 years
    My apologies for not providing more specific details about the issue, the app itself runs fine when running flutter run, the issue occurs when my colleague tried to edit the main ts file of cloud functions and gets an error when trying to deploy, I will put the snapshot of the error in the question. Thank you so much