Skip to content

Commit

Permalink
Merge pull request #56 from CodeAtlas/feature/enable_flutter_lints
Browse files Browse the repository at this point in the history
Enable Flutter Lints
  • Loading branch information
mattreid1 authored Dec 23, 2021
2 parents e8976b2 + a29746e commit 08a7c0a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
8 changes: 5 additions & 3 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
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(
title: 'Firebase Image Provider Demo',
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;

Expand Down
10 changes: 5 additions & 5 deletions lib/src/cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class FirebaseImageCacheManager {
where: 'uri = ?',
whereArgs: [object.uri],
);
return maps.length > 0;
return maps.isNotEmpty;
}

Future<FirebaseImageObject?> get(String uri, FirebaseImage image) async {
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ class FirebaseImageCacheManager {

Future<Uint8List?> 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 ??
Expand Down
1 change: 1 addition & 0 deletions lib/src/cache_refresh_strategy.dart
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
16 changes: 7 additions & 9 deletions lib/src/firebase_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,15 @@ class FirebaseImage extends ImageProvider<FirebaseImage> {

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!;
Expand Down Expand Up @@ -122,13 +120,13 @@ class FirebaseImage extends ImageProvider<FirebaseImage> {
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)';
}
10 changes: 5 additions & 5 deletions lib/src/image_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class FirebaseImageObject {

Map<String, dynamic> 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,
};
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ dependencies:
path_provider: ^2.0.5

dev_dependencies:
flutter_lints: ^1.0.4
flutter_test:
sdk: flutter

0 comments on commit 08a7c0a

Please sign in to comment.