下記の記事で、AndroidでCloud Firestoreを使う方法を記載しましたが、それをWebアプリに適用する方法を記載します。
- Firebaseの準備
Firebaseのプロジェクトの設定で、Webアプリを追加します。
追加すると下記の情報が取得できます。
const firebaseConfig = {
apiKey: "xxx",
authDomain: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx",
appId: "xxx",
measurementId: "xxx"
};
-
Flutterの実装
- 変更前
main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
- 変更後
main.dart
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
name: "xxx",
options: const FirebaseOptions(
apiKey: "xxx",
projectId: "xxx",
messagingSenderId: "xxx",
appId: "xxx",
),
);
runApp(const MyApp());
上記の情報を追加することで、Webアプリが使用することが出来ます。