0

I have been trying to add the attractions list items to the objects tripAttractions list but it doesn't seem like its working. How do I add these items correctly?

 class Trip {
          String image;
          String name;
          String location;
          List<Attraction> tripAttractions = [];

          Trip({this.image , this.name, this.location, this.tripAttractions});
        }

    final List<Trip> tripList = [
        Trip(image: 'test image', name: 'NY Trip', location: 'NY Address', tripAttractions: attractions)];

    List<Attraction> attractions = [
        Attraction('name', 'address', 'imageURL')];

Code output

1 Answer 1

1

Since your tripAttractions is of the type List where Attraction is a class, you'll have to access variables by using the object, for example

You will have to iterate through the tripAttraction list and access the data as follows,

tripAttractions[0].name
tripAttractions[0].address
tripAttractions[0].imageURL
Sign up to request clarification or add additional context in comments.

1 Comment

Wow so simple yet I was going crazy trying to figure this out lol. Thanks!

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.