4 Commits

  1. 68
      lib/core/widgets/animations/globe_animation.dart
  2. 11
      lib/features/question/presentation/bloc/question_bloc.dart
  3. 11
      lib/features/question/presentation/ui/screens/question_screen.dart

68
lib/core/widgets/animations/globe_animation.dart

@ -4,10 +4,9 @@ import 'package:flutter/material.dart';
import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart';
class GlobeAnimation extends StatefulWidget {
const GlobeAnimation({super.key, required this.child, this.state = true});
const GlobeAnimation({super.key, required this.child});
final Widget child;
final bool state;
@override
State<GlobeAnimation> createState() => _GlobeAnimationState();
@ -25,55 +24,34 @@ class _GlobeAnimationState extends State<GlobeAnimation>
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
reverseDuration: const Duration(seconds: 1),
duration: const Duration(hours: 1),
reverseDuration: const Duration(hours: 1),
);
_animation = Tween<double>(
begin: 1,
end: 1.05,
).animate(CurvedAnimation(parent: _controller, curve: Curves.linear));
}
@override
void didUpdateWidget(covariant GlobeAnimation oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.state) {
_controller.repeat(reverse: true);
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (_gradient == null) {
if (!mounted) return;
setState(() {
_gradient = RadialGradient(
colors: [
const Color(0XFFDFCD00),
const Color(0XFFDFCD00).withValues(alpha: 0.35),
const Color(0XFFDFCD00).withValues(alpha: 0),
],
center: Alignment.center,
);
});
} else {
setState(() {
_gradient = null;
});
}
});
} else {
_timer?.cancel();
_timer = null;
_controller.stop();
if (!mounted) return;
setState(() {
_gradient = RadialGradient(
colors: [
const Color(0XFFDFCD00).withValues(alpha: 0),
const Color(0XFFDFCD00).withValues(alpha: 0),
const Color(0XFFDFCD00).withValues(alpha: 0),
],
center: Alignment.center,
);
});
}
_controller.repeat(reverse: true);
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (_gradient == null) {
if (!mounted) return;
setState(() {
_gradient = RadialGradient(
colors: [
const Color(0XFFDFCD00),
const Color(0XFFDFCD00).withValues(alpha: 0.35),
const Color(0XFFDFCD00).withValues(alpha: 0),
],
center: Alignment.center,
);
});
} else {
setState(() {
_gradient = null;
});
}
});
}
@override

11
lib/features/question/presentation/bloc/question_bloc.dart

@ -87,10 +87,10 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> {
// );
// }
// Future<void> showImageWithDelayed() async {
// await Future.delayed(const Duration(milliseconds: 500));
// imageAnimationController?.forward();
// }
Future<void> showImageWithDelayed() async {
await Future.delayed(const Duration(milliseconds: 500));
imageAnimationController?.forward();
}
void showHadith({required BuildContext context}) {
showHadithDialog(
@ -240,6 +240,7 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> {
showAnswers: false,
correctAnswer: false,
));
showImageWithDelayed();
await playQuestionAudio();
imageAnimationController?.reverse();
answerAnimationController?.forward().then((value) {
@ -290,7 +291,7 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> {
} else {
showingAnswerSequence(show: true);
await Future.delayed(const Duration(seconds: 1));
imageAnimationController?.forward();
showImageWithDelayed();
scrollController.jumpTo(0);
await playQuestionAudio();
imageAnimationController?.reverse();

11
lib/features/question/presentation/ui/screens/question_screen.dart

@ -389,7 +389,6 @@ class _QuestionScreenState extends State<QuestionScreen>
alignment: AlignmentDirectional.centerStart,
children: [
GlobeAnimation(
state: true,
child: MyImage(
image: MyAssets.globe,
fit: BoxFit.cover,
@ -403,10 +402,12 @@ class _QuestionScreenState extends State<QuestionScreen>
controller: context.read<QuestionBloc>().imageAnimationController!,
child: TextButton(
onPressed: () async {
context.read<QuestionBloc>().imageAnimationController?.reverse();
context.read<QuestionBloc>().answerAnimationController?.forward();
context.read<QuestionBloc>().showingAnswerSequence(show: false);
context.read<QuestionBloc>().pausePlaying();
if(context.read<QuestionBloc>().imageAnimationController?.isForwardOrCompleted ?? false){
context.read<QuestionBloc>().imageAnimationController?.reverse();
context.read<QuestionBloc>().answerAnimationController?.forward();
context.read<QuestionBloc>().showingAnswerSequence(show: false);
context.read<QuestionBloc>().pausePlaying();
}
},
style: TextButton.styleFrom(
foregroundColor: MyColors.white.withValues(alpha: 0.7),

Loading…
Cancel
Save