diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a3be6b8 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/example/main.dart b/example/main.dart index 348b226..0f72e97 100644 --- a/example/main.dart +++ b/example/main.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; import 'package:firebase_image/firebase_image.dart'; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { return MaterialApp( @@ -11,13 +13,13 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - home: MyHomePage(title: 'Firebase Image Provider example'), + home: const MyHomePage(title: 'Firebase Image Provider example'), ); } } class MyHomePage extends StatefulWidget { - MyHomePage({Key? key, required this.title}) : super(key: key); + const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; diff --git a/lib/src/cache_manager.dart b/lib/src/cache_manager.dart index 7e3cf5b..db3dd46 100644 --- a/lib/src/cache_manager.dart +++ b/lib/src/cache_manager.dart @@ -73,7 +73,7 @@ class FirebaseImageCacheManager { where: 'uri = ?', whereArgs: [object.uri], ); - return maps.length > 0; + return maps.isNotEmpty; } Future get(String uri, FirebaseImage image) async { @@ -88,11 +88,11 @@ class FirebaseImageCacheManager { where: 'uri = ?', whereArgs: [uri], ); - if (maps.length > 0) { + if (maps.isNotEmpty) { FirebaseImageObject returnObject = FirebaseImageObject.fromMap(maps.first); returnObject.reference = getImageRef(returnObject, image.firebaseApp); - if (CacheRefreshStrategy.BY_METADATA_DATE == this.cacheRefreshStrategy) { + if (CacheRefreshStrategy.BY_METADATA_DATE == cacheRefreshStrategy) { checkForUpdate(returnObject, image); // Check for update in background } return returnObject; @@ -114,7 +114,7 @@ class FirebaseImageCacheManager { -1; if (remoteVersion != object.version) { // If true, download new image for next load - await this.upsertRemoteFileToCache(object, image.maxSizeBytes); + await upsertRemoteFileToCache(object, image.maxSizeBytes); } } @@ -147,7 +147,7 @@ class FirebaseImageCacheManager { Future upsertRemoteFileToCache( FirebaseImageObject object, int maxSizeBytes) async { - if (CacheRefreshStrategy.BY_METADATA_DATE == this.cacheRefreshStrategy) { + if (CacheRefreshStrategy.BY_METADATA_DATE == cacheRefreshStrategy) { object.version = (await object.reference.getMetadata()) .updated ?.millisecondsSinceEpoch ?? diff --git a/lib/src/cache_refresh_strategy.dart b/lib/src/cache_refresh_strategy.dart index 4ac3a39..0d727bf 100644 --- a/lib/src/cache_refresh_strategy.dart +++ b/lib/src/cache_refresh_strategy.dart @@ -1,3 +1,4 @@ +// ignore_for_file: constant_identifier_names enum CacheRefreshStrategy { // BY_METADATA_DATE uses the Storage Object updated timestamp as a version // number and checks for updates every time. diff --git a/lib/src/firebase_image.dart b/lib/src/firebase_image.dart index 5526269..414c359 100644 --- a/lib/src/firebase_image.dart +++ b/lib/src/firebase_image.dart @@ -83,17 +83,15 @@ class FirebaseImage extends ImageProvider { if (localObject != null) { bytes = await cacheManager.localFileBytes(localObject); - if (bytes == null) { - bytes = await cacheManager.upsertRemoteFileToCache( - _imageObject, this.maxSizeBytes); - } + bytes ??= await cacheManager.upsertRemoteFileToCache( + _imageObject, maxSizeBytes); } else { bytes = await cacheManager.upsertRemoteFileToCache( - _imageObject, this.maxSizeBytes); + _imageObject, maxSizeBytes); } } else { bytes = - await cacheManager.remoteFileBytes(_imageObject, this.maxSizeBytes); + await cacheManager.remoteFileBytes(_imageObject, maxSizeBytes); } return bytes!; @@ -122,13 +120,13 @@ class FirebaseImage extends ImageProvider { if (other.runtimeType != runtimeType) return false; final FirebaseImage typedOther = other; return _imageObject.uri == typedOther._imageObject.uri && - this.scale == typedOther.scale; + scale == typedOther.scale; } @override - int get hashCode => hashValues(_imageObject.uri, this.scale); + int get hashCode => hashValues(_imageObject.uri, scale); @override String toString() => - '$runtimeType("${_imageObject.uri}", scale: ${this.scale})'; + '$runtimeType("${_imageObject.uri}", scale: $scale)'; } diff --git a/lib/src/image_object.dart b/lib/src/image_object.dart index 95fc97e..7736acf 100644 --- a/lib/src/image_object.dart +++ b/lib/src/image_object.dart @@ -18,11 +18,11 @@ class FirebaseImageObject { Map toMap() { return { - 'version': this.version, - 'localPath': this.localPath, - 'bucket': this.bucket, - 'remotePath': this.remotePath, - 'uri': this.uri, + 'version': version, + 'localPath': localPath, + 'bucket': bucket, + 'remotePath': remotePath, + 'uri': uri, }; } diff --git a/pubspec.yaml b/pubspec.yaml index 61bb08c..ed7b68b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,5 +17,6 @@ dependencies: path_provider: ^2.0.5 dev_dependencies: + flutter_lints: ^1.0.4 flutter_test: sdk: flutter