dreampad/lib/app/modules/welcome/views/welcome_view.dart
2023-11-30 14:59:03 +08:00

133 lines
4.7 KiB
Dart

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';
import 'package:dreampad/app/shared/shared.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:get/get.dart';
import '../controllers/welcome_controller.dart';
import 'splash_view.dart';
class WelcomeView extends GetView<WelcomeController> {
const WelcomeView({super.key});
@override
Widget build(BuildContext context) {
return SwipeNextPageContainer(
children: [
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),
curve: Curves.fastOutSlowIn,
animationWidgetBuilder: AnimatedVisibilityWidget
.fadeAnimationWidgetBuilder,
onDone: (visible) {
if (!visible) {
showPartner.value = true;
}
},
child: InputWidget(
onFinished: () {
finishInput.value = true;
},
),
);
}),
),
const SwipePageFadeOutContainer(
child: HelloWidget(),
),
],
),
),
);
}),
const SwipePageFadeOutContainer(
child: SplashView(),
),
],
);
}
}
class _Background extends StatelessWidget {
const _Background();
@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,
),
),
),
),
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,
),
),
),
),
],
);
});
});
});
}
}