This commit is contained in:
Mguy13 2022-12-26 19:39:47 +01:00
parent 78fe9e7b09
commit c7324a6b19
458 changed files with 93141 additions and 47 deletions

View file

@ -1,5 +1,8 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import '/features/core/services/logging_service.dart';
import '../data/dtos/image_model_dto.dart';
/// Interface for implementing image-fetching strategies, specific to a resource location on the internet.
@ -7,10 +10,11 @@ import '../data/dtos/image_model_dto.dart';
/// Since I used a site that was more obscure than the ones in the examples, this (otherwise pointless
/// and convoluting) interface is for adding a bit of flexibility to change strategy to some other site.
abstract class ImagesApi {
ImagesApi({required String token}) : _token = token;
ImagesApi({required this.token});
/// Access token provided to be used with API calls
final String _token;
@protected
final String token;
/// Returns images fetched through an API as [ImageModelDTO]s.
FutureOr<Iterable<ImageModelDTO>> fetchImageUri();
@ -18,4 +22,7 @@ abstract class ImagesApi {
FutureOr<Iterable<ImageModelDTO>> searchImages({
required String searchStr,
});
@protected
final LoggingService loggingService = LoggingService.locate;
}

View file

@ -3,14 +3,13 @@ import 'dart:math';
import '/features/core/data/constants/const_values.dart';
import '/features/core/data/extensions/random_extensions.dart';
import '/features/core/services/logging_service.dart';
import '/l10n/generated/l10n.dart';
import '/locator.dart';
import '../abstracts/images_api.dart';
import '../data/dtos/image_model_dto.dart';
class UnsplashImagesApi extends ImagesApi {
final LoggingService _loggingService = LoggingService.locate;
//final LoggingService _loggingService = LoggingService.locate;
final random = Random();
UnsplashImagesApi({required super.token});
@ -44,7 +43,7 @@ class UnsplashImagesApi extends ImagesApi {
// Emulating serialization
fetchedImageModelDtos = dummyImageModels.map((final dummyModel) => dummyModel.toJson());
} on Exception catch (ex, stackTrace) {
_loggingService.handleException(ex, stackTrace);
loggingService.handleException(ex, stackTrace);
return const Iterable.empty();
}
@ -84,7 +83,7 @@ class UnsplashImagesApi extends ImagesApi {
// Emulating serialization
searchImageModelDtos = dummyImageModels.map((final dummyModel) => dummyModel.toJson());
} on Exception catch (ex, stackTrace) {
_loggingService.handleException(ex, stackTrace);
loggingService.handleException(ex, stackTrace);
return List.empty();
}
@ -94,8 +93,8 @@ class UnsplashImagesApi extends ImagesApi {
Uri _imageUrlGenerator({required int imageSide}) => Uri(
scheme: ConstValues.httpsScheme,
host: ConstValues.backendHost,
pathSegments: [...ConstValues.backendUrlPathSegments, '${imageSide}x$imageSide'],
host: ConstValues.imagesHostServer,
pathSegments: [...ConstValues.imagesHostUrlPathSegments, '${imageSide}x$imageSide'],
);
static UnsplashImagesApi get locate => Locator.locate();

View file

@ -113,6 +113,8 @@ class ImageCarouselView extends StatelessWidget {
const Gap(24),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
// Assuming that this data is coming from an external CRM, if it is coming with the
// image itself, then add it to the DTO and the Model as well, and access it here.
child: MarkdownBody(data: model.strings.imageDetails),
),
const Gap(16),