1- import 'package:cached_network_image/cached_network_image .dart' ;
1+ import 'package:auto_size_text/auto_size_text .dart' ;
22import 'package:flutter/material.dart' ;
33import 'package:flutter_slidable/flutter_slidable.dart' ;
44import 'package:piwigo_ng/components/app_image_display.dart' ;
@@ -167,6 +167,28 @@ class AlbumCardContent extends StatelessWidget {
167167
168168 final AlbumModel album;
169169
170+ bool isCommentValid (String ? input) {
171+ if (input == null ) return false ;
172+
173+ // Define a regular expression pattern to match common CSS attributes and selectors
174+ final RegExp cssPattern = RegExp (
175+ r"(^|\s)(color|font-size|margin|padding|background|border|position|display|opacity|animation|@media|@keyframes)(:|\s)" ,
176+ caseSensitive: false ,
177+ );
178+
179+ // Check if the input string contains the CSS pattern
180+ if (cssPattern.hasMatch (input)) return true ;
181+
182+ // Define a regular expression pattern to match common HTML tags and attributes
183+ final RegExp htmlPattern = RegExp (
184+ r"(^|<\s*)(div|span|p|a|h1|h2|h3|h4|h5|h6|img|ul|ol|li|br|strong|em|blockquote)(\s|>)" ,
185+ caseSensitive: false ,
186+ );
187+
188+ // Check if the input string contains the HTML pattern
189+ return htmlPattern.hasMatch (input);
190+ }
191+
170192 @override
171193 Widget build (BuildContext context) {
172194 return LayoutBuilder (builder: (context, constraints) {
@@ -190,46 +212,6 @@ class AlbumCardContent extends StatelessWidget {
190212 return ImageNetworkDisplay (
191213 imageUrl: album.urlRepresentative,
192214 );
193- if (album.urlRepresentative == null ) {
194- return FittedBox (
195- fit: BoxFit .cover,
196- child: Container (
197- padding: const EdgeInsets .all (16.0 ),
198- decoration: BoxDecoration (
199- color: Theme .of (context).scaffoldBackgroundColor,
200- ),
201- child: const Icon (Icons .image_not_supported_outlined),
202- ),
203- );
204- }
205- return CachedNetworkImage (
206- imageUrl: album.urlRepresentative! ,
207- fit: BoxFit .cover,
208- fadeInDuration: const Duration (milliseconds: 300 ),
209- progressIndicatorBuilder: (context, url, download) {
210- if (download.downloaded >= (download.totalSize ?? 0 )) {
211- return const SizedBox ();
212- }
213- return Center (
214- child: CircularProgressIndicator (
215- value: download.progress,
216- ),
217- );
218- },
219- errorWidget: (context, url, error) {
220- debugPrint ("[$url ] $error " );
221- return FittedBox (
222- fit: BoxFit .cover,
223- child: Container (
224- padding: const EdgeInsets .all (16.0 ),
225- decoration: BoxDecoration (
226- color: Theme .of (context).scaffoldBackgroundColor,
227- ),
228- child: const Icon (Icons .broken_image_outlined),
229- ),
230- );
231- },
232- );
233215 }),
234216 ),
235217 );
@@ -253,12 +235,18 @@ class AlbumCardContent extends StatelessWidget {
253235 padding: const EdgeInsets .symmetric (vertical: 4.0 ),
254236 child: Align (
255237 alignment: Alignment .bottomCenter,
256- child: Text (
257- album.comment ?? '' ,
258- softWrap: true ,
259- overflow: TextOverflow .ellipsis,
260- style: Theme .of (context).textTheme.bodySmall,
261- ),
238+ child: Builder (builder: (context) {
239+ if (isCommentValid (album.comment)) {
240+ return const SizedBox ();
241+ }
242+ return AutoSizeText (
243+ album.comment ?? '' ,
244+ softWrap: true ,
245+ maxLines: 10 ,
246+ overflow: TextOverflow .ellipsis,
247+ style: Theme .of (context).textTheme.bodySmall,
248+ );
249+ }),
262250 ),
263251 ),
264252 ),
0 commit comments