3

So, I have created a basic map

     var tracks = const [
    {
      'title':'Something',
      'subtitle':'Something'
    },
    {
      'title':'Something Else',
    },
    {
      'title':'Admission',
    },
    {
      'title':'University',
    },
    {
      'title':'Exam',
'subtitle':'Something'
    },
    {
      'title':'Job',
    },
  ];

And this is being called by a ListView.builder in the following manner:

var trackTitles = tracks[index];

and then being used like this:

return PrimaryMail(
              title: trackTitles['titles'],
            )

But, it is throwing an "Invalid Argument(s): titles error in the final build. No dart-analytics issues seen. The only error I see (info, not serious) is This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: Home.tracks (must_be_immutable] lib\main.dart:18). [edit: the immutable issue has been fixed now by replacing var with final, but the original problem remains]

So, any way to understand why it is throwing an invalid argument even though the title key does exist?

The full code of this page is here.

1 Answer 1

2

Add final before the field you declare in line lib\main.dart:18

If you have var there, replace var by final

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

6 Comments

Thank you. This solves the additional issue. But not the issue with Invalid Argument(s): titles. This error has now changed to Another exception was thrown: 'package:flutter/src/widgets/text.dart': Failed assertion: line 237 pos 15: 'data != null': is not true. Note that if I replace title: trackTitles['titles'], with title: 'Random String',, then it seems to work normally.
Try title: trackTitles['titles']?.isNotEmpty ?? 'no tile'
Thank you. Just did. Now all of the tiles display "no tile". Which means that it is empty :( But do note that I have 6 sets/maps in tracks, and 6 tiles are being printed too (with the 'no tile' text).
title: trackTitles['titles'], should be title: trackTitles['title'], (title instead of titles)
I misinterpreted your code. I deleted my comment and posted a new one above.
|

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.