Skip to content

Commit

Permalink
Merge pull request #10 from VGVentures/feat/animate-current-savings
Browse files Browse the repository at this point in the history
feat: animate current savings
  • Loading branch information
B0berman authored Aug 19, 2024
2 parents b7830eb + b5ffeb0 commit 06e4476
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions lib/demo/widgets/current_savings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@ import 'package:financial_dashboard/ui/ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class CurrentSavings extends StatelessWidget {
class CurrentSavings extends StatefulWidget {
const CurrentSavings({
super.key,
});

@override
State<CurrentSavings> createState() => _CurrentSavingsState();
}

class _CurrentSavingsState extends State<CurrentSavings>
with TickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _animation;

@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
final l10n = context.l10n;
Expand All @@ -17,12 +41,24 @@ class CurrentSavings extends StatelessWidget {
(FinancialDataBloc bloc) => bloc.state.currentSavings,
);

_animation = Tween<double>(begin: 0, end: currentSavings).animate(
_controller,
);

_controller.forward();

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
currentSavings.toCurrencyWithoutDecimal(),
style: textTheme.displayMedium,
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
final value = _animation.value;
return Text(
value.toCurrencyWithoutDecimal(),
style: textTheme.displayMedium,
);
},
),
const SizedBox(height: AppSpacing.xs),
Text(
Expand Down

0 comments on commit 06e4476

Please sign in to comment.