前提・実現したいこと
Flutterで、簡単なTODOリストのアプリを作成しています。
今まで特に問題なく動いていたのですが、先日、FlutterとDartのバージョンアップをした所
StreamBuilderで Firebaseから取得したTODOリストを、
スワイプで削除する処理において、下記のエラーが出るようにようなってしまいました。
以前、正常に動いていた時のバージョンは確認していなかったので不明です。
解決できず困っています、よろしくお願いいたします。
発生している問題・エラーメッセージ
A dismissed Dismissible widget is still part of the tree. Make sure to implement the onDismissed handler and to immediately remove the Dismissible widget from the application once that handler has fired.
該当のソースコード
Dart
1 return Scaffold( 2 appBar: AppBar( 3 title: Text("xxxx"), 4 ), 5 body: Padding( 6 padding: const EdgeInsets.all(8.0), 7 child: StreamBuilder<QuerySnapshot>( 8 stream: Firestore.instance 9 .collection("users") 10 .document(firebaseUser.uid) 11 .collection("category") 12 .document(_categoryId) 13 .collection("todoList") 14 .snapshots(), 15 16 builder: (context, snapshot) { 17 return Container( 18 child: getTodoItems(snapshot), 19 ); 20 }, 21 ), 22 ), 23 ); 24 } 25 26 /// TODOリストを表示 27 Widget getTodoItems(AsyncSnapshot<QuerySnapshot> snapshot) { 28 return ListView.builder( 29 itemCount: snapshot.data.documents.length, 30 itemBuilder: (context, index) { 31 final item = snapshot.data.documents[index]; 32 final itemID = snapshot.data.documents[index].documentID; 33 34 // スワイプによるTODOリストの削除 35 return Dismissible( 36 key: Key(itemID), 37 38 onDismissed: (direction) { 39 // Firestoreのデータを削除 40 Firestore.instance 41 .collection("users") 42 .document(firebaseUser.uid) 43 .collection("category") 44 .document(_categoryId) 45 .collection("todoList") 46 .document(itemID) 47 .delete() 48 .catchError((e) { 49 print(e); 50 }); 51 52 // 「A dismissed Dismissible widget is still part of the tree.」エラー対応 53 // これを追加してみたけど、エラーは解消せず 54 setState(() { 55 snapshot.data.documents.removeAt(index); 56 }); 57 58 }, 59 background: Container( 60 alignment: AlignmentDirectional.centerStart, 61 color: Colors.red, 62 child: const Padding(...), 63 ), 64 secondaryBackground: Container( 65 alignment: AlignmentDirectional.centerEnd, 66 color: Colors.red, 67 child: const Padding(...), 68 ), 69 // 各要素を表示 70 child: _buildListItem(context, item), 71 ); 72 }, 73 ); 74 }
試したこと
stackOverflow の下記ページなどを参考に色々ためしてみたのですが、解決に至りませんでした。
https://stackoverflow.com/questions/55792521/how-to-fix-a-dismissed-dismissible-widget-is-still-part-of-the-tree-error-in
https://stackoverflow.com/questions/58470821/a-dismissed-dismissible-widget-is-still-part-of-the-tree-in-flutter
補足情報(FW/ツールのバージョンなど)
flutter --version
Flutter 1.12.13+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 27321ebbad (3 weeks ago) • 2019-12-10 18:15:01 -0800
Engine • revision 2994f7e1e6
Tools • Dart 2.7.0
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.2 19C57, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.41.1)
[✓] Connected device (1 available)
• No issues found!
あなたの回答
tips
プレビュー