backend
This commit is contained in:
parent
193ae3b0ea
commit
3e374d24f6
13 changed files with 126 additions and 3 deletions
34
lib/features/home/api/unsplash_images_api.dart
Normal file
34
lib/features/home/api/unsplash_images_api.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import '/features/core/data/constants/const_values.dart';
|
||||
import '/l10n/generated/l10n.dart';
|
||||
import '../abstracts/images_api.dart';
|
||||
import '../data/models/image_model.dart';
|
||||
|
||||
class UnsplashImagesApi implements ImagesApi {
|
||||
@override
|
||||
FutureOr<Iterable<ImageModel>> fetchImageUri({required String token}) {
|
||||
final random = Random();
|
||||
|
||||
return Iterable<int>.generate(ConstValues.numberOfImages).map((final imageIndex) {
|
||||
// Drawing from a normal distribution
|
||||
final imageSide = ConstValues.minImageSize +
|
||||
random.nextInt((ConstValues.maxImageSize + 1) - ConstValues.minImageSize);
|
||||
|
||||
final imageUri = _imageUrlGenerator(imageSide: imageSide);
|
||||
|
||||
return ImageModel<int>(
|
||||
comparableIndex: imageIndex,
|
||||
uri: imageUri,
|
||||
imageName: Strings.current.image,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Uri _imageUrlGenerator({required int imageSide}) => Uri(
|
||||
scheme: ConstValues.httpsScheme,
|
||||
host: ConstValues.backendHost,
|
||||
pathSegments: ConstValues.backendUrlPathSegments..add('${imageSide}x$imageSide'),
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue