Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- child: TypingAnimation(
- text: 'Delivered! From Your Finger Tips',
- // style: TextStyle(
- // fontSize: 18.0,
- // color: Colors.white
- // ),
- )
- ========== TypingAnimation.dart ====================
- import 'package:flutter/material.dart';
- class TypingAnimation extends StatefulWidget {
- final String text;
- TypingAnimation({required this.text});
- @override
- _TypingAnimationState createState() => _TypingAnimationState();
- }
- class _TypingAnimationState extends State<TypingAnimation> {
- String typedText = '';
- int textIndex = 0;
- bool showCursor = true; // Track cursor visibility
- @override
- void initState() {
- super.initState();
- _startTypingAnimation();
- }
- void _startTypingAnimation() {
- Future.delayed(const Duration(milliseconds: 200), () {
- setState(() {
- typedText = widget.text.substring(0, textIndex);
- textIndex++;
- // Toggle cursor visibility
- showCursor = !showCursor;
- if (textIndex <= widget.text.length) {
- _startTypingAnimation();
- } else {
- // Reset the animation to run in a loop
- textIndex = 0;
- _startTypingAnimation();
- }
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- // Add a cursor "|" at the end if it should be shown
- final textWithCursor = showCursor ? '$typedText|' : typedText;
- return Positioned(
- left: 0.0,
- right: 0,
- top: 86.0,
- child: Center(
- child: Text(
- textWithCursor,
- style: TextStyle(
- fontSize: 18.0,
- color: Colors.white,
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement