|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:intl/intl.dart'; |
| 3 | +import 'package:piwigo_ng/components/cards/piwigo_chip.dart'; |
| 4 | +import 'package:piwigo_ng/components/modals/piwigo_modal.dart'; |
| 5 | +import 'package:piwigo_ng/components/sections/form_section.dart'; |
| 6 | +import 'package:piwigo_ng/components/sections/settings_section.dart'; |
| 7 | +import 'package:piwigo_ng/models/image_model.dart'; |
| 8 | +import 'package:piwigo_ng/services/locale_provider.dart'; |
| 9 | +import 'package:piwigo_ng/utils/localizations.dart'; |
| 10 | +import 'package:provider/provider.dart'; |
| 11 | + |
| 12 | +class ImageInfoModal extends StatelessWidget { |
| 13 | + const ImageInfoModal({Key? key, required this.image}) : super(key: key); |
| 14 | + |
| 15 | + final ImageModel image; |
| 16 | + |
| 17 | + String _getDate(BuildContext context, String date) { |
| 18 | + LocaleNotifier localeNotifier = |
| 19 | + Provider.of<LocaleNotifier>(context, listen: false); |
| 20 | + |
| 21 | + return DateFormat.yMMMMd(localeNotifier.locale.languageCode) |
| 22 | + .format(DateTime.parse(image.dateAvailable!)); |
| 23 | + } |
| 24 | + |
| 25 | + String _getTime(BuildContext context, String date) { |
| 26 | + LocaleNotifier localeNotifier = |
| 27 | + Provider.of<LocaleNotifier>(context, listen: false); |
| 28 | + |
| 29 | + return DateFormat.Hms(localeNotifier.locale.languageCode) |
| 30 | + .format(DateTime.parse(image.dateAvailable!)); |
| 31 | + } |
| 32 | + |
| 33 | + @override |
| 34 | + Widget build(BuildContext context) { |
| 35 | + return PiwigoModal( |
| 36 | + title: appStrings.imageDetailsView_title, |
| 37 | + content: Padding( |
| 38 | + padding: const EdgeInsets.symmetric( |
| 39 | + horizontal: 16.0, |
| 40 | + vertical: 8.0, |
| 41 | + ), |
| 42 | + child: Column( |
| 43 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 44 | + children: [ |
| 45 | + Padding( |
| 46 | + padding: const EdgeInsets.all(8.0), |
| 47 | + child: Text( |
| 48 | + image.name, |
| 49 | + style: Theme.of(context).textTheme.titleMedium, |
| 50 | + ), |
| 51 | + ), |
| 52 | + if (image.comment != null) Text(image.comment!), |
| 53 | + const SizedBox(height: 8.0), |
| 54 | + SettingsSection( |
| 55 | + margin: EdgeInsets.zero, |
| 56 | + title: appStrings.settingsHeader_about, |
| 57 | + children: [ |
| 58 | + Padding( |
| 59 | + padding: const EdgeInsets.all(8.0), |
| 60 | + child: Text(image.file), |
| 61 | + ), |
| 62 | + Padding( |
| 63 | + padding: const EdgeInsets.all(8.0), |
| 64 | + child: Text("${image.width}x${image.height} px"), |
| 65 | + ), |
| 66 | + if (image.dateCreation != null) ...[ |
| 67 | + Padding( |
| 68 | + padding: const EdgeInsets.all(8.0), |
| 69 | + child: Text(appStrings.imageDetails_dateCreated( |
| 70 | + _getDate(context, image.dateCreation!), |
| 71 | + _getTime(context, image.dateCreation!), |
| 72 | + )), |
| 73 | + ), |
| 74 | + ], |
| 75 | + if (image.dateAvailable != null) ...[ |
| 76 | + Padding( |
| 77 | + padding: const EdgeInsets.all(8.0), |
| 78 | + child: Text(appStrings.imageDetails_dateAvailable( |
| 79 | + _getDate(context, image.dateAvailable!), |
| 80 | + _getTime(context, image.dateAvailable!), |
| 81 | + )), |
| 82 | + ), |
| 83 | + ], |
| 84 | + Padding( |
| 85 | + padding: const EdgeInsets.all(8.0), |
| 86 | + child: Text(appStrings |
| 87 | + .imageDetails_nbAlbums(image.categories.length)), |
| 88 | + ), |
| 89 | + ], |
| 90 | + ), |
| 91 | + const SizedBox(height: 8.0), |
| 92 | + FormSection( |
| 93 | + title: appStrings.tags, |
| 94 | + titlePadding: const EdgeInsets.symmetric(horizontal: 8.0), |
| 95 | + child: Wrap( |
| 96 | + spacing: 8.0, |
| 97 | + children: List.generate( |
| 98 | + image.tags.length, |
| 99 | + (index) => PiwigoChip( |
| 100 | + label: image.tags[index].name, |
| 101 | + backgroundColor: |
| 102 | + Theme.of(context).chipTheme.backgroundColor, |
| 103 | + foregroundColor: |
| 104 | + Theme.of(context).textTheme.bodyMedium?.color, |
| 105 | + ), |
| 106 | + ), |
| 107 | + ), |
| 108 | + ), |
| 109 | + ], |
| 110 | + ), |
| 111 | + ), |
| 112 | + ); |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +Future<void> showImageDetailsModal( |
| 117 | + BuildContext context, |
| 118 | + ImageModel image, |
| 119 | +) async { |
| 120 | + await showModalBottomSheet( |
| 121 | + context: context, |
| 122 | + isScrollControlled: true, |
| 123 | + useSafeArea: true, |
| 124 | + backgroundColor: Theme.of(context).scaffoldBackgroundColor, |
| 125 | + builder: (_) => ImageInfoModal(image: image), |
| 126 | + ); |
| 127 | +} |
0 commit comments