🎃

FlutterFire のバージョンアップのハマった点

2021/06/27に公開

概要

flutter firestore のバージョンアップでハマった点まとめる。

  • 今回は更新したパッケージ
cloud_firestore: ^0.12.11 -> ^2.2.2
firebase_core: ^0.4.0+8 -> ^1.3.0
firebase_crashlytics: ^0.1.0+2 -> ^2.0.6
firebase_auth: ^0.15.4 -> ^1.4.1
firebase_messaging: ^6.0.16 -> ^10.0.2

依存関係でハマりやすいが基本的に全部最新にする方が解決しやすい。

どこのバージョンでどう変わったかは CHANGELOG を見ると良い。

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_auth/firebase_auth/CHANGELOG.md

0.18.0
BREAKING: The FirebaseUser class has been renamed to User.

マイナーバージョンの変更でも破壊的変更が入ってることが見受けられる。

各対応

Core

  • firebase の初期化が必要
+ import 'package:firebase_core/firebase_core.dart';

+ await Firebase.initializeApp();
  runApp(MyApp());
  • Firestore -> FirebaseFirestore
- static final Firestore _firestore = Firestore.instance;
+ static final FirebaseFirestore _firestore = FirebaseFirestore.instance;
  • documentID -> id
- var id = document.documentID;
+ var id = document.id;
  • getDocuments() -> get()
  • documents -> docs
  • data -> data()
- var data = await _firestore.collection("user").getDocuments();
- return data.documents.map((document) => document.data).toList();
+ var data = await _firestore.collection("user").get();
+ return data.docs.map((document) => document.data()).toList();
  • getDocuments -> get
- await _firestore.collection("users").where("uid", isEqualTo: uid).getDocuments();
+ await _firestore.collection("users").where("uid", isEqualTo: uid).get();
  • setData() -> set()
  • merge -> SetOptions
- await doc.reference.setData({"name": name}, merge: true);
+ await doc.reference.set({"name": name}, SetOptions(merge: true));

Auth

  • FirebaseUser -> User
  • currentUser() -> currentUser
  • UserCredential -> AuthResult
- FirebaseUser user = FirebaseAuth.instance.currentUser();
+ User user = FirebaseAuth.instance.currentUser;

- UserCredential result = FirebaseAuth.instance.signInWithCredential(googleCredential);
+ AuthResult result = FirebaseAuth.instance.signInWithCredential(googleCredential);

Messaging

  • IosNotificationSettings -> requestPermission
- final FirebaseMessaging messaging = new FirebaseMessaging();
+ final FirebaseMessaging messaging = FirebaseMessaging.instance;

- messaging.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true));
- messaging.onIosSettingsRegistered.listen((IosNotificationSettings settings) {});
+ messaging.requestPermission(
+     announcement: true,
+     carPlay: true,
+     criticalAlert: true,
+     provisional: false,
+     sound: true,
+     badge: true,
+     alert: true
+   );

Crashlytics

手順通り
https://firebase.flutter.dev/docs/crashlytics/overview/
fablic 関連ファイルが残ってたら削除する。

Discussion