codelearner
codelearner

Reputation: 1365

Image.asset in Expanded FittedBox widgets show blank

I am trying to use Image.asset inside FittedBox in Expanded widget. But it always shows black screen.

Scaffold(
 body: Column(
    children: [
     Expanded(
      child: FittedBox(
       fit: BoxFit.contain,
       child: Image.asset('assets/images/logo.png'),
      ),
    )
  ]
 )
)

If I use it without Expanded and FittedBox then it works

Scaffold(
 body: Column(
   children: [
    Image.asset('assets/images/logo.png')
  ]
 )
)

Any idea what I am doing wrong?

Upvotes: 0

Views: 220

Answers (1)

codelearner
codelearner

Reputation: 1365

Just figured it out. It seems I was overusing the widgets. I have to simply use the fit property of Image.asset instead of using another parent widget FittedBox. My code reduces to:

Scaffold(
 body: Column(
  children: [
   Expanded(
    child: Image.asset('assets/images/logo.png', fit: BoxFit.contain)
   )
  ]
 )
)

Upvotes: 1

Related Questions