Integrating Firebase into a Flutter app

Following the Flutter Firebase codelab:

  • Created a Firebase project.
  • Added the debug SHA signature. To get it, run keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore with no password.
  • Ran it in the emulator.
  • It failed with an error about multidex. Luckily the tutorial explains how to work around it: open android/app/build.gradle and replace minSdkVersion 16 to 21.
  • It works!


I got error MissingPluginException(No implementation found for method Query#addSnapshotListener... because I had forgotten to run flutter packages get. Running it solved it.

Then I added the UI, some hardcoded data in the Firebase database and voilà!


However I also noticed some errors in logcat:

W/Firestore(14258): (0.6.6-dev) [Firestore]: The behavior for java.util.Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK.
W/Firestore(14258): To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:
W/Firestore(14258): FirebaseFirestore firestore = FirebaseFirestore.getInstance();
W/Firestore(14258): FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
W/Firestore(14258):     .setTimestampsInSnapshotsEnabled(true)
W/Firestore(14258):     .build();
W/Firestore(14258): firestore.setFirestoreSettings(settings);
W/Firestore(14258): With this change, timestamps stored in Cloud Firestore will be read back as objects instead of as system java.util.Date objects. So you will also need to update code expecting a java.util.Date to instead expect a Timestamp. For example:
W/Firestore(14258): // Old:
W/Firestore(14258): java.util.Date date = snapshot.getDate("created_at");
W/Firestore(14258): // New:
W/Firestore(14258): Timestamp timestamp = snapshot.getTimestamp("created_at");
W/Firestore(14258): java.util.Date date = timestamp.toDate();
W/Firestore(14258): Please audit all existing usages of java.util.Date when you enable the new behavior. In a future release, the behavior will be changed to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.

I'll have to look into it.