1

I want to add a text widget to the body if no data was return. Otherwise, I want to display the data. However, the following error is returned:

flutter: type '_CompactLinkedHashSet<Widget>' is not a subtype of type 'Widget'

My Code:

body: SafeArea(
  child: (isLoading)
    ? Center(
         child: new CircularProgressIndicator(),
      )
    : Stack(
         children: <Widget>[
            (jobDetail == null && !isLoading)
                ? noDataFound()
                : {
                     detailWidget(context, jobDetail),
                      applyWidget(context, jobDetail)
                  }
          ],
      ),
),

This is my code for the text widget

Widget noDataFound() {
    return Container(
      child: Center(
          child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text(
          "We could not get the detail. Please try again later",
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 20.0),
        ),
      )),
    );
  }
3
  • Did you try future builder? Commented Jul 17, 2019 at 12:13
  • 1
    Thanks. No. I have not tried future builder. Is something not correct with my current logic? Commented Jul 17, 2019 at 12:19
  • try removing this : && !isLoading Commented Jul 17, 2019 at 12:24

1 Answer 1

4

You are trying to assign a hash set of widgets to the stack as the error message says (the {...} part makes it a hashset). The easiest way around that is changing the location of your ternary operator.

Example reduced to the core problem:

Stack(
  children: (jobDetail == null && !isLoading)
    ? [
        Container(),
      ]
    : [
        Container(),
        Container(),
      ],
),
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.