Created
July 23, 2025 16:52
-
-
Save jtmuller5/37b8e0d71cb2f64f8bb5ed0f914503b1 to your computer and use it in GitHub Desktop.
Flutter loading widget that shows a simple skeleton animation on a custom-sized box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:flutter_animate/flutter_animate.dart'; | |
| class SkeletonBox extends StatelessWidget { | |
| const SkeletonBox({ | |
| super.key, | |
| required this.width, | |
| required this.height, | |
| this.borderRadius = 4.0, | |
| this.delay, | |
| }); | |
| final double width; | |
| final double height; | |
| final double borderRadius; | |
| final Duration? delay; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Container( | |
| width: width, | |
| height: height, | |
| decoration: BoxDecoration( | |
| color: Colors.grey[300], | |
| borderRadius: BorderRadius.circular(borderRadius), | |
| ), | |
| ).animate(onPlay: (controller) => controller.repeat(reverse: true)).shimmer( | |
| duration: 1500.ms, | |
| color: Colors.grey[100]!, | |
| delay: delay ?? 0.ms, | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment