|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:intl/intl.dart'; |
| 3 | +import 'package:piwigo_ng/models/image_model.dart'; |
| 4 | +import 'package:piwigo_ng/services/preferences_service.dart'; |
| 5 | + |
| 6 | +class ImageDetailsCard extends StatelessWidget { |
| 7 | + const ImageDetailsCard({Key? key, required this.image, this.onRemove}) : super(key: key); |
| 8 | + |
| 9 | + final ImageModel image; |
| 10 | + final Function()? onRemove; |
| 11 | + |
| 12 | + @override |
| 13 | + Widget build(BuildContext context) { |
| 14 | + return Stack( |
| 15 | + children: [ |
| 16 | + Padding( |
| 17 | + padding: const EdgeInsets.all(8.0), |
| 18 | + child: Row( |
| 19 | + children: [ |
| 20 | + _imageThumbnail(context), |
| 21 | + Expanded( |
| 22 | + child: Container( |
| 23 | + margin: EdgeInsets.symmetric(vertical: 8.0), |
| 24 | + padding: EdgeInsets.only(top: 8.0, bottom: 8.0, right: 8.0), |
| 25 | + decoration: BoxDecoration( |
| 26 | + borderRadius: BorderRadius.horizontal(right: Radius.circular(10.0)), |
| 27 | + color: Theme.of(context).cardColor, |
| 28 | + ), |
| 29 | + child: Column( |
| 30 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 31 | + children: [ |
| 32 | + Text( |
| 33 | + image.file, |
| 34 | + maxLines: 2, |
| 35 | + overflow: TextOverflow.ellipsis, |
| 36 | + style: Theme.of(context).textTheme.bodyMedium, |
| 37 | + ), |
| 38 | + if (image.dateAvailable != null) |
| 39 | + Flexible( |
| 40 | + child: Padding( |
| 41 | + padding: const EdgeInsets.only(top: 4.0), |
| 42 | + child: Text( |
| 43 | + DateFormat.yMMMMd().format(DateTime.parse(image.dateAvailable!)), // todo locale |
| 44 | + maxLines: 2, |
| 45 | + style: Theme.of(context).textTheme.bodyMedium, |
| 46 | + ), |
| 47 | + ), |
| 48 | + ), |
| 49 | + ], |
| 50 | + ), |
| 51 | + ), |
| 52 | + ), |
| 53 | + ], |
| 54 | + ), |
| 55 | + ), |
| 56 | + _removeButton(context), |
| 57 | + ], |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + Widget _imageThumbnail(context) => Container( |
| 62 | + padding: EdgeInsets.all(8.0), |
| 63 | + decoration: BoxDecoration( |
| 64 | + borderRadius: BorderRadius.circular(10.0), |
| 65 | + color: Theme.of(context).cardColor, |
| 66 | + ), |
| 67 | + child: AspectRatio( |
| 68 | + aspectRatio: 1.0, |
| 69 | + child: ClipRRect( |
| 70 | + borderRadius: BorderRadius.circular(5.0), |
| 71 | + child: Builder(builder: (context) { |
| 72 | + final String? imageUrl = image.getDerivativeFromString(Preferences.getImageThumbnailSize)?.url; |
| 73 | + return Image.network( |
| 74 | + imageUrl ?? '', |
| 75 | + fit: BoxFit.cover, |
| 76 | + errorBuilder: (context, o, s) { |
| 77 | + debugPrint("$o\n$s"); |
| 78 | + return Center(child: Icon(Icons.image_not_supported)); |
| 79 | + }, |
| 80 | + loadingBuilder: (context, child, loadingProgress) { |
| 81 | + if (loadingProgress == null) return child; |
| 82 | + return Center( |
| 83 | + child: CircularProgressIndicator( |
| 84 | + value: loadingProgress.expectedTotalBytes != null |
| 85 | + ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes! |
| 86 | + : null, |
| 87 | + ), |
| 88 | + ); |
| 89 | + }, |
| 90 | + ); |
| 91 | + }), |
| 92 | + ), |
| 93 | + ), |
| 94 | + ); |
| 95 | + |
| 96 | + Widget _removeButton(context) => Positioned( |
| 97 | + bottom: 0.0, |
| 98 | + right: 16.0, |
| 99 | + child: GestureDetector( |
| 100 | + behavior: HitTestBehavior.opaque, |
| 101 | + onTap: onRemove, |
| 102 | + child: Container( |
| 103 | + padding: EdgeInsets.all(2.0), |
| 104 | + decoration: BoxDecoration( |
| 105 | + shape: BoxShape.circle, |
| 106 | + color: Theme.of(context).cardColor, |
| 107 | + ), |
| 108 | + child: Icon(Icons.remove_circle_outline), |
| 109 | + ), |
| 110 | + ), |
| 111 | + ); |
| 112 | +} |
0 commit comments