better linting
This commit is contained in:
parent
c7324a6b19
commit
aa31a79d20
26 changed files with 163 additions and 131 deletions
|
@ -9,16 +9,19 @@ import '../abstracts/images_api.dart';
|
|||
import '../data/dtos/image_model_dto.dart';
|
||||
|
||||
class UnsplashImagesApi extends ImagesApi {
|
||||
UnsplashImagesApi({required super.token});
|
||||
|
||||
//final LoggingService _loggingService = LoggingService.locate;
|
||||
final random = Random();
|
||||
|
||||
UnsplashImagesApi({required super.token});
|
||||
|
||||
@override
|
||||
FutureOr<Iterable<ImageModelDTO>> fetchImageUri() async {
|
||||
// Dummy fetching delay emulation
|
||||
await Future.delayed(const Duration(
|
||||
milliseconds: ConstValues.defaultEmulatedLatencyMillis * ConstValues.numberOfImages));
|
||||
await Future<void>.delayed(
|
||||
const Duration(
|
||||
milliseconds: ConstValues.defaultEmulatedLatencyMillis * ConstValues.numberOfImages,
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Map<String, dynamic>> fetchedImageModelDtos;
|
||||
try {
|
||||
|
@ -48,8 +51,7 @@ class UnsplashImagesApi extends ImagesApi {
|
|||
}
|
||||
|
||||
// Emulating deserialization
|
||||
return fetchedImageModelDtos
|
||||
.map((final emulatedModelSerialized) => ImageModelDTO.fromJson(emulatedModelSerialized));
|
||||
return fetchedImageModelDtos.map(ImageModelDTO.fromJson);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -59,8 +61,11 @@ class UnsplashImagesApi extends ImagesApi {
|
|||
final numberOfResults = random.nextIntInRange(min: 0, max: ConstValues.numberOfImages);
|
||||
|
||||
// Dummy fetching delay emulation
|
||||
await Future.delayed(
|
||||
Duration(milliseconds: ConstValues.defaultEmulatedLatencyMillis * numberOfResults));
|
||||
await Future<void>.delayed(
|
||||
Duration(
|
||||
milliseconds: ConstValues.defaultEmulatedLatencyMillis * numberOfResults,
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Map<String, dynamic>> searchImageModelDtos;
|
||||
try {
|
||||
|
@ -87,8 +92,7 @@ class UnsplashImagesApi extends ImagesApi {
|
|||
return List.empty();
|
||||
}
|
||||
|
||||
return searchImageModelDtos
|
||||
.map((final emulatedModelSerialized) => ImageModelDTO.fromJson(emulatedModelSerialized));
|
||||
return searchImageModelDtos.map(ImageModelDTO.fromJson);
|
||||
}
|
||||
|
||||
Uri _imageUrlGenerator({required int imageSide}) => Uri(
|
||||
|
|
|
@ -2,13 +2,24 @@ import '../dtos/image_model_dto.dart';
|
|||
|
||||
/// Represents an Image, that would be displayed in the gallery.
|
||||
class ImageModel {
|
||||
const ImageModel({
|
||||
const ImageModel._({
|
||||
required this.uri,
|
||||
required this.imageIndex,
|
||||
required this.imageName,
|
||||
required this.isFavourite,
|
||||
});
|
||||
|
||||
factory ImageModel.fromDto({
|
||||
required ImageModelDTO imageModelDto,
|
||||
required bool isFavourite,
|
||||
}) =>
|
||||
ImageModel._(
|
||||
uri: imageModelDto.uri,
|
||||
imageIndex: imageModelDto.imageIndex,
|
||||
imageName: imageModelDto.imageName,
|
||||
isFavourite: isFavourite,
|
||||
);
|
||||
|
||||
/// An image's target [Uri].
|
||||
///
|
||||
/// Storing an image's [ByteData] is more expensive, memory-wise.
|
||||
|
@ -23,24 +34,13 @@ class ImageModel {
|
|||
/// Whether the image was 'Starred' ot not.
|
||||
final bool isFavourite;
|
||||
|
||||
factory ImageModel.fromDto({
|
||||
required ImageModelDTO imageModelDto,
|
||||
required bool isFavourite,
|
||||
}) =>
|
||||
ImageModel(
|
||||
uri: imageModelDto.uri,
|
||||
imageIndex: imageModelDto.imageIndex,
|
||||
imageName: imageModelDto.imageName,
|
||||
isFavourite: isFavourite,
|
||||
);
|
||||
|
||||
ImageModel copyWith({
|
||||
Uri? uri,
|
||||
int? imageIndex,
|
||||
String? imageName,
|
||||
bool? isFavourite,
|
||||
}) {
|
||||
return ImageModel(
|
||||
return ImageModel._(
|
||||
uri: uri ?? this.uri,
|
||||
imageIndex: imageIndex ?? this.imageIndex,
|
||||
imageName: imageName ?? this.imageName,
|
||||
|
|
|
@ -22,7 +22,7 @@ class ImageCacheManagerService {
|
|||
final LoggingService _loggingService = LoggingService.locate;
|
||||
final _cacheManager = DefaultCacheManager();
|
||||
|
||||
Future<void> emptyCache() async => await _cacheManager.emptyCache();
|
||||
void emptyCache() => _cacheManager.emptyCache();
|
||||
|
||||
Future<void> _init() async {
|
||||
_appLifecycleService.addListener(
|
||||
|
|
|
@ -54,19 +54,25 @@ class ImagesService {
|
|||
|
||||
// Prefill from stored values
|
||||
if (favouritesStatuses.isNotEmpty) {
|
||||
_loggingService.good('Found favourites statuses on device -> Prefilling');
|
||||
assert(fetchedImageModelDtos.length == favouritesStatuses.length);
|
||||
_loggingService.fine('Found favourites statuses on device -> Prefilling');
|
||||
assert(
|
||||
fetchedImageModelDtos.length == favouritesStatuses.length,
|
||||
'Downloaded images must be the same number as the statuses stored on device',
|
||||
);
|
||||
|
||||
_imageModels = LinkedHashMap.of({
|
||||
for (final pair in IterableZip([fetchedImageModelDtos, favouritesStatuses]))
|
||||
(pair[0] as ImageModelDTO).imageName: ImageModel.fromDto(
|
||||
imageModelDto: pair[0] as ImageModelDTO,
|
||||
isFavourite: pair[1] as bool,
|
||||
for (final zippedDtosAndFavourites
|
||||
in IterableZip([fetchedImageModelDtos, favouritesStatuses]))
|
||||
(zippedDtosAndFavourites[0] as ImageModelDTO).imageName: ImageModel.fromDto(
|
||||
imageModelDto: zippedDtosAndFavourites[0] as ImageModelDTO,
|
||||
isFavourite: zippedDtosAndFavourites[1] as bool,
|
||||
)
|
||||
});
|
||||
|
||||
// Set to false and create the stored values
|
||||
} else {
|
||||
_loggingService.good('NO favourites statuses found -> creating new');
|
||||
|
||||
_imageModels = LinkedHashMap.of({
|
||||
for (final fetchedImageModelDto in fetchedImageModelDtos)
|
||||
fetchedImageModelDto.imageName: ImageModel.fromDto(
|
||||
|
@ -119,8 +125,10 @@ class ImagesService {
|
|||
: imageName.containsAllCharacters(targetChars: imageNamePart))
|
||||
.toList(growable: false)
|
||||
// Sorting by the highest similarity first
|
||||
..sort((final a, final b) =>
|
||||
ConstSorters.stringsSimilarityTarget(targetWord: imageNamePart, a, b))
|
||||
..sort(
|
||||
(final a, final b) =>
|
||||
ConstSorters.stringsSimilarityTarget(targetWord: imageNamePart, a, b),
|
||||
)
|
||||
..reversed;
|
||||
|
||||
return _imageModels.valuesByKeys(keys: rankedKeys).toList(growable: false);
|
||||
|
|
|
@ -150,8 +150,8 @@ class _SearchBox extends StatelessWidget {
|
|||
items: [
|
||||
for (final searchOption in SearchOption.values)
|
||||
DropdownMenuItem(
|
||||
child: Center(child: Text(searchOption.name)),
|
||||
value: searchOption,
|
||||
child: Center(child: Text(searchOption.name)),
|
||||
),
|
||||
],
|
||||
value: searchOption,
|
||||
|
|
|
@ -42,7 +42,7 @@ class GalleryViewModel extends BaseViewModel {
|
|||
ValueListenable<bool> get isViewingFavouriteListenable => _isViewingFavouriteNotifier;
|
||||
|
||||
@override
|
||||
Future<void> initialise(bool Function() mounted, [arguments]) async {
|
||||
Future<void> initialise(bool Function() mounted, [Object? arguments]) async {
|
||||
super.initialise(mounted, arguments);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class ImageCarouselView extends StatelessWidget {
|
|||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Card(
|
||||
elevation: 8,
|
||||
surfaceTintColor: ConstColours.transparent,
|
||||
|
@ -110,7 +110,7 @@ class ImageCarouselView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
const Gap(24),
|
||||
Gap.size24,
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
// Assuming that this data is coming from an external CRM, if it is coming with the
|
||||
|
|
|
@ -21,9 +21,11 @@ class ImageCarouselViewModel extends BaseViewModel {
|
|||
final CarouselController carouselController = CarouselController();
|
||||
|
||||
@override
|
||||
Future<void> initialise(bool Function() mounted, [arguments]) async {
|
||||
_currentImageModelNotifier = ValueNotifier(_imagesService.imageModels
|
||||
.elementAt((arguments as ImageCarouselViewArguments).imageIndexKey));
|
||||
Future<void> initialise(bool Function() mounted, [Object? arguments]) async {
|
||||
_currentImageModelNotifier = ValueNotifier(
|
||||
_imagesService.imageModels
|
||||
.elementAt((arguments! as ImageCarouselViewArguments).imageIndexKey),
|
||||
);
|
||||
log.info('Initialized with image: ${_currentImageModelNotifier.value.imageIndex}');
|
||||
|
||||
super.initialise(mounted, arguments);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue