Files
CityCards_Customer_Flutter/lib/postcard/widgets/front_card_widget.dart
2026-02-26 15:54:57 +05:30

99 lines
2.6 KiB
Dart

import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class FrontCardWidget extends StatelessWidget {
final String imageUrl;
final double aspectRatio;
const FrontCardWidget({
super.key,
this.imageUrl = '',
this.aspectRatio = 1.5,
});
/// Automatically detect if the path is a network URL or local file path
bool get _isNetworkImage {
return imageUrl.startsWith('http://') ||
imageUrl.startsWith('https://');
}
@override
Widget build(BuildContext context) {
return Container(
key: const ValueKey('front'),
margin: EdgeInsets.symmetric(horizontal: 12.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
// boxShadow: [
// BoxShadow(
// color: Colors.black.withOpacity(0.1),
// blurRadius: 10,
// offset: const Offset(0, 4),
// ),
// ],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(6),
child: AspectRatio(
aspectRatio: aspectRatio,
child: _buildImage(),
),
),
);
}
Widget _buildImage() {
if (imageUrl.isEmpty) {
return Container(
color: Colors.grey.shade200,
child: const Center(
child: Icon(Icons.image, size: 40, color: Colors.grey),
),
);
}
if (_isNetworkImage) {
return CachedNetworkImage(
imageUrl: imageUrl,
fit: BoxFit.cover,
progressIndicatorBuilder: (context, url, progress) {
return Container(
color: Colors.grey.shade200,
alignment: Alignment.center,
child: CircularProgressIndicator(
color: const Color(0xffF95F62),
value: progress.progress, // 👈 percentage
strokeWidth: 2,
),
);
},
errorWidget: (context, url, error) => Container(
color: Colors.grey.shade200,
alignment: Alignment.center,
child: const Icon(
Icons.broken_image,
size: 40,
color: Colors.grey,
),
),
);
} else {
return Image.file(
File(imageUrl),
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(
color: Colors.grey.shade200,
child: const Center(
child: Icon(Icons.broken_image, size: 40, color: Colors.grey),
),
);
},
);
}
}
}