Animation in Flutter Linear Gauge (SfLinearGauge)

18 Nov 20186 minutes to read

All Linear Gauge elements such as axis (along with ticks and labels), range, bar pointer, shape marker pointer, and widget marker pointer can be animated separately.

Animate axis

The animateAxis and animationDuration properties in SfLinearGauge are used to animate the axis track along with the ticks and labels. The axis will have a fade-in with opacity animation when animateAxis is set to true. By default, the animateAxis is set to false.

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';

void main() => runApp(const LinearGaugeDemo());

class LinearGaugeDemo extends StatelessWidget {
  const LinearGaugeDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: SfLinearGauge(
            animateAxis: true,
            animationDuration: 3000
          ),
        ),
      ),
    );
  }
}

Animate axis in Flutter Linear Gauge

Animate range

The animateRange and animationDuration properties in SfLinearGauge are used to animate ranges. The range will have a fade-in with opacity animation when animateRange is set to true. By default, the animateRange is set to false.

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';

void main() => runApp(const LinearGaugeDemo());

class LinearGaugeDemo extends StatelessWidget {
  const LinearGaugeDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: SfLinearGauge(
            animateRange: true,
            animationDuration: 3000
          ),
        ),
      ),
    );
  }
}

Animate range in Flutter Linear Gauge

Pointer animation

The animation behavior is common for all three pointers in Linear Gauge - shape pointer, widget pointer, and bar pointer.

All three pointers have the following properties for animation:

The animationType supports the following animations. The default animation type is animationType.ease.

  • bounceOut
  • ease
  • easeInCir
  • easeOutBack
  • elasticOut
  • linear
  • slowMiddle

Animate bar pointer

The following code example demonstrates how to customize the animation for bar pointer:

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';

void main() => runApp(const LinearGaugeDemo());

class LinearGaugeDemo extends StatelessWidget {
  const LinearGaugeDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: SfLinearGauge(
            barPointers: [
              LinearBarPointer(
                value: 50,
                animationDuration: 2000,
                animationType: LinearAnimationType.bounceOut
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Animate marker pointers (Shape and Widget Pointers)

Both the shape and widget marker pointers have the same set of properties and behave similarly for animation. The example below demonstrates LinearShapePointer but the same principles apply to LinearWidgetPointer as well.

Marker pointer with bounceOut animation

The following code example demonstrates how to animate a shape marker pointer with bounceOut animation type:

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';

void main() => runApp(const LinearGaugeDemo());

class LinearGaugeDemo extends StatelessWidget {
  const LinearGaugeDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: SfLinearGauge(
            markerPointers: [
              LinearShapePointer(
                value: 60,
                animationType: LinearAnimationType.bounceOut,
                animationDuration: 2000,
                enableAnimation: true,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Animate marker pointer in Flutter Linear Gauge