whitebear
whitebear

Reputation: 12461

The argument type 'Image?' can't be assigned to the parameter type 'Widget' because 'Image?'

I have this error after updating flutter version,

before updating it works well.

The argument type 'Image?' can't be assigned to the parameter type 'Widget' because 'Image?' is nullable and 'Widget' isn't.

How can I fix this??

  Widget levelBtn = FlatButton(
    onPressed: (){
      setState((){
        level++;
        if (level == 2){level = 0;}
      });
    },
    padding: EdgeInsets.all(0.0),
    child: ((){
      if (level == 0){
        return Image.asset("images/LL_BeginnerJa.png",height:constrain.minHeight /414 * 30);
                    
      } else if (level == 1){
        return Image.asset("images/LL_NormalJa.png",height:constrain.minHeight /414 * 30);
      
      } 
    })()
  );

Upvotes: 0

Views: 599

Answers (1)

esentis
esentis

Reputation: 4716

Can you try this syntax and tell me if it works ?

child: level == 0 ? Image.asset("images/LL_BeginnerJa.png",height:constrain.minHeight /414 * 30) : level == 1 ? Image.asset("images/LL_NormalJa.png",height:constrain.minHeight /414 * 30) : SizedBox(),

Whole code

Widget levelBtn = FlatButton(
  onPressed: () {
    setState((){
      level++;
      if (level == 2){level = 0;}
    });
  },
  padding: EdgeInsets.all(0.0),
  child: level == 0
      ? Image.asset("images/LL_BeginnerJa.png",
          height: constrain.minHeight / 414 * 30)
      : level == 1
          ? Image.asset("images/LL_NormalJa.png",
              height: constrain.minHeight / 414 * 30)
          : SizedBox(),
);

Upvotes: 1

Related Questions