0

I'm using the Timestamp class from cloud_firestore to convert DateTime value from a formfield when I post the form.

Here is my function for converting the selected date of the formfield:

    int convertDate(DateTime date) {
    var convertedDate = int.parse(Timestamp.fromDate(date).millisecondsSinceEpoch.toString());
    return convertedDate;
}

And here is where I use this function in the onPressed function of my form button:

Row(
    mainAxisAlignment: MainAxisAlignment.end,
    children: [
        Padding(
            padding: EdgeInsets.only(right: 35),
            child: ElevatedButton(
                onPressed: (){postTimes(convertDate(selectedDate), convertTime(_timeController.text));},
                child: Text("Save")
            ),
        )
    ],
)

It worked fine the first times I used it with the cloud_firestore package.

But when I reopened my code the day after and launched it I got this error:

TypeError: Cannot read properties of undefined (reading 'app')

So I added firebase and firebase_core packages, and this :

<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>

in my index.html file like said in the tutorials.

Now, I get this error:

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).

I made my main() asynchronous and added these lines:

WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

just as advised in this topic.

Right now, I'm still getting the error and don't know how to fix it,

If anyone can help,

Thanks,

OmniOwl
  • 5,477
  • 17
  • 67
  • 116
JS1
  • 631
  • 2
  • 7
  • 23
  • Also, I precise that thanks to the answer of this [topic](https://stackoverflow.com/questions/33866061/error-file-google-services-json-is-missing-from-module-root-folder-the-google) I made it works with my Android emulator, but I still get the same issue when I want to run my app in the browser. – JS1 Oct 25 '21 at 14:39
  • Can you also show your dependencies? As per this [comment](https://github.com/firebase/firebase-js-sdk/issues/258#issuecomment-418842537), load order matters. – Farid Shumbar Oct 26 '21 at 07:47
  • In my main.dart : import 'package:firebase_core/firebase_core.dart'; In the file where I use the Timestamp class from firestore : import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; – JS1 Oct 26 '21 at 12:40
  • Try one of the examples from the answer of [this thread](https://stackoverflow.com/questions/63492211/no-firebase-app-default-has-been-created-call-firebase-initializeapp-in?rq=1). – Farid Shumbar Nov 03 '21 at 14:36

0 Answers0