Flutterで以下のようなコードを書いたのですが、①の部分の実行が終わる前に②③が実行されてしまいます。
①の再帰の中身まで完全に終わってから②③を実行したいのですが、どのようにプログラムを書けば良いでしょうか?どなたかご教授お願いします。
dart
1static deleteFolder(String level, String currentLevel) async { 2 String userId = await User.getUserId(); 3 4 var batch = _firestore.batch(); 5 6 Future deleteChildFolderLoop(String newLevel) async { 7 _firestore 8 .collection('users') 9 .document(userId) 10 .collection(newLevel) 11 .getDocuments() 12 .then((snapshot) { 13 for (DocumentSnapshot ds in snapshot.documents) { 14 String type = ds.data['type']; 15 String id = ds.data['id']; 16 if (type == 'folder') { 17 deleteChildFolderLoop(id); 18 } 19 batch.delete(ds.reference); 20 } 21 }); 22 } 23 24 //① 25 await deleteChildFolderLoop(level); 26 27 //② 28 batch.delete(_firestore 29 .collection('users') 30 .document(userId) 31 .collection(currentLevel) 32 .document(level)); 33 //③ 34 batch.commit(); 35 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/04/05 14:59