我不记得除了尝试使用云firestore运行StreamBuilder之外还做了什么更改,然后下面的错误开始出现。我对StreamBuilder进行了注解,但没有任何更改。
- 我采取的步骤:
1.已运行flutter发布缓存修复
1.已清除Flutter
1.删除Cloud Firestore软件包,然后调用pub get,然后再次添加并再次运行pub get。**
软件包版本: Firebase _核心:^0.7.0云存储器_火灾存储器:^0.16.0
Flutter:Flutter1.22.5·通道稳定·https://github.com/flutter/flutter.git框架·修订版7891006299(6周前)·2020年12月10日11:54:40 -0800引擎·修订版ae90085a84工具·Dart 2.10.4
错误:
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/collection_reference.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/document_change.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/document_reference.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/document_snapshot.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/field_value.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/firestore.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/query.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/query_document_snapshot.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/query_snapshot.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/snapshot_metadata.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/transaction.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/utils/codec_utility.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/write_batch.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\yassin\Downloads\Programming files\Flutter\packages\flutter_tools\gradle\flutter.gradle' line: 904
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\yassin\Downloads\Programming files\Flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 12s
Exception: Gradle task assembleDebug failed with exit code 1
更新1:当前被注解的流,但在错误出现之前我已经调用了。
Future<List<QuerySnapshot>> displayLocations() async {
final List<DocumentSnapshot> documents = [];
_firebaseFirestore
.collection('locations')
.get()
.then((QuerySnapshot querySnapshot) => {
querySnapshot.docs.forEach((doc) {
documents.add(doc);
return documents;
})
});
}
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('locations').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return ListView(
children: snapshot.data.docs.map((DocumentSnapshot document) {
return ListTile(
title: Text(
document.data()['locationName'] ?? 'Unable to retrieve data'),
);
}).toList(),
);
},
);
}
4条答案
按热度按时间qnakjoqk1#
这里提出的解决方案https://github.com/Dart-Code/Dart-Code/issues/2172对我来说是:
1.删除项目中的.dart_tool文件
2.转到pubspec.yaml和pubget.
balp4ylt2#
在您的终端中升级抖动:
0lvr5msh3#
解决我只是删除
^
从版本的Firebase库在pubspec.yaml示例
至
然后扑干净和扑酒吧得到
arknldoa4#
经过多次尝试删除dart文件夹和pub get以及flutter清理,最终意识到flutter版本是罪魁祸首,**问题在flutter升级后得到解决。**感谢所有之前的输入。