dreampad/lib/app/shared/widgets/animated_column_widget.dart

53 lines
1.6 KiB
Dart
Raw Normal View History

2023-11-29 20:37:45 +08:00
import 'package:dartx/dartx.dart';
import 'package:dreampad/app/shared/shared.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
class AnimatedColumnWidget extends HookWidget {
const AnimatedColumnWidget({
super.key,
required this.children,
this.mainAxisAlignment = MainAxisAlignment.start,
this.mainAxisSize = MainAxisSize.max,
this.onDone,
});
final List<Widget> children;
final VoidCallback? onDone;
final MainAxisAlignment mainAxisAlignment;
final MainAxisSize mainAxisSize;
@override
Widget build(BuildContext context) {
final displayIndex = useState(0);
return Column(
mainAxisAlignment: mainAxisAlignment,
mainAxisSize: mainAxisSize,
children: [
...children.mapIndexed((index, child) => AnimatedVisibilityWidget(
duration: const Duration(milliseconds: 800),
animationWidgetBuilder:
AnimatedVisibilityWidget.fadeAnimationWidgetBuilder,
isVisible: index <= displayIndex.value,
2023-11-30 14:58:48 +08:00
isInitAnimated: index == 0,
onDone: (visible) async {
2023-11-29 20:37:45 +08:00
if (visible) {
2023-11-30 14:58:48 +08:00
if (displayIndex.value == children.length - 1) {
2023-11-29 20:37:45 +08:00
onDone?.call();
2023-11-30 14:58:48 +08:00
} else {
await Future.delayed(const Duration(milliseconds: 500));
displayIndex.value = displayIndex.value + 1;
2023-11-29 20:37:45 +08:00
}
}
},
child: child,
)),
],
);
}
}