0

I have this widget

StreamBuilder(
        stream:
            FirebaseFirestore.instance.collection('HouseDetails').snapshots(),
        builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (!snapshot.hasData) {
            return Center(
              child: CircularProgressIndicator(),
            );
          }
          return Expanded(
            child: ListView(
              children: snapshot.data.docs.map<Widget>((document) {
                return _buildHouse(context, document);
              }).toList(),
              physics: BouncingScrollPhysics(),
            ),
          );
        });

Now the _buildHouse builds a basic screen which has an onTap functionality. I am passing the QueryDocumentSnapshot document to another screen using MaterialPageRoute.

 onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (_) => DetailsScreen(house: document),
          ),
        );
      },

the line builder: (_) => DetailsScreen(house: document), throws the error

The following _TypeError was thrown building DetailsScreen(dirty, state: _DetailsScreenState#cc47a):
I/flutter ( 5479): type 'List<dynamic>' is not a subtype of type 'List<String>'
I/flutter ( 5479): The relevant error-causing widget was:
 I/flutter ( 5479):   DetailsScreen

What goes wrong here?

2 Answers 2

1

I just had to use .map<String>((e)=>e.toString()).toList() inside the DetailsScreen class where the variables of the type List<String> .

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

Comments

0

I always got that error when setting a list like this: List testList;

Often it's solved by just doing List testList = []; or List testList = new List;

1 Comment

This happens as you have not initialized your list yet.

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.