Fix word card resize on load and add points animation

pull/2245/head
avashilling 4 months ago
parent 7d92e81f56
commit 5205ec8775

@ -1,3 +1,4 @@
import 'package:fluffychat/pangea/analytics_misc/gain_points_animation.dart';
import 'package:fluffychat/pangea/constructs/construct_level_enum.dart'; import 'package:fluffychat/pangea/constructs/construct_level_enum.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -26,7 +27,7 @@ class _NewWordOverlayState extends State<NewWordOverlay>
late final Animation<double> _fadeAnim; late final Animation<double> _fadeAnim;
late final Animation<Alignment> _alignmentAnim; late final Animation<Alignment> _alignmentAnim;
late final Animation<Offset> _offsetAnim; late final Animation<Offset> _offsetAnim;
final bool _showOverlay = true; bool pointsBlast = false;
Widget xpSeedWidget = const SizedBox(); Widget xpSeedWidget = const SizedBox();
Widget? get svg => ConstructLevelEnum.seeds.icon(); Widget? get svg => ConstructLevelEnum.seeds.icon();
@override @override
@ -34,7 +35,7 @@ class _NewWordOverlayState extends State<NewWordOverlay>
super.initState(); super.initState();
_controller = AnimationController( _controller = AnimationController(
vsync: this, vsync: this,
duration: const Duration(milliseconds: 2500), duration: const Duration(milliseconds: 2000),
); );
_xpScaleAnim = CurvedAnimation( _xpScaleAnim = CurvedAnimation(
@ -43,7 +44,7 @@ class _NewWordOverlayState extends State<NewWordOverlay>
); );
_fadeAnim = CurvedAnimation( _fadeAnim = CurvedAnimation(
parent: _controller, parent: _controller,
curve: const Interval(0.5, 1.0, curve: Curves.easeOut), curve: const Interval(0.7, 1.0, curve: Curves.easeOut),
); );
_alignmentAnim = AlignmentTween( _alignmentAnim = AlignmentTween(
@ -67,6 +68,14 @@ class _NewWordOverlayState extends State<NewWordOverlay>
), ),
); );
_controller.addListener(() {
if (!pointsBlast && _controller.value >= 0.6) {
setState(() {
pointsBlast = true;
});
}
});
xpSeedWidget = Container( xpSeedWidget = Container(
child: svg, child: svg,
); );
@ -84,15 +93,19 @@ class _NewWordOverlayState extends State<NewWordOverlay>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (!_showOverlay) return widget.child; if (!widget.show) return widget.child;
return Stack( return Stack(
children: [ children: [
widget.child, widget.child,
Positioned.fill( Positioned(
child: FadeTransition( left: 5,
right: 5,
top: 5,
bottom: 5,
child: Stack(
children: [
FadeTransition(
opacity: ReverseAnimation(_fadeAnim), opacity: ReverseAnimation(_fadeAnim),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container( child: Container(
color: widget.overlayColor, color: widget.overlayColor,
child: AnimatedBuilder( child: AnimatedBuilder(
@ -105,7 +118,7 @@ class _NewWordOverlayState extends State<NewWordOverlay>
child: ScaleTransition( child: ScaleTransition(
scale: _xpScaleAnim, scale: _xpScaleAnim,
child: Transform.scale( child: Transform.scale(
scale: 2 * (1 - _fadeAnim.value), scale: 2 * (.8 - _fadeAnim.value),
child: xpSeedWidget, child: xpSeedWidget,
), ),
), ),
@ -115,6 +128,16 @@ class _NewWordOverlayState extends State<NewWordOverlay>
), ),
), ),
), ),
pointsBlast
? const Align(
alignment: Alignment.bottomCenter,
child: PointsGainedAnimation(
points: 10,
targetID: "",
),
)
: const SizedBox.shrink(),
],
), ),
), ),
], ],

@ -43,9 +43,8 @@ class WordZoomWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isNewWord = wordIsNew;
final overlayColor = Theme.of(context).scaffoldBackgroundColor; final overlayColor = Theme.of(context).scaffoldBackgroundColor;
Widget card = Container( final Widget card = Container(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
constraints: const BoxConstraints( constraints: const BoxConstraints(
minHeight: AppConfig.toolbarMinHeight - 8, minHeight: AppConfig.toolbarMinHeight - 8,
@ -245,13 +244,11 @@ class WordZoomWidget extends StatelessWidget {
), ),
), ),
); );
if (isNewWord) { // Only wrap in NewWordOverlay if wordIsNew is true
card = NewWordOverlay( return NewWordOverlay(
show: true, show: wordIsNew,
overlayColor: overlayColor, overlayColor: overlayColor,
child: card, child: card,
); );
} }
return card;
}
} }

Loading…
Cancel
Save