kipluo
Flutter8 min read4 steps

How to Build a Custom Loader Widget in Flutter

CircularProgressIndicator covers the basics; a custom loader is how you match a brand. This guide paints an arc spinner with CustomPainter, drives it with a repeating controller, adds a determinate mode, exposes progress to screen readers, and respects the reduce-motion setting.

You needFlutter 3.27+ (for Color.withValues)CustomPainter basicsAnimationController
Loading demo
The web version of Worm Loader, which also ships as the Flutter WormLoader widget.Component page

1. Anatomy of a loader widget

A loader has three jobs: show that work is happening, optionally show how much is done, and tell assistive technology the same thing. In Flutter that maps to an AnimationController for the loop, a CustomPainter for drawing, and a Semantics wrapper for the label and value.

Use AnimatedBuilder (or pass the controller as the painter's repaint listenable) so each frame only repaints the canvas instead of rebuilding widgets.

2. Paint an arc spinner

When value is null the arc rotates and its length breathes; when value is set, it draws a static arc proportional to progress. The controller repeats only while indeterminate and when the platform allows animations.

arc_loader.dart
import 'dart:math' as math;
import 'package:flutter/material.dart';

class ArcLoader extends StatefulWidget {
  const ArcLoader({super.key, this.value, this.size = 48, this.label = 'Loading'});

  /// 0..1 for determinate progress, null for indeterminate.
  final double? value;
  final double size;
  final String label;

  @override
  State<ArcLoader> createState() => _ArcLoaderState();
}

class _ArcLoaderState extends State<ArcLoader> with SingleTickerProviderStateMixin {
  late final AnimationController _controller = AnimationController(
    vsync: this,
    duration: const Duration(milliseconds: 1100),
  );

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _sync(); // re-runs when the reduce-motion setting changes
  }

  @override
  void didUpdateWidget(ArcLoader oldWidget) {
    super.didUpdateWidget(oldWidget);
    _sync();
  }

  void _sync() {
    final reduceMotion = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
    final shouldSpin = widget.value == null && !reduceMotion;
    if (shouldSpin && !_controller.isAnimating) {
      _controller.repeat();
    } else if (!shouldSpin && _controller.isAnimating) {
      _controller.stop();
    }
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final color = Theme.of(context).colorScheme.primary;
    final value = widget.value;
    return Semantics(
      label: widget.label,
      value: value == null ? null : '${(value * 100).round()}%',
      child: SizedBox.square(
        dimension: widget.size,
        child: AnimatedBuilder(
          animation: _controller,
          builder: (context, _) => CustomPaint(
            painter: _ArcPainter(turn: _controller.value, value: value, color: color),
          ),
        ),
      ),
    );
  }
}

class _ArcPainter extends CustomPainter {
  _ArcPainter({required this.turn, required this.value, required this.color});

  final double turn;
  final double? value;
  final Color color;

  @override
  void paint(Canvas canvas, Size size) {
    final stroke = size.width * 0.1;
    final rect = (Offset.zero & size).deflate(stroke / 2);
    final track = Paint()
      ..style = PaintingStyle.stroke
      ..strokeWidth = stroke
      ..color = color.withValues(alpha: 0.15);
    final arc = Paint()
      ..style = PaintingStyle.stroke
      ..strokeWidth = stroke
      ..strokeCap = StrokeCap.round
      ..color = color;

    canvas.drawCircle(rect.center, rect.width / 2, track);

    final v = value;
    if (v != null) {
      canvas.drawArc(rect, -math.pi / 2, 2 * math.pi * v.clamp(0.0, 1.0), false, arc);
    } else {
      final start = 2 * math.pi * turn - math.pi / 2;
      final sweep = math.pi * (0.4 + 0.6 * math.sin(math.pi * turn).abs());
      canvas.drawArc(rect, start, sweep, false, arc);
    }
  }

  @override
  bool shouldRepaint(_ArcPainter old) => old.turn != turn || old.value != value || old.color != color;
}

3. Add finished and failed states

Users need to know when loading ends, especially if it fails. Add a status parameter (running, complete, error) and draw a different end state for each: a full ring in a success colour, or a red ring with an icon. Update the Semantics label too, for example "Upload complete" or "Upload failed".

4. Kipluo loaders

Every Kipluo loader is a Flutter widget with the same shape of API: value (0–100, or null for indeterminate), status (LoaderStatus.running, .complete or .error), size and label. They stop looping when animations are disabled, report progress through Semantics, and play a short sound when they complete or fail.

The Worm, Pixel Progress, Paper Plane, Typing Indicator, Bouncing Cube and Hourglass Sand loaders are free in the kipluo package; the others install with npx kipluo add <name> --flutter.

upload_progress.dart
import 'package:kipluo/kipluo.dart';

WormLoader(
  value: uploadPercent,          // 0..100, or null while waiting for the server
  status: failed ? LoaderStatus.error : LoaderStatus.running,
  label: 'Uploading photo',
)

Accessibility checklist

Tick each one off as you check your build. Your ticks stay in this browser.

0 of 4 checked

Build it yourself or install it

Build it yourself when

You need one branded spinner. The ArcLoader above is complete and dependency-free.

Install Kipluo when

You want illustrated loaders with determinate progress, complete and error states, sound and a matching React version.

Keep building