Type 1:
import 'package:flutter/material.dart';
import 'package:k2k/resource/style/app_colors.dart';
import 'package:lottie/lottie.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class SuccessDialog extends StatefulWidget {
final String message;
const SuccessDialog({super.key, required this.message});
@override
_SuccessDialogState createState() => _SuccessDialogState();
}
class _SuccessDialogState extends State<SuccessDialog>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _scaleAnimation;
late Animation<double> _fadeAnimation;
late Animation<double> _lineAnimation;
@override
void initState() {
super.initState();
// Animation controller for scale, fade, and strikethrough animations
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1500),
);
_scaleAnimation = CurvedAnimation(
parent: _animationController,
curve: Curves.easeOutBack,
);
_fadeAnimation = Tween<double>(begin: 0, end: 1).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
),
);
_lineAnimation = Tween<double>(begin: 0, end: 1).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
),
);
// Start the animation
_animationController.forward();
// Automatically close the dialog after 2.3 seconds
Future.delayed(const Duration(milliseconds: 2300), () {
if (Get.isDialogOpen!) {
_animationController.reverse().then((_) {
Get.back();
});
}
});
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ScaleTransition(
scale: _scaleAnimation,
child: Dialog(
backgroundColor: Colors.transparent, // To allow gradient visibility
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r),
),
child: Container(
padding: EdgeInsets.all(16.w), // Responsive padding
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.r),
gradient: const LinearGradient(
colors: [Colors.white, Colors.white],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Lottie Animation
Lottie.asset(
'assets/splash/addcarta.json',
width: double.infinity,
height: 100.h,
),
SizedBox(height: 8.h),
// Animated Text with Strikethrough Animation
FadeTransition(
opacity: _fadeAnimation,
child: Stack(
alignment: Alignment.center,
children: [
// Text Message
Text(
widget.message,
style: TextStyle(
fontSize: 16.sp, // Responsive font size
fontWeight: FontWeight.bold,
color: AppColors.primaryColor,
),
textAlign: TextAlign.center,
),
// Strikethrough Animation Line
AnimatedBuilder(
animation: _lineAnimation,
builder: (context, child) {
return CustomPaint(
painter: StrikethroughPainter(_lineAnimation.value),
child: Container(
height: 20.h,
),
);
},
),
],
),
),
],
),
),
),
);
}
}
// Custom Painter for the Strikethrough effect
class StrikethroughPainter extends CustomPainter {
final double progress;
StrikethroughPainter(this.progress);
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.white
..strokeWidth = 2.0;
final startX = 0.0;
final endX = size.width * progress;
final y = size.height / 2;
canvas.drawLine(Offset(startX, y), Offset(endX, y), paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
Type 2:
import 'package:flutter/material.dart';
import 'package:k2k/resource/style/app_colors.dart';
import 'package:lottie/lottie.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class SuccessDialog extends StatefulWidget {
final String message;
const SuccessDialog({super.key, required this.message});
@override
_SuccessDialogState createState() => _SuccessDialogState();
}
class _SuccessDialogState extends State<SuccessDialog>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _scaleAnimation;
late Animation<double> _fadeAnimation;
late Animation<double> _lineAnimation;
@override
void initState() {
super.initState();
// Animation controller for scale, fade, and strikethrough animations
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 500),
);
_scaleAnimation = CurvedAnimation(
parent: _animationController,
curve: Curves.easeOutBack,
);
_fadeAnimation = Tween<double>(begin: 0, end: 1).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
),
);
_lineAnimation = Tween<double>(begin: 0, end: 1).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
),
);
// Start the animation
_animationController.forward();
// Automatically close the dialog after 2.3 seconds
Future.delayed(const Duration(milliseconds: 2300), () {
if (Get.isDialogOpen!) {
_animationController.reverse().then((_) {
Get.back();
});
}
});
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ScaleTransition(
scale: _scaleAnimation,
child: Dialog(
backgroundColor: Colors.transparent, // To allow gradient visibility
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r),
),
child: Container(
padding: EdgeInsets.all(16.w), // Responsive padding
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.r),
gradient: const LinearGradient(
colors: [AppColors.primaryColor, AppColors.borderColor],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Lottie Animation
Lottie.asset(
'assets/splash/addcarta.json',
width: double.infinity,
height: 80.h,
),
SizedBox(height: 8.h),
// Animated Text with Strikethrough Animation
FadeTransition(
opacity: _fadeAnimation,
child: Stack(
alignment: Alignment.center,
children: [
// Text Message
Text(
widget.message,
style: TextStyle(
fontSize: 16.sp, // Responsive font size
fontWeight: FontWeight.bold,
color: Colors.white,
),
textAlign: TextAlign.center,
),
// Strikethrough Animation Line
AnimatedBuilder(
animation: _lineAnimation,
builder: (context, child) {
return CustomPaint(
painter: StrikethroughPainter(_lineAnimation.value),
child: Container(
height: 20.h,
),
);
},
),
],
),
),
],
),
),
),
);
}
}
// Custom Painter for the Strikethrough effect
class StrikethroughPainter extends CustomPainter {
final double progress;
StrikethroughPainter(this.progress);
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.white
..strokeWidth = 2.0;
final startX = 0.0;
final endX = size.width * progress;
final y = size.height / 2;
canvas.drawLine(Offset(startX, y), Offset(endX, y), paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
Type 3:
import 'package:flutter/material.dart';
import 'package:k2k/resource/style/app_colors.dart';
import 'package:lottie/lottie.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class SuccessDialog extends StatefulWidget {
final String message;
const SuccessDialog({super.key, required this.message});
@override
_SuccessDialogState createState() => _SuccessDialogState();
}
class _SuccessDialogState extends State<SuccessDialog>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _scaleAnimation;
late Animation<double> _fadeAnimation;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 500),
);
_scaleAnimation = CurvedAnimation(
parent: _animationController,
curve: Curves.easeOutBack,
);
_fadeAnimation = Tween<double>(begin: 0, end: 1).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
),
);
_animationController.forward();
Future.delayed(const Duration(milliseconds: 2300), () {
if (Get.isDialogOpen!) {
_animationController.reverse().then((_) {
Get.back();
});
}
});
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ScaleTransition(
scale: _scaleAnimation,
child: Dialog(
backgroundColor: Colors.transparent, // To allow gradient visibility
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.r),
),
child: Container(
padding: EdgeInsets.all(20.w), // Responsive padding
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.r),
gradient: LinearGradient(
colors: [Colors.greenAccent, AppColors.bgColor],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Lottie Animation
Lottie.asset(
'assets/splash/addcarta.json',
width: double.infinity,
height: 80.h,
),
SizedBox(height: 8.h),
// Animated Text
FadeTransition(
opacity: _fadeAnimation,
child: Text(
widget.message,
style: TextStyle(
fontSize: 16.sp, // Responsive font size
fontWeight: FontWeight.bold,
color: Colors.white,
),
textAlign: TextAlign.center,
),
),
],
),
),
),
);
}
}