|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:shimmer/shimmer.dart'; |
| 3 | + |
| 4 | +/// These are the static widgets that we're gonna use as skeleton loaders. |
| 5 | +/// We use the Text Widget with dummy values to emulate the the exact dimensions of specific widgets |
| 6 | +/// The text values won't show up because they are overlapped by the shimmer effect. It's just for height and width purposes. |
| 7 | +
|
| 8 | +const Duration fadeInDuration = Duration(milliseconds: 500); |
| 9 | + |
| 10 | +class CardExpandedLoader extends StatelessWidget { |
| 11 | + const CardExpandedLoader({ |
| 12 | + required this.height, |
| 13 | + this.baseColor = const Color(0xFF607D8B), |
| 14 | + this.highlightColor = const Color(0xFFCFD8DC), |
| 15 | + super.key, |
| 16 | + }); |
| 17 | + final double height; |
| 18 | + final Color baseColor; |
| 19 | + final Color highlightColor; |
| 20 | + |
| 21 | + @override |
| 22 | + Widget build(BuildContext context) { |
| 23 | + return Shimmer.fromColors( |
| 24 | + baseColor: baseColor, |
| 25 | + highlightColor: highlightColor, |
| 26 | + child: Container( |
| 27 | + decoration: BoxDecoration( |
| 28 | + borderRadius: BorderRadius.circular(8), |
| 29 | + color: baseColor.withOpacity(0.1), |
| 30 | + ), |
| 31 | + margin: const EdgeInsets.only(right: 8), |
| 32 | + height: height, |
| 33 | + ), |
| 34 | + ); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +class CardLoader extends StatelessWidget { |
| 39 | + const CardLoader({ |
| 40 | + required this.height, |
| 41 | + required this.width, |
| 42 | + this.baseColor = const Color(0xFF607D8B), |
| 43 | + this.highlightColor = const Color(0xFFCFD8DC), |
| 44 | + super.key, |
| 45 | + }); |
| 46 | + final double height; |
| 47 | + final double width; |
| 48 | + final Color baseColor; |
| 49 | + final Color highlightColor; |
| 50 | + |
| 51 | + @override |
| 52 | + Widget build(BuildContext context) { |
| 53 | + return Shimmer.fromColors( |
| 54 | + baseColor: baseColor, |
| 55 | + highlightColor: highlightColor, |
| 56 | + child: Container( |
| 57 | + decoration: BoxDecoration( |
| 58 | + borderRadius: BorderRadius.circular(8), |
| 59 | + color: baseColor.withOpacity(0.1), |
| 60 | + ), |
| 61 | + margin: const EdgeInsets.only(right: 8), |
| 62 | + height: height, |
| 63 | + width: width, |
| 64 | + ), |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments