Thor
Thor

Reputation: 559

How can I return either a specific container widget, or nothing at all

I am using the Dismissible widget for swiping within my application. However, I wish to reuse the swiping activity, without the ability for the user to swipe. The whole class is wrapped in the dismissible.

So the overall code looks something like this:

Dimissible(
   Row(
       Column(
         // random code
       ),
   ),
);

Whereas I want to be able to either have everything wrapped inside the dismissble, or not, without having to copy paste the entire code into a new class. Any suggestions?

Upvotes: 0

Views: 314

Answers (1)

Vicky Salunkhe
Vicky Salunkhe

Reputation: 10975

How can I return either a specific container widget, or nothing at all

How would I go about that. Either return the dismissible or instead null? Wouldn't that leave me with an exception?

You can return a blank Container() or a SizedBox() widget (when you condition meets to return null).

Flutter will not throw an error then.

Upvotes: 1

Related Questions