'How to show widget sent from another page based on a condition in flutter

I have a page that I use in common. I'm posting a "widget" named "custom widget" on this page. If "custom widget" is sent I want to show it. If it's not sent, don't do anything. How can I achieve this?

enter image description here



Solution 1:[1]

use your custom widget like this:

customWidget != null ? Row(children: [customWidget!]) : Container()

Solution 2:[2]

Check if the customWidget is null and show it if it's not.

customWidget ?? Container()

Solution 3:[3]

you can use the if condition like below.

Row(
  children: [
    if (customWidget != null) customWidget,
  ],
),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 reza
Solution 2 Dani3le_
Solution 3 nagendra nag