1

I don't recall changing anything besides attempting to run a StreamBuilder using cloud firestore, then this error below started to appear. I commented the Streambuilder but nothing is changing.

**Steps i have taken:

  1. Ran flutter pub cache repair
  2. Ran flutter clean
  3. Removed cloud firestore package then called pub get and then added it again and run pub get once more.**

Packages versions: firebase_core: ^0.7.0 cloud_firestore: ^0.16.0

Flutter: Flutter 1.22.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7891006299 (6 weeks ago) • 2020-12-10 11:54:40 -0800 Engine • revision ae90085a84 Tools • Dart 2.10.4

The Error:

/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

UPDATE 1: The streams that are currently commented but i had called before the error appeared.

     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(),
        );
      },
    );
  }
2
  • Can you show us your code? Where you call the StreamBuilder. Commented Jan 19, 2021 at 13:06
  • Added an update with the code. @Andrej Commented Jan 19, 2021 at 20:18

4 Answers 4

2

The solution that worked for me as proposed here https://github.com/Dart-Code/Dart-Code/issues/2172 is to:

1. Delete the .dart_tool file which you'll find inside your project

2. Go to pubspec.yaml and pub get.

Sign up to request clarification or add additional context in comments.

Comments

0

Upgrade flutter in your terminal:

flutter upgrade

Comments

0

sloved me just remove ^ from the versions of Firebase libraries in pubspec.yaml

example

  firebase_core: ^1.7.0
  firebase_auth: ^3.1.3
  cloud_firestore: ^2.5.3
  firebase_storage: ^10.0.5

to

  firebase_core: 1.7.0
  firebase_auth: 3.1.3
  cloud_firestore: 2.5.3
  firebase_storage: 10.0.5

then flutter clean And flutter pub get

1 Comment

This will use the packages for only these versions, which is not recommended for to include non-breaking updates. For example for Firebase core: Before version >= 1.7.0 and <2.0.0 , your after causes version to only use 1.7.0
0

After multiple attempts of deleting dart folders and pub gets and flutter cleans, finally realized that the flutter version was the culprit and issue resolved after flutter upgrade. Thanks for all the previous inputs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.