Browse Source

fix: globe animation

pull/62/head
AmirrezaChegini 5 days ago
parent
commit
4d68dcf2f7
  1. 64
      lib/core/widgets/animations/globe_animation.dart
  2. 1
      lib/features/question/presentation/ui/screens/question_screen.dart

64
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();
@ -32,48 +31,27 @@ class _GlobeAnimationState extends State<GlobeAnimation>
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

1
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,

Loading…
Cancel
Save