dreampad/lib/app/modules/welcome/views/welcome_view.dart

133 lines
4.7 KiB
Dart
Raw Normal View History

2023-11-29 20:37:45 +08:00
import 'package:dreampad/app/modules/welcome/views/hello_widget.dart';
import 'package:dreampad/app/modules/welcome/views/input_widget.dart';
import 'package:dreampad/app/modules/welcome/views/partner_widget.dart';
2023-11-28 10:44:58 +08:00
import 'package:dreampad/app/shared/shared.dart';
import 'package:flutter/material.dart';
2023-11-29 20:37:45 +08:00
import 'package:flutter_hooks/flutter_hooks.dart';
2023-11-28 10:44:58 +08:00
import 'package:get/get.dart';
import '../controllers/welcome_controller.dart';
2023-11-29 20:37:45 +08:00
import 'splash_view.dart';
2023-11-28 10:44:58 +08:00
class WelcomeView extends GetView<WelcomeController> {
2023-11-29 20:37:45 +08:00
const WelcomeView({super.key});
2023-11-28 10:44:58 +08:00
@override
Widget build(BuildContext context) {
2023-11-29 20:37:45 +08:00
return SwipeNextPageContainer(
2023-11-28 10:44:58 +08:00
children: [
2023-11-29 20:37:45 +08:00
const _Background(),
HookBuilder(builder: (context) {
final currentIndexState =
SwipeNextPageContainer.of(context)!.currentIndex;
final showWelcomeView = useListenableSelector(
currentIndexState, () => currentIndexState.value == 1);
return AnimatedVisibilityWidget(
isVisible: showWelcomeView,
animationWidgetBuilder:
AnimatedVisibilityWidget.fadeAnimationWidgetBuilder,
child: Visibility(
visible: showWelcomeView,
child: SwipeNextPageContainer(
children: [
SwipePageCurrentVisible(
child: HookBuilder(builder: (context) {
final finishInput = useState(false);
final showPartner = useState(false);
return showPartner.value
? const PartnerWidget()
: AnimatedVisibilityWidget(
isVisible: !finishInput.value,
duration: const Duration(milliseconds: 800),
2023-11-30 10:16:09 +08:00
curve: Curves.fastOutSlowIn,
2023-11-29 20:37:45 +08:00
animationWidgetBuilder: AnimatedVisibilityWidget
.fadeAnimationWidgetBuilder,
onDone: (visible) {
if (!visible) {
showPartner.value = true;
}
},
child: InputWidget(
onFinished: () {
finishInput.value = true;
},
),
);
}),
2023-11-28 10:44:58 +08:00
),
2023-11-29 20:37:45 +08:00
const SwipePageFadeOutContainer(
child: HelloWidget(),
2023-11-28 10:44:58 +08:00
),
2023-11-29 20:37:45 +08:00
],
),
2023-11-28 10:44:58 +08:00
),
2023-11-29 20:37:45 +08:00
);
}),
const SwipePageFadeOutContainer(
child: SplashView(),
2023-11-28 10:44:58 +08:00
),
],
);
}
2023-11-29 20:37:45 +08:00
}
2023-11-28 10:44:58 +08:00
2023-11-29 20:37:45 +08:00
class _Background extends StatelessWidget {
const _Background();
2023-11-28 10:44:58 +08:00
2023-11-29 20:37:45 +08:00
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraint) {
final controller = SwipeNextPageContainer.of(context)!.controller;
final currentIndexState =
SwipeNextPageContainer.of(context)!.currentIndex;
return HookBuilder(builder: (context) {
final currentIndex = useListenableSelector(currentIndexState, () {
return currentIndexState.value;
});
return AnimatedBuilder(
animation: controller,
builder: (context, _) {
final animationValue =
currentIndex == 2 ? controller.value : controller.upperBound;
return Stack(
children: [
Positioned(
top: 0 - animationValue + 1,
left: -2,
right: 2,
child: Container(
width: constraint.maxWidth,
height: constraint.maxHeight,
decoration: const BoxDecoration(
image: DecorationImage(
image: Images.splashBg,
fit: BoxFit.fill,
),
),
),
2023-11-28 10:44:58 +08:00
),
2023-11-29 20:37:45 +08:00
Positioned(
top: controller.upperBound - animationValue,
left: 0,
right: 0,
child: Container(
width: constraint.maxWidth,
height: constraint.maxHeight,
decoration: const BoxDecoration(
image: DecorationImage(
image: Images.welcomeBg,
fit: BoxFit.fill,
),
),
2023-11-28 10:44:58 +08:00
),
2023-11-29 20:37:45 +08:00
),
],
);
});
});
});
2023-11-28 10:44:58 +08:00
}
}