flutterflutter-container

Is there a logic that allows the display of an image when available in container in flutter?


image 1

Is it possible to create a logic that allows the container to only display only text (image above) or text and image (image below) when image is available.

image 2


Solution

  • Let's say person is an object that has a name and optionally an image. Then this is a way to write it

    Column(
      children: [
        Text(person.name),
        if (person.image != null) Image.network(person.image!)
      ],
    )