Skip to content

Instantly share code, notes, and snippets.

@matifdeveloper
Created January 23, 2024 05:04
Show Gist options
  • Save matifdeveloper/1b11b034b7eb14210be148b226f0178b to your computer and use it in GitHub Desktop.
Save matifdeveloper/1b11b034b7eb14210be148b226f0178b to your computer and use it in GitHub Desktop.
Text Animation Flutter

Text Animation Flutter

Created with <3 with dartpad.dev.

import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Animated Text Demo'),
),
body: Center(
child: AnimatedTextWidgets(),
),
),
);
}
}
class AnimatedTextWidgets extends StatefulWidget {
@override
State<AnimatedTextWidgets> createState() => _AnimatedTextWidgetsState();
}
class _AnimatedTextWidgetsState extends State<AnimatedTextWidgets> {
List<String> texts = ['Hello,', 'Flutter!', 'Welcome!'];
int currentIndex = 0;
@override
void initState() {
super.initState();
animateText();
}
Future<void> animateText() async {
await Future.delayed(const Duration(seconds: 1));
setState(() {
currentIndex = 1;
});
await Future.delayed(const Duration(seconds: 2));
setState(() {
currentIndex = 2;
});
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnimatedOpacity(
duration: const Duration(seconds: 1),
opacity: currentIndex == 0 ? 1.0 : 0.0,
child: const Text(
'Hello,',
style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
),
),
AnimatedOpacity(
duration: const Duration(seconds: 1),
opacity: currentIndex == 1 ? 1.0 : 0.0,
child: const Text(
'Flutter!',
style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
),
),
AnimatedOpacity(
duration: const Duration(seconds: 1),
opacity: currentIndex == 2 ? 1.0 : 0.0,
child: const Text(
'Welcome!',
style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment