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),
        ),
      )),
    );
  }
flarkmarup
  • 5,129
  • 3
  • 24
  • 25
user2570135
  • 2,669
  • 6
  • 50
  • 80

1 Answers1

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(),
      ],
),
Tim Klingeleers
  • 2,834
  • 14
  • 20