You want to controll opacity dynamicaly but you don’t want to remove the widget that has opacity = 0

Dart

Problem

You want to implement some animation in flutter. And you are using flutter_hooks as state management.

Once the opacity = 0, the widget will be disposed. And the state will be disposed automatically.

How do you have it remain on the widget Tree?

Solve

Visibility is it. You should wrap your widget you want to manage your opacity and don't want to dispose.

      child: Visibility(
        maintainSize: true,
        maintainAnimation: true,
        maintainState: true,
        child: AnimatedOpacity(
          duration: const Duration(milliseconds: 500),
          opacity: isVisible.value ? 1.0 : 0.0,
          child: Row(
          // continue...

コメント

タイトルとURLをコピーしました