Andrei Volgin
Andrei Volgin

Reputation: 41089

SlideTransition in flutter takes space before it slides in

I implemented SlideTransition for a widget in flutter, and it slides in as expected. The issue is that before the animation is called, the space where the slider is going to be displayed later is empty.

How can I make the parent to give this space to other widgets in the layout until the moment that a slider comes into view?

I was thinking about giving a slider the initial height of zero, but then the widgets inside the slider would act funny as the height changes in sync with sliding. I wonder if there is a simpler way.

The parent is:

new Scaffold(
    appBar: _appBar,
    body: new Column(
      children: <Widget>[
        new Expanded(
          child: _body;
          }),
        ),
        new SlideTransition(
          position: _sliderPosition, // 
          child: _slider,
        ),
      ],
    );

And the position is defined as:

_sliderPosition = new MaterialPointArcTween(
  begin: const Offset(0.0, 1.0),
  end: Offset.zero,
).animate(_animationController);

Upvotes: 5

Views: 1856

Answers (2)

Thibault
Thibault

Reputation: 415

Bumped into the same issue with a SlideTransition taking the full height during a vertical slide. In the end I achieved the slide effect by using a SizeTransition instead, and setting its axisAlignment property accordingly (-1, 0, 1 for top/center/bottom in my case).

Upvotes: 4

Andrei Volgin
Andrei Volgin

Reputation: 41089

I solved this issue by replacing _slider with _buildSlider() which returns null until a slider is needed.

This is also better for performance as there is no need to render a slider if it's hidden.

Upvotes: 3

Related Questions