@@ -274,9 +274,7 @@ class CachedVideoPlayerPlus {
274274 /// Returns a [Future] that completes when initialization is finished.
275275 Future <void > initialize () async {
276276 if (_isInitialized) {
277- if (kDebugMode) {
278- debugPrint ('CachedVideoPlayerPlus is already initialized.' );
279- }
277+ _debugPrint ('CachedVideoPlayerPlus is already initialized.' );
280278 return ;
281279 }
282280
@@ -286,11 +284,7 @@ class CachedVideoPlayerPlus {
286284 if (_shouldUseCache) {
287285 FileInfo ? cachedFile = await _cacheManager.getFileFromCache (_cacheKey);
288286
289- if (kDebugMode) {
290- debugPrint (
291- 'Cached video of [$dataSource ] is: ${cachedFile ?.file .path }' ,
292- );
293- }
287+ _debugPrint ('Cached video of [$dataSource ] is: ${cachedFile ?.file .path }' );
294288
295289 if (cachedFile != null ) {
296290 final cachedElapsedMillis = await _storage.read (_cacheKey);
@@ -303,20 +297,16 @@ class CachedVideoPlayerPlus {
303297 );
304298 final difference = now.difference (cachedDate);
305299
306- if (kDebugMode) {
307- debugPrint (
308- 'Cache for [$dataSource ] valid till: '
309- '${cachedDate .add (invalidateCacheIfOlderThan )}' ,
310- );
311- }
300+ _debugPrint (
301+ 'Cache for [$dataSource ] valid till: '
302+ '${cachedDate .add (invalidateCacheIfOlderThan )}' ,
303+ );
312304
313305 isCacheExpired = difference > invalidateCacheIfOlderThan;
314306 }
315307
316308 if (isCacheExpired) {
317- if (kDebugMode) {
318- debugPrint ('Cache of [$dataSource ] expired. Removing...' );
319- }
309+ _debugPrint ('Cache of [$dataSource ] expired. Removing...' );
320310 _cacheManager.removeFile (_cacheKey);
321311 cachedFile = null ;
322312 }
@@ -330,9 +320,7 @@ class CachedVideoPlayerPlus {
330320 _cacheKey,
331321 DateTime .timestamp ().millisecondsSinceEpoch,
332322 );
333- if (kDebugMode) {
334- debugPrint ('Cached video [$dataSource ] successfully.' );
335- }
323+ _debugPrint ('Cached video [$dataSource ] successfully.' );
336324 });
337325 } else {
338326 isCacheAvailable = true ;
@@ -528,9 +516,7 @@ class CachedVideoPlayerPlus {
528516 }
529517
530518 if (isCacheExpired) {
531- if (kDebugMode) {
532- debugPrint ('Cache of [$url ] expired. Removing...' );
533- }
519+ _debugPrint ('Cache of [$url ] expired. Removing...' );
534520 await cacheManager.removeFile (effectiveCacheKey);
535521 cachedFile = null ;
536522 }
@@ -549,9 +535,14 @@ class CachedVideoPlayerPlus {
549535 DateTime .timestamp ().millisecondsSinceEpoch,
550536 );
551537
552- if (kDebugMode) {
553- debugPrint ('Pre-Cached video [$url ] successfully.' );
554- }
538+ _debugPrint ('Pre-Cached video [$url ] successfully.' );
555539 }
556540 }
557541}
542+
543+ /// Checks if [kDebugMode] is enabled and prints a debug message.
544+ void _debugPrint (String ? message, {int ? wrapWidth}) {
545+ if (kDebugMode) {
546+ debugPrint (message, wrapWidth: wrapWidth);
547+ }
548+ }
0 commit comments