前記事「[基礎知識]既存Flutter(Web)アプリに、Firestore(Firebase Cloud Firestore)機能を追加する手順」では既存FlutterアプリにCloud Firestore 機能を追加(Firestore DB登録等含む)しました。
またローカル環境ではFirebase Emulator Suite を利用しましたが、これのFirestoreエミュレータにも同じ内容のDB登録が必要です。
以下はその際の作業記録です。
1.Firestoreエミュレータ起動
ローカル環境でFirestoreエミュレータを起動します。
> firebase emulators:start

2.Firestoreエミュレータでデータベース作成
(1) コレクションの作成
画面左上の+ Start collection
をクリックします。

(2) コレクションIDの設定
コレクションIDフィールドにtaskinfo
を入力し、Next
をクリックします。

(3) コレクションIDの設定
コレクションIDフィールドにtaskinfo
を入力し、Next
をクリックします。
※ここではFirestoreエミュレータにFirebase本サーバ上のCloud Firestore DBに登録済みのドキュメントIDと同じデータを設定しました。
(本サーバとローカル環境の)ドキュメントIDについて:
ローカル環境でテストしたFlutterアプリのコードを変更せずに、Firebase本サーバー上のCloud Firestoreに接続することは可能です。Firestoreエミュレータでテストする際も、本番環境のFirestoreで使用するのと同じドキュメントIDを使用することで、一貫性を保つことができます。

(4) フィールドの追加


(5) 登録内容の確認

3.登録データのエクスポート
Firebase Emulator Suite / Firestore エミュレータは起動する度に登録データが削除(初期化)されます。
開発中毎回DB再登録する手間を無くす為に登録データをエクスポートします。
(1) データ格納フォルダに移動
※ここではFlutterプロジェクトフォルダに移動しています。
(2) エクスポート
> firebase emulators:export ./exported_data
※上記コマンドの場合、カレントフォルダ配下にエクスポートされます(下図)。

※上記エクスポートデータには、FirestoreデータベースだけでなくAuthenticationデータ(登録ユーザ)等も一緒にエクスポートされます。
4.登録データのインポート
エミュレータが起動する際に、インポート用オプションを指定します。
これにより、エミュレータが起動された時には、データが復元しています。
(1) インポートモードでエミュレータを起動
> firebase emulators:start –import=./exported_data
(2) 復元データ確認
①Firestoreデータベース

②Authentication登録ユーザ情報

エミュレータ登録データのエクスポート・インポート手順は以上です。