games_app/prediqo_mobile/lib/shared/widgets/pred_skeleton.dart

133 lines
3.4 KiB
Dart

import 'package:flutter/material.dart';
import '../../core/theme/app_colors.dart';
/// Soft shimmer placeholder that stays readable on dark navy surfaces.
///
/// Uses a lighter base + moving highlight (not card→elevated, which were too
/// close to [AppColors.bgDark] / shortcut cards and looked like empty space).
class PredSkeleton extends StatefulWidget {
const PredSkeleton({
super.key,
this.width,
this.height = 16,
this.borderRadius = 10,
});
final double? width;
final double height;
final double borderRadius;
@override
State<PredSkeleton> createState() => _PredSkeletonState();
}
class _PredSkeletonState extends State<PredSkeleton>
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1400),
)..repeat();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final base = isDark
? Color.lerp(AppColors.surfaceCard, Colors.white, 0.10)!
: const Color(0xFFE8ECF4);
final mid = isDark
? Color.lerp(AppColors.surfaceCard, Colors.white, 0.20)!
: const Color(0xFFF3F5FA);
final tip = isDark
? Color.lerp(AppColors.surfaceCard, Colors.white, 0.32)!
: Colors.white;
final border = isDark
? AppColors.border.withValues(alpha: 0.85)
: const Color(0xFFD0D7E6);
return AnimatedBuilder(
animation: _controller,
builder: (context, _) {
final t = _controller.value;
// Sweep left → right so loading is obvious even on a still frame.
final start = Alignment(-1.4 + 2.8 * t, 0);
final end = Alignment(-0.2 + 2.8 * t, 0);
return Container(
width: widget.width,
height: widget.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(widget.borderRadius),
border: Border.all(color: border, width: 1),
gradient: LinearGradient(
begin: start,
end: end,
colors: [base, mid, tip, mid, base],
stops: const [0.0, 0.35, 0.5, 0.65, 1.0],
),
),
);
},
);
}
}
/// Hero / ad carousel placeholder (~200px).
class PredSkeletonCarousel extends StatelessWidget {
const PredSkeletonCarousel({super.key, this.height = 200});
final double height;
@override
Widget build(BuildContext context) {
return PredSkeleton(
width: double.infinity,
height: height,
borderRadius: 22,
);
}
}
/// Horizontal game / list card placeholder.
class PredSkeletonCard extends StatelessWidget {
const PredSkeletonCard({super.key, this.height = 88});
final double height;
@override
Widget build(BuildContext context) {
return PredSkeleton(
width: double.infinity,
height: height,
borderRadius: 16,
);
}
}
/// Compact list-row placeholder.
class PredSkeletonLine extends StatelessWidget {
const PredSkeletonLine({
super.key,
this.width,
this.height = 14,
});
final double? width;
final double height;
@override
Widget build(BuildContext context) {
return PredSkeleton(width: width, height: height, borderRadius: 8);
}
}