Docs
This commit is contained in:
parent
78fe9e7b09
commit
c7324a6b19
458 changed files with 93141 additions and 47 deletions
|
@ -1,7 +1,7 @@
|
|||
abstract class ConstValues {
|
||||
static const String httpsScheme = 'https';
|
||||
static const String backendHost = 'source.unsplash.com';
|
||||
static const List<String> backendUrlPathSegments = ['user', 'c_v_r'];
|
||||
static const String imagesHostServer = 'source.unsplash.com';
|
||||
static const List<String> imagesHostUrlPathSegments = ['user', 'c_v_r'];
|
||||
|
||||
static const int numberOfImages = 25;
|
||||
static const int minImageSize = 50;
|
||||
|
|
|
@ -2,9 +2,14 @@ extension StringExtensions on String {
|
|||
/// Returns true if given word contains atleast all the characters in [targetChars], and `false` otherwise
|
||||
///
|
||||
/// Very efficient `O(n)` instead of naive `O(n*m)`
|
||||
bool containsAllCharacters({required String targetChars}) {
|
||||
final Set<String> characterSet = Set.from(targetChars.split(''));
|
||||
for (final testChar in split('')) {
|
||||
bool containsAllCharacters({
|
||||
required String targetChars,
|
||||
bool ignoreCase = true,
|
||||
}) {
|
||||
final Set<String> characterSet = ignoreCase
|
||||
? Set.from(targetChars.toLowerCase().split(''))
|
||||
: Set.from(targetChars.split(''));
|
||||
for (final testChar in ignoreCase ? toLowerCase().split('') : split('')) {
|
||||
characterSet.remove(testChar);
|
||||
if (characterSet.isEmpty) return true;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue