sojorn/sojorn_app/lib/widgets/post/post_media.dart
Patrick Britton b76154be3a Fix UUID casting issues in post, notification, and category repositories
- Replace NULLIF with CASE WHEN for proper UUID casting
- Fix missing ::uuid casting in WHERE clauses
- Resolve 'operator does not exist: uuid = text' errors
- Focus on post_repository.go, notification_repository.go, and category_repository.go
2026-01-31 13:55:59 -06:00

96 lines
3 KiB
Dart

import 'package:flutter/material.dart';
import '../../models/post.dart';
import '../../theme/app_theme.dart';
import '../media/signed_media_image.dart';
import 'post_view_mode.dart';
/// Post media widget with view-mode-aware sizing.
///
/// Logic:
/// - feed: BoxFit.cover with fixed height (300)
/// - detail: Full height (unconstrained)
/// - compact: Smaller height (200)
class PostMedia extends StatelessWidget {
final Post? post;
final Widget? child;
final PostViewMode mode;
const PostMedia({
super.key,
this.post,
this.child,
this.mode = PostViewMode.feed,
});
/// Get image height based on view mode
double get _imageHeight {
switch (mode) {
case PostViewMode.feed:
return 300.0;
case PostViewMode.detail:
return 500.0; // Full height for detail view
case PostViewMode.compact:
return 200.0; // Smaller for profile lists
}
}
@override
Widget build(BuildContext context) {
if (post != null && post!.imageUrl != null && post!.imageUrl!.isNotEmpty) {
return Padding(
padding: const EdgeInsets.only(top: AppTheme.spacingSm),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ConstrainedBox(
constraints: BoxConstraints(maxHeight: _imageHeight),
child: ClipRRect(
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
child: SizedBox(
width: double.infinity,
child: SignedMediaImage(
url: post!.imageUrl!,
fit: BoxFit.contain,
loadingBuilder: (context) => Container(
color: AppTheme.queenPink.withValues(alpha: 0.3),
child: const Center(child: CircularProgressIndicator()),
),
errorBuilder: (context, error, stackTrace) => Container(
color: Colors.red.withValues(alpha: 0.3),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.broken_image,
size: 48, color: Colors.white),
const SizedBox(height: 8),
Text('Error: $error',
style: const TextStyle(
color: Colors.white, fontSize: 10)),
],
),
),
),
),
),
),
),
],
),
);
}
if (child == null) {
return const SizedBox.shrink();
}
return Padding(
padding: const EdgeInsets.only(top: AppTheme.spacingSm),
child: ClipRRect(
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
child: child,
),
);
}
}