How to create typing text animation in Flutter

In this Google flutter code example we are going to learn how to create typing text animation in Flutter.

You can copy and adopt this source code example to your android project without reinventing the wheel.

The code is based on flutter version 1.

Main.dart (App entry point)

import 'package:flutter/material.dart';
import 'typing_text_animation_task-18.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        // This is the theme of your application.
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
      home: TypingTextAnimation(),


import 'package:flutter/material.dart';

class TypingTextAnimation extends StatefulWidget {
  State createState() => new TypingTextAnimationState();

class TypingTextAnimationState extends State<TypingTextAnimation>
    with TickerProviderStateMixin {
  Animation<int> _characterCount;

  int _stringIndex;
  static const List<String> _kStrings = const <String>[
  String get _currentString => _kStrings[_stringIndex % _kStrings.length];
  AnimationController controller;

  void initState() {
    controller = new AnimationController(
      duration: const Duration(milliseconds: 4000),
      vsync: this,
    setState(() {
      _stringIndex = _stringIndex == null ? 0 : _stringIndex + 1;
      _characterCount = new StepTween(begin: 0, end: _currentString.length)
              new CurvedAnimation(parent: controller, curve: Curves.easeIn));

  void dispose() {

  Widget build(BuildContext context) {
    ThemeData theme = Theme.of(context);
    TextStyle textStyle = theme.textTheme.title.copyWith(
      color: theme.primaryColor,
    return new Scaffold(
      appBar: AppBar(title: Text("Typing Text Animation")),
      body: new Container(
        margin: new EdgeInsets.symmetric(vertical: 50.0, horizontal: 10.0),
        child: _characterCount == null
            ? null
            : new AnimatedBuilder(
                animation: _characterCount,
                builder: (BuildContext context, Widget child) {
                  String text =
                      _currentString.substring(0, _characterCount.value);
                  return new Text(text, style: textStyle);

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.


Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.