|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:shimmer/shimmer.dart'; |
| 3 | +import 'package:survey_flutter/theme/app_constants.dart'; |
| 4 | + |
| 5 | +const double _bottomPadding = 62; |
| 6 | +const double _rectangleHeight = 20; |
| 7 | +const double _circleSize = 36; |
| 8 | + |
| 9 | +class HomeShimmerLoading extends StatelessWidget { |
| 10 | + const HomeShimmerLoading({Key? key}) : super(key: key); |
| 11 | + |
| 12 | + @override |
| 13 | + Widget build(BuildContext context) { |
| 14 | + final screenWidth = MediaQuery.of(context).size.width; |
| 15 | + |
| 16 | + return Shimmer.fromColors( |
| 17 | + baseColor: Colors.white.withOpacity(0.12), |
| 18 | + highlightColor: Colors.white24, |
| 19 | + child: Column( |
| 20 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 21 | + children: [ |
| 22 | + _buildTopRows(screenWidth), |
| 23 | + const Spacer(), |
| 24 | + _buildBottomRows(screenWidth), |
| 25 | + ], |
| 26 | + ), |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + Widget _buildTopRows(double screenWidth) { |
| 31 | + return Row( |
| 32 | + children: [ |
| 33 | + Column( |
| 34 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 35 | + children: [ |
| 36 | + _buildShimmerText( |
| 37 | + topPadding: 61, |
| 38 | + width: screenWidth * 0.3, |
| 39 | + ), |
| 40 | + _buildShimmerText( |
| 41 | + topPadding: 10, |
| 42 | + width: screenWidth * 0.25, |
| 43 | + ), |
| 44 | + ], |
| 45 | + ), |
| 46 | + const Spacer(), |
| 47 | + Padding( |
| 48 | + padding: const EdgeInsets.only(top: 79, right: Metrics.spacing20), |
| 49 | + child: Container( |
| 50 | + width: _circleSize, |
| 51 | + height: _circleSize, |
| 52 | + decoration: const BoxDecoration( |
| 53 | + shape: BoxShape.circle, |
| 54 | + color: Colors.black, |
| 55 | + ), |
| 56 | + ), |
| 57 | + ), |
| 58 | + ], |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + Widget _buildShimmerText({ |
| 63 | + double? topPadding, |
| 64 | + double? bottomPadding, |
| 65 | + double? width, |
| 66 | + }) { |
| 67 | + return Padding( |
| 68 | + padding: EdgeInsets.only( |
| 69 | + left: Metrics.spacing20, |
| 70 | + top: topPadding ?? 0, |
| 71 | + right: Metrics.spacing20, |
| 72 | + bottom: bottomPadding ?? 0, |
| 73 | + ), |
| 74 | + child: Container( |
| 75 | + decoration: BoxDecoration( |
| 76 | + borderRadius: BorderRadius.circular(_rectangleHeight / 2), |
| 77 | + color: Colors.black, |
| 78 | + ), |
| 79 | + width: width, |
| 80 | + height: _rectangleHeight, |
| 81 | + ), |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + Widget _buildBottomRows(double screenWidth) { |
| 86 | + return Column( |
| 87 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 88 | + children: [ |
| 89 | + _buildShimmerText( |
| 90 | + topPadding: 0, |
| 91 | + width: screenWidth * 0.1, |
| 92 | + ), |
| 93 | + _buildShimmerText( |
| 94 | + topPadding: Metrics.spacing16, |
| 95 | + width: screenWidth * 0.67, |
| 96 | + ), |
| 97 | + _buildShimmerText( |
| 98 | + topPadding: Metrics.spacing10, |
| 99 | + width: screenWidth * 0.3, |
| 100 | + ), |
| 101 | + _buildShimmerText( |
| 102 | + topPadding: Metrics.spacing16, |
| 103 | + width: screenWidth * 0.84, |
| 104 | + ), |
| 105 | + _buildShimmerText( |
| 106 | + topPadding: Metrics.spacing10, |
| 107 | + bottomPadding: _bottomPadding, |
| 108 | + width: screenWidth * 0.5, |
| 109 | + ), |
| 110 | + ], |
| 111 | + ); |
| 112 | + } |
| 113 | +} |
0 commit comments