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,