import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; import 'package:confetti/confetti.dart'; import 'dart:math'; import '../../../l10n/app_localizations.dart'; class BeneficiaryResultPage extends StatefulWidget { final bool isSuccess; const BeneficiaryResultPage({super.key, required this.isSuccess}); @override State createState() => _BeneficiaryResultPageState(); } class _BeneficiaryResultPageState extends State { late ConfettiController _confettiController; @override void initState() { super.initState(); _confettiController = ConfettiController(duration: const Duration(seconds: 3)); if (widget.isSuccess) { _confettiController.play(); } } @override void dispose() { _confettiController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final successAnimation = 'assets/animations/done.json'; final errorAnimation = 'assets/animations/error.json'; return Scaffold( backgroundColor: widget.isSuccess ? Colors.green[50] : Colors.red[50], body: Stack( alignment: Alignment.center, children: [ Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Lottie.asset( widget.isSuccess ? successAnimation : errorAnimation, width: 150, height: 150, repeat: false, ), const SizedBox(height: 20), Text( widget.isSuccess ? AppLocalizations.of(context).beneficiaryAddedSuccess : AppLocalizations.of(context).beneficiaryAdditionFailed, style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: widget.isSuccess ? Colors.green : Colors.red, ), textAlign: TextAlign.center, ), ], ), if (widget.isSuccess) Align( alignment: Alignment.topCenter, child: ConfettiWidget( confettiController: _confettiController, blastDirection: pi / 2, maxBlastForce: 10, minBlastForce: 5, emissionFrequency: 0.05, numberOfParticles: 20, gravity: 0.2, shouldLoop: false, ), ), ], ), ); } }