Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

hide widget from ui without taking any space

I have a code like below, I want to hide the subtitle text using if, but when the subtitle is hidden, it adds empty space under the title, but if the subtitle text is removed, it will work fine

enter image description here

Column(
  children : [
    SizedBox(height: AppTheme.space1),
    Image.asset(
      image,
      width: 128,
      height: 128,
    ),
    SizedBox(height: AppTheme.space2),
    Text(
      title,
      style: Theme.of(context).textTheme.headline2,
      textAlign: TextAlign.center,
    ),
    if (subTitle != null)
      SizedBox(height: AppTheme.space0),
    if (subTitle != null)
      Text(
        subTitle ?? '',
        style: Theme.of(context).textTheme.bodyText1,
      ),
    SizedBox(height: AppTheme.space3),
    Button(
      onPressed: () {
        Navigator.pop(context, returnTextYes);
        onTapPrimaryButton?.call();
      },
      text: textYes,
    ),
  ]
)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use Visibility Widget

bool isVisible = subtitle.isNotEmpty

Visibility(
visible:isVisible
child: Text(
          subTitle ?? '',
          style: Theme.of(context).textTheme.bodyText1,
        )
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading