Updated 10 May 2024
Introducing scratch card animations to your Flutter app can be just the unique touch you need to captivate users and enhance engagement. Imagine the anticipation as users swipe away to reveal hidden content, reminiscent of lottery scratch cards. In this blog, we’ll explore how you can effortlessly integrate Scratch card animation into your Flutter app, creating an immersive and interactive user experience.
Before starting with the blog, if you are looking to develop Mobile Apps, you can check out Flutter development services offered by Mobikul.
1 2 |
scratcher: ^2.5.0 confetti: ^0.7.0 |
2. Create new stateful class (ScratchCard) and add code for UI as showing below :-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
class ScratchCard extends StatefulWidget { const ScratchCard({Key? key}) : super(key: key); @override State<ScratchCard> createState() => _ScratchCardState(); } class _ScratchCardState extends State<ScratchCard> { late ConfettiController _controller; @override void initState() { super.initState(); _controller = ConfettiController( duration: const Duration(seconds: 2), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text("Scratch card")), body: Center( child: Scratcher( brushSize: 50, threshold: 75, color: Colors.red, image: Image.asset( "assets/images/outerImage.png", fit: BoxFit.fill, ), onChange: (value) => print("Scratch progress: $value%"), onThreshold: () => _controller.play(), child: Container( height: 300, width: 300, color: Colors.purple, child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.asset( "assets/images/newImage.png", fit: BoxFit.contain, width: 250, height: 250, ), Column( children: [ ConfettiWidget( blastDirectionality: BlastDirectionality.explosive, confettiController: _controller, particleDrag: 0.05, emissionFrequency: 0.05, numberOfParticles: 100, gravity: 0.05, shouldLoop: false, colors: const [ Colors.green, Colors.red, Colors.yellow, Colors.blue, Colors.purple ], ), ], ), ], ), ), ), ), ); } } |
In above example code we have create basic UI to display two asses images to add scratch animation in app as :-
SlimyCard Animation in Flutter
Thanks for reading this article ❤️
I hope this blog will help you to learn about scratch card animation in flutter and you will be able to implement it. For more updates, make sure to keep following Mobikul Blogs to learn more about mobile app development.
Happy Learning ✍️
Other blogs you may like…
Flip Card Animation in Android
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.