blob: 003e6b2869e42f1c7606fef5b527f93f3bb96a6b [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'dart:ui' as ui show Codec;
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
/// An animated GIF image with 3 1x1 pixel frames (a red, green, and blue
/// frames). The GIF animates forever, and each frame has a 100ms delay.
const String kAnimatedGif = 'R0lGODlhAQABAKEDAAAA//8AAAD/AP///yH/C05FVFNDQVBFMi'
/// A 50x50 blue square png
/// A 10x10 grid of animated looping placeholder gifts that fade into a
/// blue square.
class AnimatedPlaceholderPage extends StatelessWidget {
const AnimatedPlaceholderPage({super.key});
Widget build(BuildContext context) {
return GridView.builder(
itemCount: 100,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 10),
itemBuilder: (BuildContext context, int index) {
return FadeInImage(
placeholder: const DelayedBase64Image(, kAnimatedGif),
image: DelayedBase64Image(Duration(milliseconds: 100 * index), kBlueSquare),
int _key = 0;
/// An image provider that is always unique from other DelayedBase64Images and
/// simulates a delay in loading.
class DelayedBase64Image extends ImageProvider<int> {
const DelayedBase64Image(this.delay,;
final String data;
final Duration delay;
Future<int> obtainKey(ImageConfiguration configuration) {
return SynchronousFuture<int>(_key++);
ImageStreamCompleter loadImage(int key, ImageDecoderCallback decode) {
return MultiFrameImageStreamCompleter(
codec: Future<ui.Codec>.delayed(
() async => decode(await ImmutableBuffer.fromUint8List(base64.decode(data))),
scale: 1.0,